[gnome-shell-extensions] window-list: Refactoring to use an Extension object



commit 5fc66444b6afce0fa040272f2f3fe6d191d05545
Author: Sylvain Pasche <sylvain pasche gmail com>
Date:   Mon Nov 10 21:35:27 2014 +0100

    window-list: Refactoring to use an Extension object
    
    Move the global state into a new Extension object. This is in
    preparation for adding more logic to the Extension object.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737486

 extensions/window-list/extension.js |   83 ++++++++++++++++++++---------------
 1 files changed, 47 insertions(+), 36 deletions(-)
---
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
index 0cee654..718af9d 100644
--- a/extensions/window-list/extension.js
+++ b/extensions/window-list/extension.js
@@ -53,7 +53,7 @@ function _onMenuStateChanged(menu, isOpen) {
 
     let [x, y,] = global.get_pointer();
     let actor = global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, x, y);
-    if (windowList.actor.contains(actor))
+    if (Me.stateObj.windowListContains(actor))
         actor.sync_hover();
 }
 
@@ -812,7 +812,7 @@ const WindowList = new Lang.Class({
             Main.layoutManager.connect('keyboard-visible-changed',
                 Lang.bind(this, function(o, state) {
                     Main.layoutManager.keyboardBox.visible = state;
-                    Main.uiGroup.set_child_above_sibling(windowList.actor,
+                    Main.uiGroup.set_child_above_sibling(this.actor,
                                                          Main.layoutManager.keyboardBox);
                     this._updateKeyboardAnchor();
                 }));
@@ -1176,49 +1176,60 @@ const WindowList = new Lang.Class({
     }
 });
 
-let windowList;
-let injections = {};
-let notificationParent;
+const Extension = new Lang.Class({
+    Name: 'Extension',
 
-function init() {
-}
+    _init: function() {
+        this._windowList = null;
+        this._injections = {};
+        this._notificationParent = null;
+    },
 
-function enable() {
-    windowList = new WindowList();
+    enable: function() {
+        this._windowList = new WindowList();
+        let windowListActor = this._windowList.actor;
 
-    windowList.actor.connect('notify::hover', Lang.bind(Main.messageTray,
-        function() {
-            this._pointerInNotification = windowList.actor.hover;
-            this._updateState();
-        }));
+        windowListActor.connect('notify::hover', Lang.bind(Main.messageTray,
+            function() {
+                this._pointerInNotification = windowListActor.hover;
+                this._updateState();
+            }));
 
-    injections['_trayDwellTimeout'] = MessageTray.MessageTray.prototype._trayDwellTimeout;
-    MessageTray.MessageTray.prototype._trayDwellTimeout = function() {
-        return false;
-    };
+        this._injections['_trayDwellTimeout'] =
+            MessageTray.MessageTray.prototype._trayDwellTimeout;
+        MessageTray.MessageTray.prototype._trayDwellTimeout = function() {
+            return false;
+        };
 
-    notificationParent = Main.messageTray._notificationWidget.get_parent();
-    Main.messageTray._notificationWidget.hide();
-    Main.messageTray._notificationWidget.reparent(windowList.actor);
-    Main.messageTray._notificationWidget.show();
-}
+        this._notificationParent = Main.messageTray._notificationWidget.get_parent();
+        Main.messageTray._notificationWidget.hide();
+        Main.messageTray._notificationWidget.reparent(windowListActor);
+        Main.messageTray._notificationWidget.show();
+    },
 
-function disable() {
-    var prop;
+    disable: function() {
+        if (!this._windowList)
+            return;
 
-    if (!windowList)
-        return;
+        this._windowList.actor.hide();
 
-    windowList.actor.hide();
+        if (this._notificationParent) {
+            Main.messageTray._notificationWidget.reparent(this._notificationParent);
+            this._notificationParent = null;
+        }
 
-    if (notificationParent) {
-        Main.messageTray._notificationWidget.reparent(notificationParent);
-        notificationParent = null;
-    }
+        this._windowList.actor.destroy();
+        this._windowList = null;
 
-    windowList.actor.destroy();
-    windowList = null;
+        for (let prop in this._injections)
+            MessageTray.MessageTray.prototype[prop] = this._injections[prop];
+    },
 
-    for (prop in injections)
-        MessageTray.MessageTray.prototype[prop] = injections[prop];
+    windowListContains: function(actor) {
+        return this._windowList.actor.contains(actor);
+    }
+});
+
+function init() {
+    return new Extension();
 }


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