[gnome-shell/wip/gtkmenutrackeritem: 1/5] remoteMenu: Split the tracking code into a separate class



commit 0dcf3744b5f07b4fdddfec57ff8afff2fc834ac1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu May 9 17:32:52 2013 -0400

    remoteMenu: Split the tracking code into a separate class
    
    The tracking logic will be used to more easily implement submenus.

 js/ui/remoteMenu.js |   55 +++++++++++++++++++++++++++++---------------------
 1 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/js/ui/remoteMenu.js b/js/ui/remoteMenu.js
index 13b6e4a..fbbe6b8 100644
--- a/js/ui/remoteMenu.js
+++ b/js/ui/remoteMenu.js
@@ -94,32 +94,24 @@ const RemoteMenuItemMapper = new Lang.Class({
     },
 });
 
-const RemoteMenu = new Lang.Class({
-    Name: 'RemoteMenu',
-    Extends: PopupMenu.PopupMenu,
-
-    _init: function(sourceActor, model, actionGroup) {
-        this.parent(sourceActor, 0.0, St.Side.TOP);
+const RemoteMenuTracker = new Lang.Class({
+    Name: 'RemoteMenuTracker',
 
-        this._model = model;
-        this._actionGroup = actionGroup;
-        this._trackMenu(model, this);
-    },
-
-    _trackMenu: function(model, item) {
-        item._tracker = Shell.MenuTracker.new(this._actionGroup,
+    _init: function(actionGroup, model, menu) {
+        this._menu = menu;
+        this._tracker = Shell.MenuTracker.new(actionGroup,
                                               model,
                                               null, /* action namespace */
-                                              Lang.bind(this, this._insertItem, item),
-                                              Lang.bind(this, this._removeItem, item));
+                                              Lang.bind(this, this._insertItem),
+                                              Lang.bind(this, this._removeItem));
+    },
 
-        item.connect('destroy', function() {
-            item._tracker.destroy();
-            item._tracker = null;
-        });
+    destroy: function() {
+        this._tracker.destroy();
+        this._tracker = null;
     },
 
-    _insertItem: function(trackerItem, position, target) {
+    _insertItem: function(trackerItem, position) {
         let item;
 
         if (trackerItem.get_is_separator()) {
@@ -130,11 +122,28 @@ const RemoteMenu = new Lang.Class({
             item = mapper.menuItem;
         }
 
-        target.addMenuItem(item, position);
+        this._menu.addMenuItem(item, position);
     },
 
-    _removeItem: function(position, target) {
-        let items = target._getMenuItems();
+    _removeItem: function(position) {
+        let items = this._menu._getMenuItems();
         items[position].destroy();
     },
 });
+
+const RemoteMenu = new Lang.Class({
+    Name: 'RemoteMenu',
+    Extends: PopupMenu.PopupMenu,
+
+    _init: function(sourceActor, model, actionGroup) {
+        this.parent(sourceActor, 0.0, St.Side.TOP);
+
+        this._model = model;
+        this._tracker = new RemoteMenuTracker(actionGroup, model, this);
+    },
+
+    destroy: function() {
+        this._tracker.destroy();
+        this.parent();
+    }
+});


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