[gnome-shell-extensions/wip/window-list: 1/4] Factor out WindowTitle



commit 1da2589476624cd11fa9a3a9af0615db0817eb4d
Author: Florian MÃllner <fmuellner gnome org>
Date:   Thu Jan 24 22:31:57 2013 +0100

    Factor out WindowTitle

 extensions/window-list/extension.js |   81 ++++++++++++++++++++--------------
 1 files changed, 48 insertions(+), 33 deletions(-)
---
diff --git a/extensions/window-list/extension.js b/extensions/window-list/extension.js
index c09a02d..c49c3b9 100644
--- a/extensions/window-list/extension.js
+++ b/extensions/window-list/extension.js
@@ -18,29 +18,65 @@ function _minimizeOrActivateWindow(window) {
 }
 
 
+const WindowTitle = new Lang.Class({
+    Name: 'WindowTitle',
+
+    _init: function(metaWindow) {
+        this._metaWindow = metaWindow;
+        this.actor = new St.BoxLayout();
+
+        let textureCache = St.TextureCache.get_default();
+        let icon = textureCache.bind_pixbuf_property(this._metaWindow, "icon");
+        this._icon = new St.Bin({ style_class: 'window-button-icon',
+                                  child: icon });
+        this.actor.add(this._icon);
+        this._label = new St.Label();
+        this.actor.add(this._label);
+
+        this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
+
+        this._notifyTitleId =
+            this._metaWindow.connect('notify::title',
+                                    Lang.bind(this, this._updateTitle));
+        this._notifyMinimizedId =
+            this._metaWindow.connect('notify::minimized',
+                                    Lang.bind(this, this._minimizedChanged));
+        this._minimizedChanged();
+    },
+
+    _minimizedChanged: function() {
+        this._icon.opacity = this._metaWindow.minimized ? 128 : 255;
+        this._updateTitle();
+    },
+
+    _updateTitle: function() {
+        if (this._metaWindow.minimized)
+            this._label.text = '[%s]'.format(this._metaWindow.title);
+        else
+            this._label.text = this._metaWindow.title;
+    },
+
+    _onDestroy: function() {
+        this._metaWindow.disconnect(this._notifyTitleId);
+        this._metaWindow.disconnect(this._notifyMinimizedId);
+    }
+});
+
+
 const WindowButton = new Lang.Class({
     Name: 'WindowButton',
 
     _init: function(metaWindow) {
         this.metaWindow = metaWindow;
 
-        let box = new St.BoxLayout();
+        this._windowTitle = new WindowTitle(this.metaWindow);
         this.actor = new St.Button({ style_class: 'window-button',
                                      x_fill: true,
-                                     child: box });
+                                     child: this._windowTitle.actor });
         this.actor._delegate = this;
 
         this.actor.connect('allocation-changed',
                            Lang.bind(this, this._updateIconGeometry));
-
-        let textureCache = St.TextureCache.get_default();
-        let icon = textureCache.bind_pixbuf_property(this.metaWindow, "icon");
-        this._icon = new St.Bin({ style_class: 'window-button-icon',
-                                  child: icon });
-        box.add(this._icon);
-        this._label = new St.Label();
-        box.add(this._label);
-
         this.actor.connect('clicked', Lang.bind(this, this._onClicked));
         this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
 
@@ -49,35 +85,16 @@ const WindowButton = new Lang.Class({
                                           Lang.bind(this, this._updateVisibility));
         this._updateVisibility();
 
-        this._notifyTitleId =
-            this.metaWindow.connect('notify::title',
-                                    Lang.bind(this, this._updateTitle));
-        this._notifyMinimizedId =
-            this.metaWindow.connect('notify::minimized',
-                                    Lang.bind(this, this._minimizedChanged));
         this._notifyFocusId =
             global.display.connect('notify::focus-window',
                                    Lang.bind(this, this._updateStyle));
-        this._minimizedChanged();
+        this._updateStyle();
     },
 
     _onClicked: function() {
         _minimizeOrActivateWindow(this.metaWindow);
     },
 
-    _minimizedChanged: function() {
-        this._icon.opacity = this.metaWindow.minimized ? 128 : 255;
-        this._updateTitle();
-        this._updateStyle();
-    },
-
-    _updateTitle: function() {
-        if (this.metaWindow.minimized)
-            this._label.text = '[%s]'.format(this.metaWindow.title);
-        else
-            this._label.text = this.metaWindow.title;
-    },
-
     _updateStyle: function() {
         if (this.metaWindow.minimized)
             this.actor.add_style_class_name('minimized');
@@ -110,8 +127,6 @@ const WindowButton = new Lang.Class({
 
     _onDestroy: function() {
         global.window_manager.disconnect(this._switchWorkspaceId);
-        this.metaWindow.disconnect(this._notifyTitleId);
-        this.metaWindow.disconnect(this._notifyMinimizedId);
         global.display.disconnect(this._notifyFocusId);
     }
 });



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