[gnome-shell/wip/raresv/uiTweaks] search.js: evil patch
- From: Rares Visalom <raresvisalom src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/raresv/uiTweaks] search.js: evil patch
- Date: Mon, 26 Jun 2017 23:13:57 +0000 (UTC)
commit 57dfceb8e59ed69018e7386a354672ca72c0df63
Author: raresvis <rares visalom gmail com>
Date: Tue Jun 27 02:13:43 2017 +0300
search.js: evil patch
js/ui/search.js | 73 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 56 insertions(+), 17 deletions(-)
---
diff --git a/js/ui/search.js b/js/ui/search.js
index 74e120b..ab5bb53 100644
--- a/js/ui/search.js
+++ b/js/ui/search.js
@@ -74,8 +74,13 @@ const ListSearchResult = new Lang.Class({
ICON_SIZE: 24,
- _init: function(provider, metaInfo) {
+ _init: function(provider, metaInfo, parentInstance) {
this.parent(provider, metaInfo);
+
+ this._parentInstance = parentInstance;
+ this._parentInstance.connect('terms-changed',
+ Lang.bind(this, this._boldHandler));
+
log ('>>>' + metaInfo.terms);
this.actor.style_class = 'list-search-result';
this.actor.x_fill = true;
@@ -107,24 +112,36 @@ const ListSearchResult = new Lang.Class({
if (!this.metaInfo['description'])
log("no description in metainfo");
+ this._descriptionLabel = new St.Label({
+ style_class: 'list-search-result-description' });
+
if (this.metaInfo['description']) {
- let searchTerms =
- Shell.util_regex_escape(metaInfo.terms.join(' ')).split(" ");
+ /*let searchTerms = metaInfo.terms.map(
+ (currentTerm, index, array) =>
+ { return Shell.util_regex_escape(currentTerm) });
let description_text = this.metaInfo['description'].replace(
new RegExp(`(${searchTerms.join('|')})`, 'gi'),
- '<b>$1</b>');
+ '<b>$1</b>');*/
- let description = new St.Label({
- style_class: 'list-search-result-description' });
- description.clutter_text.set_markup(description_text);
+ /*this._descriptionLabel = new St.Label({
+ style_class: 'list-search-result-description' });*/
- log('description_text: ' + description_text);
- details.add(description, { x_fill: false,
+ this._boldHandler();
+
+ //log('description_text: ' + description_text);
+ details.add(this._descriptionLabel, { x_fill: false,
y_fill: false,
x_align: St.Align.START,
y_align: St.Align.MIDDLE });
}
+ },
+
+ _boldHandler: function() {
+ if (!this.metaInfo['description'] || !this._descriptionLabel || !this._parentInstance)
+ return;
+
+
this._descriptionLabel.clutter_text.set_markup(this._parentInstance.highlightTerms(this.metaInfo['description']));
}
});
@@ -132,7 +149,7 @@ const GridSearchResult = new Lang.Class({
Name: 'GridSearchResult',
Extends: SearchResult,
- _init: function(provider, metaInfo) {
+ _init: function(provider, metaInfo, parentInstance) {
this.parent(provider, metaInfo);
this.actor.style_class = 'grid-search-result';
@@ -281,9 +298,11 @@ const ListSearchResults = new Lang.Class({
Name: 'ListSearchResults',
Extends: SearchResultsBase,
- _init: function(provider) {
+ _init: function(provider, parentInstance) {
this.parent(provider);
+ this._parentInstance = parentInstance;
+
this._container = new St.BoxLayout({ style_class: 'search-section-content' });
this.providerInfo = new ProviderInfo(provider);
this.providerInfo.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
@@ -322,7 +341,7 @@ const ListSearchResults = new Lang.Class({
log("YEEEEEEP");
if (!meta['description'])
log("NO DESCRIPTION FFS");
- return this.parent(meta) || new ListSearchResult(this.provider, meta);
+ return this.parent(meta) || new ListSearchResult(this.provider, meta, this._parentInstance);
},
_addItem: function(display) {
@@ -342,14 +361,16 @@ const GridSearchResults = new Lang.Class({
Name: 'GridSearchResults',
Extends: SearchResultsBase,
- _init: function(provider, parentContainer) {
+ _init: function(provider, parentInstance) {
this.parent(provider);
// We need to use the parent container to know how much results we can show.
// None of the actors in this class can be used for that, since the main actor
// goes hidden when no results are displayed, and then it lost its allocation.
// Then on the next use of _getMaxDisplayedResults allocation is 0, en therefore
// it doesn't show any result although we have some.
- this._parentContainer = parentContainer;
+ this._parentContainer = parentInstance.actor;
+
+ this._parentInstance = parentInstance;
this._grid = new IconGrid.IconGrid({ rowLimit: MAX_GRID_SEARCH_RESULTS_ROWS,
xAlign: St.Align.START });
@@ -370,7 +391,7 @@ const GridSearchResults = new Lang.Class({
},
_createResultDisplay: function(meta) {
- return this.parent(meta) || new GridSearchResult(this.provider, meta);
+ return this.parent(meta) || new GridSearchResult(this.provider, meta, this._parentInstance);
},
_addItem: function(display) {
@@ -434,6 +455,8 @@ const SearchResults = new Lang.Class({
this._providers = [];
+ this._searchTermRegex = null;
+
this._searchSettings = new Gio.Settings({ schema_id: SEARCH_PROVIDERS_SCHEMA });
this._searchSettings.connect('changed::disabled', Lang.bind(this, this._reloadRemoteProviders));
this._searchSettings.connect('changed::enabled', Lang.bind(this, this._reloadRemoteProviders));
@@ -553,6 +576,14 @@ const SearchResults = new Lang.Class({
if (this._searchTimeoutId == 0)
this._searchTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 150, Lang.bind(this,
this._onSearchTimeout));
+
+ let escapedSearchTerms = this._terms.map(
+ (currentTerm, index, array) =>
+ { return Shell.util_regex_escape(currentTerm) });
+
+ this._searchTermRegex =
+ new RegExp(`(${escapedSearchTerms.join('|')})`, 'gi');
+ this.emit('terms-changed');
},
_onPan: function(action) {
@@ -572,9 +603,9 @@ const SearchResults = new Lang.Class({
let providerDisplay;
if (provider.appInfo)
- providerDisplay = new ListSearchResults(provider);
+ providerDisplay = new ListSearchResults(provider, this);
else
- providerDisplay = new GridSearchResults(provider, this.actor);
+ providerDisplay = new GridSearchResults(provider, this);
providerDisplay.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
providerDisplay.actor.hide();
@@ -691,8 +722,16 @@ const SearchResults = new Lang.Class({
} else {
result.actor.remove_style_pseudo_class('selected');
}
+ },
+
+ highlightTerms: function(description) {
+ if (!description)
+ return '';
+
+ return description.replace(this._searchTermRegex, '<b>$1</b>');
}
});
+Signals.addSignalMethods(SearchResults.prototype);
const ProviderInfo = new Lang.Class({
Name: 'ProviderInfo',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]