From c516f059272dbc3cdbfcd91e31a4eacfe91ed15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 9 Jun 2019 23:09:12 +0000 Subject: [PATCH] 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 helper function. https://gitlab.gnome.org/GNOME/gnome-shell-extensions/merge_requests/71 --- extensions/workspace-indicator/extension.js | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/extensions/workspace-indicator/extension.js b/extensions/workspace-indicator/extension.js index 3f21685d..00959cb0 100644 --- a/extensions/workspace-indicator/extension.js +++ b/extensions/workspace-indicator/extension.js @@ -34,12 +34,10 @@ class WorkspaceIndicator extends PanelMenu.Button { this.menu.addMenuItem(this._workspaceSection); this._workspaceManagerSignals = [ - workspaceManager.connect_after('workspace-added', - this._createWorkspacesSection.bind(this)), - workspaceManager.connect_after('workspace-removed', - this._createWorkspacesSection.bind(this)), + workspaceManager.connect_after('notify::n-workspaces', + this._nWorkspacesChanged.bind(this)), workspaceManager.connect_after('workspace-switched', - this._updateIndicator.bind(this)) + this._onWorkspaceSwitched.bind(this)) ]; this.connect('scroll-event', this._onScrollEvent.bind(this)); @@ -66,14 +64,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;