[gnome-shell] extensionPrefs: Use actions for row controls



commit 059524b007290f2fe39ae603407a875963270ad7
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Nov 30 04:24:39 2019 +0100

    extensionPrefs: Use actions for row controls
    
    Actions are another mean to separate state and interactions from
    the UI. Start using them for the existing controls before adding
    more in follow-up commits.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/1968

 js/extensionPrefs/main.js             | 52 +++++++++++++++++++----------------
 js/extensionPrefs/ui/extension-row.ui |  8 +++++-
 2 files changed, 36 insertions(+), 24 deletions(-)
---
diff --git a/js/extensionPrefs/main.js b/js/extensionPrefs/main.js
index 10f022c0b2..ac9169ba53 100644
--- a/js/extensionPrefs/main.js
+++ b/js/extensionPrefs/main.js
@@ -350,11 +350,6 @@ var ExtensionsWindow = GObject.registerClass({
 
     _addExtensionRow(extension) {
         let row = new ExtensionRow(extension);
-
-        row.prefsButton.connect('clicked', () => {
-            this._showPrefs(row.uuid);
-        });
-
         row.show_all();
         this._extensionsList.add(row);
     }
@@ -474,13 +469,9 @@ var Expander = GObject.registerClass({
 var ExtensionRow = GObject.registerClass({
     GTypeName: 'ExtensionRow',
     Template: 'resource:///org/gnome/shell/ui/extension-row.ui',
-    Children: [
-        'prefsButton',
-    ],
     InternalChildren: [
         'nameLabel',
         'descriptionLabel',
-        'switch',
     ],
 }, class ExtensionRow extends Gtk.ListBoxRow {
     _init(extension) {
@@ -490,21 +481,38 @@ var ExtensionRow = GObject.registerClass({
         this._extension = extension;
         this._prefsModule = null;
 
-        let name = GLib.markup_escape_text(this.name, -1);
-        this._nameLabel.label = name;
-
-        let desc = this._extension.metadata.description.split('\n')[0];
-        this._descriptionLabel.label = desc;
+        this._actionGroup = new Gio.SimpleActionGroup();
+        this.insert_action_group('row', this._actionGroup);
 
-        this.prefsButton.visible = this.hasPrefs;
+        let action;
+        action = new Gio.SimpleAction({
+            name: 'show-prefs',
+            enabled: this.hasPrefs,
+        });
+        action.connect('activate', () => this.get_toplevel().openPrefs(this.uuid));
+        this._actionGroup.add_action(action);
 
-        this._notifyActiveId = this._switch.connect('notify::active', () => {
-            if (this._switch.active)
+        action = new Gio.SimpleAction({
+            name: 'enabled',
+            state: new GLib.Variant('b', false),
+        });
+        action.connect('activate', () => {
+            let state = action.get_state();
+            action.change_state(new GLib.Variant('b', !state.get_boolean()));
+        });
+        action.connect('change-state', (a, state) => {
+            if (state.get_boolean())
                 this._app.shellProxy.EnableExtensionRemote(this.uuid);
             else
                 this._app.shellProxy.DisableExtensionRemote(this.uuid);
         });
-        this._switch.connect('state-set', () => true);
+        this._actionGroup.add_action(action);
+
+        let name = GLib.markup_escape_text(this.name, -1);
+        this._nameLabel.label = name;
+
+        let desc = this._extension.metadata.description.split('\n')[0];
+        this._descriptionLabel.label = desc;
 
         this.connect('destroy', this._onDestroy.bind(this));
 
@@ -538,11 +546,9 @@ var ExtensionRow = GObject.registerClass({
     _updateState() {
         let state = this._extension.state === ExtensionState.ENABLED;
 
-        this._switch.block_signal_handler(this._notifyActiveId);
-        this._switch.state = state;
-        this._switch.unblock_signal_handler(this._notifyActiveId);
-
-        this._switch.sensitive = this._canToggle();
+        let action = this._actionGroup.lookup('enabled');
+        action.set_state(new GLib.Variant('b', state));
+        action.enabled = this._canToggle();
     }
 
     _onDestroy() {
diff --git a/js/extensionPrefs/ui/extension-row.ui b/js/extensionPrefs/ui/extension-row.ui
index 6f50f9addf..99ea655e1e 100644
--- a/js/extensionPrefs/ui/extension-row.ui
+++ b/js/extensionPrefs/ui/extension-row.ui
@@ -27,9 +27,14 @@
         <child>
           <object class="GtkButton" id="prefsButton">
             <property name="no_show_all">True</property>
+            <property name="visible"
+                      bind-source="prefsButton"
+                      bind-property="sensitive"
+                      bind-flags="sync-create"/>
             <property name="can_focus">True</property>
             <property name="receives_default">True</property>
             <property name="valign">center</property>
+            <property name="action-name">row.show-prefs</property>
             <style>
               <class name="circular"/>>
               <class name="image-button"/>>
@@ -46,10 +51,11 @@
           </packing>
         </child>
         <child>
-          <object class="GtkSwitch" id="switch">
+          <object class="GtkSwitch">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="valign">center</property>
+            <property name="action-name">row.enabled</property>
           </object>
           <packing>
             <property name="height">2</property>


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