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



commit 6a69a309bf9783b897ba0c56b22c94055de36562
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.

 data/theme/gnome-shell.css |    1 +
 js/ui/appDisplay.js        |   31 ++++++++++++-------------------
 js/ui/search.js            |   42 ++++++++++++++++--------------------------
 3 files changed, 29 insertions(+), 45 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 0cdcb26..1bedacd 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -22,6 +22,7 @@ const Main = imports.ui.main;
 const Overview = imports.ui.overview;
 const OverviewControls = imports.ui.overviewControls;
 const PopupMenu = imports.ui.popupMenu;
+const Search = imports.ui.search;
 const Tweener = imports.ui.tweener;
 const Workspace = imports.ui.workspace;
 const Params = imports.misc.params;
@@ -1089,15 +1090,7 @@ const AppSearchProvider = new Lang.Class({
     },
 
     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();
+        // Rely on AppIcon.activate() having been called instead
     },
 
     dragActivateResult: function(id, params) {
@@ -1110,7 +1103,10 @@ const AppSearchProvider = new Lang.Class({
 
     createResultObject: function (resultMeta) {
         let app = this._appSys.lookup_app(resultMeta['id']);
-        return new AppIcon(app);
+        let appIcon = new AppIcon(app);
+        appIcon.metaInfo = resultMeta;
+        appIcon.provider = this;
+        return appIcon;
     }
 });
 
@@ -1569,19 +1565,17 @@ Signals.addSignalMethods(AppFolderPopup.prototype);
 
 const AppIcon = new Lang.Class({
     Name: 'AppIcon',
+    Extends: Search.SearchResult,
 
     _init : function(app, params) {
         this.app = app;
         this.id = app.get_id();
         this.name = app.get_name();
 
-        this.actor = new St.Button({ style_class: 'app-well-app',
-                                     reactive: true,
-                                     button_mask: St.ButtonMask.ONE | St.ButtonMask.TWO,
-                                     can_focus: true,
-                                     x_fill: true,
-                                     y_fill: true });
-        this.actor._delegate = this;
+        this.parent();
+
+        this.actor.add_style_class_name('app-well-app');
+        this.actor.button_mask = St.ButtonMask.ONE | St.ButtonMask.TWO;
 
         if (!params)
             params = {};
@@ -1687,9 +1681,8 @@ const AppIcon = new Lang.Class({
         return Clutter.EVENT_PROPAGATE;
     },
 
-    _onClicked: function(actor, button) {
+    _onClicked: function() {
         this._removeMenuTimeout();
-        this.activate(button);
     },
 
     _onKeyboardPopupMenu: function() {
diff --git a/js/ui/search.js b/js/ui/search.js
index 16e04bf..cbecc06 100644
--- a/js/ui/search.js
+++ b/js/ui/search.js
@@ -232,25 +232,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 +252,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 +299,14 @@ const SearchResultsBase = new Lang.Class({
         this._terms = [];
     },
 
-    _clearResultDisplay: function() {
+    _createResultDisplay: function(meta) {
+        if (this.provider.createResultObject) {
+            let result = this.provider.createResultObject(meta);
+            if (!result instanceof SearchResult)
+                throw new Error('Provided result object is not a SearchResult');
+            return result;
+        }
+        return null;
     },
 
     clear: function() {
@@ -448,7 +438,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 +486,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) {


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