[gnome-shell/wip/paging-release2: 21/22] iconGrid: Change IconGrid.addItem() to take an object instead of an actor



commit ab8473e66efef946eebb6e3e0182c09c48ea5177
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 29 23:25:13 2013 +0200

    iconGrid: Change IconGrid.addItem() to take an object instead of an actor
    
    IconGrid has never really been a general purpose container, but has always been
    used in conjunction with BaseIcon. IconGrid will soon gain the ability to adjust
    the item size dynamically to adapt to the available space, which will require that
    we can make some more assumptions about the items added to the grid (namely: we
    need access to BaseIcon's setIconSize() method).
    So change addItem() to take an object instead, which should have an actor and a
    (BaseIcon) icon property.
    
    Based on a patch by Carlos Soriano.

 js/ui/appDisplay.js    |    9 ++++-----
 js/ui/iconGrid.js      |   15 +++++++++++----
 js/ui/searchDisplay.js |   16 +++++++++-------
 js/ui/wanda.js         |    5 ++---
 4 files changed, 26 insertions(+), 19 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index ae13555..7c2f42f 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -131,7 +131,7 @@ const BaseAppView = new Lang.Class({
             let id = this._getItemId(this._allItems[i]);
             if (!id)
                 continue;
-            this._grid.addItem(this._items[id].actor);
+            this._grid.addItem(this._items[id]);
         }
     }
 });
@@ -620,7 +620,7 @@ const FrequentView = new Lang.Class({
             if (!mostUsed[i].get_app_info().should_show())
                 continue;
             let appIcon = new AppIcon(mostUsed[i]);
-            this._grid.addItem(appIcon.actor, -1);
+            this._grid.addItem(appIcon, -1);
         }
     },
 
@@ -894,10 +894,9 @@ const AppSearchProvider = new Lang.Class({
         app.open_new_window(workspace);
     },
 
-    createResultActor: function (resultMeta, terms) {
+    createResultObject: function (resultMeta, terms) {
         let app = resultMeta['id'];
-        let icon = new AppIcon(app);
-        return icon.actor;
+        return new AppIcon(app);
     }
 });
 
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index a283f58..2b66fa7 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -201,7 +201,7 @@ const IconGrid = new Lang.Class({
 
         this.actor = new St.BoxLayout({ style_class: 'icon-grid',
                                         vertical: true });
-
+        this._items = [];
         // Pulled from CSS, but hardcode some defaults here
         this._spacing = 0;
         this._hItemSize = this._vItemSize = ICON_SIZE;
@@ -406,14 +406,21 @@ const IconGrid = new Lang.Class({
     },
 
     removeAll: function() {
+        this._items = [];
         this._grid.destroy_all_children();
     },
 
-    addItem: function(actor, index) {
+    addItem: function(item, index) {
+        if (!item.icon || !item.icon instanceof BaseIcon) {
+            log('Only items with a BaseIcon icon property can be added to IconGrid');
+            return;
+        }
+
+        this._items.push(item);
         if (index !== undefined)
-            this._grid.insert_child_at_index(actor, index);
+            this._grid.insert_child_at_index(item.actor, index);
         else
-            this._grid.add_actor(actor);
+            this._grid.add_actor(item.actor);
     },
 
     getItemAtIndex: function(index) {
diff --git a/js/ui/searchDisplay.js b/js/ui/searchDisplay.js
index 9d47e44..72aa131 100644
--- a/js/ui/searchDisplay.js
+++ b/js/ui/searchDisplay.js
@@ -126,23 +126,25 @@ const GridSearchResult = new Lang.Class({
 
         this.actor.style_class = 'grid-search-result';
 
-        let content = provider.createResultActor(metaInfo, terms);
+        let content = provider.createResultObject(metaInfo, terms);
         let dragSource = null;
 
         if (content == null) {
-            content = new St.Bin();
+            let actor = new St.Bin();
             let icon = new IconGrid.BaseIcon(this.metaInfo['name'],
                                              { createIcon: this.metaInfo['createIcon'] });
-            content.set_child(icon.actor);
-            content.label_actor = icon.label;
+            actor.set_child(icon.actor);
+            actor.label_actor = icon.label;
             dragSource = icon.icon;
+            content = { actor: actor, icon: icon };
         } else {
             if (content._delegate && content._delegate.getDragActorSource)
                 dragSource = content._delegate.getDragActorSource();
         }
 
-        this.actor.set_child(content);
-        this.actor.label_actor = content.label_actor;
+        this.actor.set_child(content.actor);
+        this.actor.label_actor = content.actor.label_actor;
+        this.icon = content.icon;
 
         let draggable = DND.makeDraggable(this.actor);
         draggable.connect('drag-begin',
@@ -327,7 +329,7 @@ const GridSearchResults = new Lang.Class({
         for (let i = 0; i < metas.length; i++) {
             let display = new GridSearchResult(this.provider, metas[i], this._terms);
             display.actor.connect('key-focus-in', Lang.bind(this, this._keyFocusIn));
-            this._grid.addItem(display.actor);
+            this._grid.addItem(display);
         }
     },
 
diff --git a/js/ui/wanda.js b/js/ui/wanda.js
index 713f4cd..731a631 100644
--- a/js/ui/wanda.js
+++ b/js/ui/wanda.js
@@ -150,8 +150,7 @@ const WandaSearchProvider = new Lang.Class({
         this._dialog = new FortuneDialog(capitalize(fish), FISH_COMMAND);
     },
 
-    createResultActor: function (resultMeta, terms) {
-        let icon = new WandaIconBin(resultMeta.id, resultMeta.name);
-        return icon.actor;
+    createResultObject: function (resultMeta, terms) {
+        return new WandaIconBin(resultMeta.id, resultMeta.name);
     }
 });


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