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: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/218>
This commit is contained in:
Florian Müllner
2022-02-13 15:06:39 +01:00
parent 57f7f21ecb
commit f0e46f4b12
+11 -7
View File
@@ -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() {