[gnome-shell/wip/swarm: 2/3] search: Allow providers to return the complete result object



commit 928e25cfd3c53840bf271d6e10a304a522b71800
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 20 18:39:02 2014 +0200

    search: Allow providers to return the complete result object
    
     This makes the existing createResultObject() match its name better
     and avoids oddities like nested StButtons in app search results.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=734726

 data/theme/gnome-shell.css |    1 +
 js/ui/appDisplay.js        |   12 -------
 js/ui/search.js            |   69 ++++++++++++++++++-------------------------
 3 files changed, 30 insertions(+), 52 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index 89d6909..843ed6c 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -1159,6 +1159,7 @@ StScrollBar StButton#vhandle:active {
 .show-apps:checked > .overview-icon,
 .show-apps:active > .overview-icon,
 .search-provider-icon:active,
+.grid-search-result:active .overview-icon,
 .list-search-result:active {
     background-gradient-start: rgba(255, 255, 255, .05);
     background-gradient-end: rgba(255, 255, 255, .15);
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index d9efcbf..98dea5f 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -1055,18 +1055,6 @@ const AppSearchProvider = new Lang.Class({
         this.getInitialResultSet(terms, callback, cancellable);
     },
 
-    activateResult: function(result) {
-        let app = this._appSys.lookup_app(result);
-        let event = Clutter.get_current_event();
-        let modifiers = event ? event.get_state() : 0;
-        let openNewWindow = modifiers & Clutter.ModifierType.CONTROL_MASK;
-
-        if (openNewWindow)
-            app.open_new_window(-1);
-        else
-            app.activate();
-    },
-
     dragActivateResult: function(id, params) {
         params = Params.parse(params, { workspace: -1,
                                         timestamp: 0 });
diff --git a/js/ui/search.js b/js/ui/search.js
index f33b8ad..d50de47 100644
--- a/js/ui/search.js
+++ b/js/ui/search.js
@@ -165,13 +165,6 @@ const SearchResult = new Lang.Class({
 
     activate: function() {
         this.emit('activate', this.metaInfo.id);
-    },
-
-    setSelected: function(selected) {
-        if (selected)
-            this.actor.add_style_pseudo_class('selected');
-        else
-            this.actor.remove_style_pseudo_class('selected');
     }
 });
 Signals.addSignalMethods(SearchResult.prototype);
@@ -232,25 +225,11 @@ const GridSearchResult = new Lang.Class({
 
         this.actor.style_class = 'grid-search-result';
 
-        let content = provider.createResultObject(metaInfo);
-        let dragSource = null;
-
-        if (content == null) {
-            let actor = new St.Bin();
-            let icon = new IconGrid.BaseIcon(this.metaInfo['name'],
-                                             { createIcon: this.metaInfo['createIcon'] });
-            actor.set_child(icon.actor);
-            actor.label_actor = icon.label;
-            dragSource = icon.icon;
-            content = { actor: actor, icon: icon };
-        } else {
-            if (content.getDragActorSource)
-                dragSource = content.getDragActorSource();
-        }
-
-        this.actor.set_child(content.actor);
-        this.actor.label_actor = content.actor.label_actor;
-        this.icon = content.icon;
+        this.icon = new IconGrid.BaseIcon(this.metaInfo['name'],
+                                          { createIcon: this.metaInfo['createIcon'] });
+        let content = new St.Bin({ child: this.icon.actor });
+        this.actor.set_child(content);
+        this.actor.label_actor = this.icon.label;
 
         let draggable = DND.makeDraggable(this.actor);
         draggable.connect('drag-begin',
@@ -266,10 +245,7 @@ const GridSearchResult = new Lang.Class({
                               Main.overview.endItemDrag(this);
                           }));
 
-        if (!dragSource)
-            // not exactly right, but alignment problems are hard to notice
-            dragSource = content.actor;
-        this._dragActorSource = dragSource;
+        this._dragActorSource = content;
     },
 
     getDragActorSource: function() {
@@ -316,7 +292,11 @@ const SearchResultsBase = new Lang.Class({
         this._terms = [];
     },
 
-    _clearResultDisplay: function() {
+    _createResultDisplay: function(meta) {
+        if (this.provider.createResultObject)
+            return this.provider.createResultObject(meta);
+
+        return null;
     },
 
     clear: function() {
@@ -448,7 +428,7 @@ const ListSearchResults = new Lang.Class({
     },
 
     _createResultDisplay: function(meta) {
-        return new ListSearchResult(this.provider, meta);
+        return this.parent(meta) || new ListSearchResult(this.provider, meta);
     },
 
     _addItem: function(display) {
@@ -496,7 +476,7 @@ const GridSearchResults = new Lang.Class({
     },
 
     _createResultDisplay: function(meta) {
-        return new GridSearchResult(this.provider, meta);
+        return this.parent(meta) || new GridSearchResult(this.provider, meta);
     },
 
     _addItem: function(display) {
@@ -633,12 +613,9 @@ const SearchResults = new Lang.Class({
 
         if (newDefaultResult != this._defaultResult) {
             if (this._defaultResult)
-                this._defaultResult.setSelected(false);
-            if (newDefaultResult) {
-                newDefaultResult.setSelected(this._highlightDefault);
-                if (this._highlightDefault)
-                    Util.ensureActorVisibleInScrollView(this._scrollView, newDefaultResult.actor);
-            }
+                this._setSelected(this._defaultResult, false);
+            if (newDefaultResult)
+                this._setSelected(newDefaultResult, this._highlightDefault);
 
             this._defaultResult = newDefaultResult;
         }
@@ -676,7 +653,7 @@ const SearchResults = new Lang.Class({
     highlightDefault: function(highlight) {
         this._highlightDefault = highlight;
         if (this._defaultResult) {
-            this._defaultResult.setSelected(highlight);
+            this._setSelected(this._defaultResult, highlight);
             if (highlight)
                 Util.ensureActorVisibleInScrollView(this._scrollView, this._defaultResult.actor);
         }
@@ -694,6 +671,18 @@ const SearchResults = new Lang.Class({
 
         let from = this._defaultResult ? this._defaultResult.actor : null;
         this.actor.navigate_focus(from, direction, false);
+    },
+
+    _setSelected: function(result, selected) {
+        if (!result)
+            return;
+
+        if (selected) {
+            result.actor.add_style_pseudo_class('selected');
+            Util.ensureActorVisibleInScrollView(this._scrollView, result.actor);
+        } else {
+            result.actor.remove_style_pseudo_class('selected');
+        }
     }
 });
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]