[gnome-shell-extensions/wip/rstrode/heads-up-display: 41/62] workspace-indicator: Refactor workspace signal handlers




commit ea211f3cfd522dfbbd561183fb003cdc5b0899fc
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Jun 9 23:09:12 2019 +0000

    workspace-indicator: Refactor workspace signal handlers
    
    We are about to support a separate representation if horizontal
    workspaces are used. To prepare for that, rename the handlers to
    something more generic and split out menu-specific bits into a
    dedicated help function.
    
    https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/71

 extensions/workspace-indicator/extension.js | 31 +++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/extensions/workspace-indicator/extension.js b/extensions/workspace-indicator/extension.js
index 7ebc1f0..34fc275 100644
--- a/extensions/workspace-indicator/extension.js
+++ b/extensions/workspace-indicator/extension.js
@@ -34,13 +34,12 @@ class WorkspaceIndicator extends PanelMenu.Button {
         this._workspaceSection = new PopupMenu.PopupMenuSection();
         this.menu.addMenuItem(this._workspaceSection);
 
-        this._workspaceManagerSignals = [];
-        this._workspaceManagerSignals.push(workspaceManager.connect_after('workspace-added',
-                                                                          
this._createWorkspacesSection.bind(this)));
-        this._workspaceManagerSignals.push(workspaceManager.connect_after('workspace-removed',
-                                                                          
this._createWorkspacesSection.bind(this)));
-        this._workspaceManagerSignals.push(workspaceManager.connect_after('workspace-switched',
-                                                                          this._updateIndicator.bind(this)));
+        this._workspaceManagerSignals = [
+            workspaceManager.connect_after('notify::n-workspaces',
+                this._nWorkspacesChanged.bind(this)),
+            workspaceManager.connect_after('workspace-switched',
+                this._onWorkspaceSwitched.bind(this))
+        ];
 
         this.connect('scroll-event', this._onScrollEvent.bind(this));
         this._createWorkspacesSection();
@@ -66,14 +65,26 @@ class WorkspaceIndicator extends PanelMenu.Button {
         super._onDestroy();
     }
 
-    _updateIndicator() {
-        this._workspacesItems[this._currentWorkspace].setOrnament(PopupMenu.Ornament.NONE);
+    _onWorkspaceSwitched() {
         this._currentWorkspace = global.workspace_manager.get_active_workspace_index();
-        this._workspacesItems[this._currentWorkspace].setOrnament(PopupMenu.Ornament.DOT);
+
+        this._updateMenuOrnament();
 
         this._statusLabel.set_text(this._labelText());
     }
 
+    _nWorkspacesChanged() {
+        this._createWorkspacesSection();
+    }
+
+    _updateMenuOrnament() {
+        for (let i = 0; i < this._workspacesItems.length; i++) {
+            this._workspacesItems[i].setOrnament(i == this._currentWorkspace
+                ? PopupMenu.Ornament.DOT
+                : PopupMenu.Ornament.NONE);
+        }
+    }
+
     _labelText(workspaceIndex) {
         if (workspaceIndex == undefined) {
             workspaceIndex = this._currentWorkspace;


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