From f0e46f4b12db6f83ee6986c4d998ba4e2124499c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 13 Feb 2022 15:06:39 +0100 Subject: [PATCH] workspace-indicator: Change 'update' action to 'rename' Limiting the action to the row that changed instead of the list as a whole makes it easier to only update the changed value and not recreate the entire list. This doesn't make a difference right now, because we carefully sync the list to reuse existing rows, but we are about to back the list with a GListModel instead of updating it manually. Part-of: --- extensions/workspace-indicator/prefs.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/extensions/workspace-indicator/prefs.js b/extensions/workspace-indicator/prefs.js index 3cffbcfe..b0dfca8d 100644 --- a/extensions/workspace-indicator/prefs.js +++ b/extensions/workspace-indicator/prefs.js @@ -19,8 +19,8 @@ class WorkspaceSettingsWidget extends Adw.PreferencesGroup { self => self._addNewName()); this.install_action('workspaces.remove', 's', (self, name, param) => self._removeName(param.unpack())); - this.install_action('workspaces.update', null, - self => self._saveNames()); + this.install_action('workspaces.rename', '(ss)', + (self, name, param) => self._changeName(...param.deepUnpack())); } constructor() { @@ -59,8 +59,13 @@ class WorkspaceSettingsWidget extends Adw.PreferencesGroup { .filter(name => name !== removedName)); } - _saveNames() { - const names = this._getWorkspaceRows().map(row => row.name); + _changeName(oldName, newName) { + const names = this._settings.get_strv(WORKSPACE_KEY); + const pos = names.indexOf(oldName); + if (pos < 0) + return; + + names.splice(pos, 1, newName); this._settings.set_strv(WORKSPACE_KEY, names); } @@ -143,6 +148,8 @@ class WorkspaceRow extends Adw.PreferencesRow { this.child = this._stack; this._entry.connect('activate', () => { + this.activate_action('workspaces.rename', + new GLib.Variant('(ss)', [this.name, this._entry.text])); this.name = this._entry.text; this._stopEdit(); }); @@ -151,9 +158,6 @@ class WorkspaceRow extends Adw.PreferencesRow { return; this._stopEdit(); }); - - this.connect('notify::name', - () => this.activate_action('workspaces.update', null); } edit() {