[gnome-shell-extensions] auto-move-windows: Change 'update' action to 'rename'
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] auto-move-windows: Change 'update' action to 'rename'
- Date: Fri, 18 Feb 2022 12:26:38 +0000 (UTC)
commit 725cf83551ef22d0ad5f49468731650547bc44d2
Author: Florian Müllner <fmuellner gnome org>
Date: Sun Feb 13 15:23:20 2022 +0100
auto-move-windows: 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>
extensions/auto-move-windows/prefs.js | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/extensions/auto-move-windows/prefs.js b/extensions/auto-move-windows/prefs.js
index 793db06..125b431 100644
--- a/extensions/auto-move-windows/prefs.js
+++ b/extensions/auto-move-windows/prefs.js
@@ -19,7 +19,8 @@ class AutoMoveSettingsWidget extends Adw.PreferencesGroup {
this.install_action('rules.add', null, self => self._addNewRule());
this.install_action('rules.remove', 's',
(self, name, param) => self._removeRule(param.unpack()));
- this.install_action('rules.update', null, self => self._saveRules());
+ this.install_action('rules.change-workspace', '(si)',
+ (self, name, param) => self._changeWorkspace(...param.deepUnpack()));
}
constructor() {
@@ -67,24 +68,28 @@ class AutoMoveSettingsWidget extends Adw.PreferencesGroup {
}));
}
- _saveRules() {
- this._settings.set_strv(SETTINGS_KEY,
- this._getRuleRows().map(row => `${row.id}:${row.value}`));
- }
+ _changeWorkspace(id, workspace) {
+ const rules = this._settings.get_strv(SETTINGS_KEY);
+ const pos = rules.findIndex(r => r.startsWith(`${id}:`));
+ if (pos < 0)
+ return;
+
+ rules.splice(pos, 1, `${id}:${workspace}`);
- _getRuleRows() {
- return [...this._list].filter(row => !!row.id);
+ this._settings.block_signal_handler(this._changedId);
+ this._settings.set_strv(SETTINGS_KEY, rules);
+ this._settings.unblock_signal_handler(this._changedId);
}
_sync() {
- const oldRules = this._getRuleRows();
+ const oldRules = [...this._list].filter(row => !!row.id);
const newRules = this._settings.get_strv(SETTINGS_KEY).map(entry => {
const [id, value] = entry.split(':');
return { id, value };
});
this._settings.block_signal_handler(this._changedId);
- this.action_set_enabled('rules.update', false);
+ this.action_set_enabled('rules.change-workspace', false);
newRules.forEach(({ id, value }, index) => {
const row = oldRules.find(r => r.id === id);
@@ -102,7 +107,7 @@ class AutoMoveSettingsWidget extends Adw.PreferencesGroup {
removed.forEach(r => this._list.remove(r));
this._settings.unblock_signal_handler(this._changedId);
- this.action_set_enabled('rules.update', true);
+ this.action_set_enabled('rules.change-workspace', true);
}
}
@@ -209,8 +214,10 @@ class RuleRow extends Adw.ActionRow {
});
this.add_suffix(button);
- this.connect('notify::value',
- () => this.activate_action('rules.update', null));
+ this.connect('notify::value', () => {
+ this.activate_action('rules.change-workspace',
+ new GLib.Variant('(si)', [this.id, this.value]));
+ });
}
get id() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]