[gnome-shell] extensionPrefs: Split out window class



commit f49e20bbaed6ad3a56228a49918e633df5c192ad
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Nov 30 02:48:18 2019 +0100

    extensionPrefs: Split out window class
    
    Currently the main window is a plain Gtk.ApplicationWindow that is
    built and managed from within the application.
    
    As the application becomes more complex, it makes sense to decouple
    the two and handle the window from a separate ExtensionsWindow class.
    
    Not least this is a prerequisite of using a widget template for the
    window.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/1968

 js/extensionPrefs/main.js | 164 +++++++++++++++++++++++++++-------------------
 1 file changed, 95 insertions(+), 69 deletions(-)
---
diff --git a/js/extensionPrefs/main.js b/js/extensionPrefs/main.js
index 5343fd55d5..a680112d62 100644
--- a/js/extensionPrefs/main.js
+++ b/js/extensionPrefs/main.js
@@ -30,18 +30,80 @@ class Application extends Gtk.Application {
             application_id: 'org.gnome.shell.ExtensionPrefs',
             flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
         });
+    }
+
+    get shellProxy() {
+        return this._shellProxy;
+    }
+
+    vfunc_activate() {
+        this._window.present();
+    }
+
+    vfunc_startup() {
+        super.vfunc_startup();
+
+        this._shellProxy = new GnomeShellProxy(Gio.DBus.session, 'org.gnome.Shell', '/org/gnome/Shell');
+        this._window = new ExtensionsWindow({ application: this });
+    }
+
+    vfunc_command_line(commandLine) {
+        let args = commandLine.get_arguments();
+
+        if (args.length) {
+            let uuid = args[0];
+
+            // Strip off "extension:///" prefix which fakes a URI, if it exists
+            uuid = stripPrefix(uuid, 'extension:///');
+
+            this._window.openPrefs(uuid);
+        } else {
+            this.activate();
+        }
+        return 0;
+    }
+});
+
+var ExtensionsWindow = GObject.registerClass(
+class ExtensionsWindow extends Gtk.ApplicationWindow {
+    _init(params) {
+        super._init(params);
 
         this._startupUuid = null;
         this._loaded = false;
-        this._skipMainWindow = false;
-        this._shellProxy = null;
+        this._prefsDialog = null;
+
+        this._buildUI();
+
+        this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
+        this._settings.bind('disable-user-extensions',
+            this._killSwitch, 'active',
+            Gio.SettingsBindFlags.DEFAULT | Gio.SettingsBindFlags.INVERT_BOOLEAN);
+
+        this._extensionSelector.set_sort_func(this._sortList.bind(this));
+        this._extensionSelector.set_header_func(this._updateHeader.bind(this));
+
+        this._shellProxy.connectSignal('ExtensionStateChanged',
+            this._onExtensionStateChanged.bind(this));
+
+        this._scanExtensions();
     }
 
-    get shellProxy() {
-        return this._shellProxy;
+    get _shellProxy() {
+        return this.application.shellProxy;
+    }
+
+    openPrefs(uuid) {
+        if (!this._loaded)
+            this._startupUuid = uuid;
+        else if (!this._showPrefs(uuid))
+            this.present();
     }
 
     _showPrefs(uuid) {
+        if (this._prefsDialog)
+            return false;
+
         let row = this._extensionSelector.get_children().find(c => {
             return c.uuid === uuid && c.hasPrefs;
         });
@@ -57,29 +119,33 @@ class Application extends Gtk.Application {
             widget = this._buildErrorUI(row, e);
         }
 
-        let dialog = new Gtk.Window({
-            modal: !this._skipMainWindow,
+        this._prefsDialog = new Gtk.Window({
+            application: this.application,
+            default_width: 600,
+            default_height: 400,
+            modal: this.visible,
             type_hint: Gdk.WindowTypeHint.DIALOG,
+            window_position: Gtk.WindowPosition.CENTER,
         });
-        dialog.set_titlebar(new Gtk.HeaderBar({
+
+        this._prefsDialog.set_titlebar(new Gtk.HeaderBar({
             show_close_button: true,
             title: row.name,
             visible: true,
         }));
 
-        if (this._skipMainWindow) {
-            this.add_window(dialog);
-            if (this._window)
-                this._window.destroy();
-            this._window = dialog;
-            this._window.window_position = Gtk.WindowPosition.CENTER;
-        } else {
-            dialog.transient_for = this._window;
-        }
+        if (this.visible)
+            this._prefsDialog.transient_for = this;
+
+        this._prefsDialog.connect('destroy', () => {
+            this._prefsDialog = null;
 
-        dialog.set_default_size(600, 400);
-        dialog.add(widget);
-        dialog.show();
+            if (!this.visible)
+                this.destroy();
+        });
+
+        this._prefsDialog.add(widget);
+        this._prefsDialog.show();
 
         return true;
     }
@@ -200,27 +266,23 @@ class Application extends Gtk.Application {
     }
 
     _buildUI() {
-        this._window = new Gtk.ApplicationWindow({ application: this,
-                                                   window_position: Gtk.WindowPosition.CENTER });
-
-        this._window.set_default_size(800, 500);
+        this.set({
+            window_position: Gtk.WindowPosition.CENTER,
+            default_width: 800,
+            default_height: 500,
+        });
 
         this._titlebar = new Gtk.HeaderBar({ show_close_button: true,
                                              title: _("Shell Extensions") });
-        this._window.set_titlebar(this._titlebar);
-
-        let killSwitch = new Gtk.Switch({ valign: Gtk.Align.CENTER });
-        this._titlebar.pack_end(killSwitch);
+        this.set_titlebar(this._titlebar);
 
-        this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
-        this._settings.bind('disable-user-extensions', killSwitch, 'active',
-                            Gio.SettingsBindFlags.DEFAULT |
-                            Gio.SettingsBindFlags.INVERT_BOOLEAN);
+        this._killSwitch = new Gtk.Switch({ valign: Gtk.Align.CENTER });
+        this._titlebar.pack_end(this._killSwitch);
 
         this._mainStack = new Gtk.Stack({
             transition_type: Gtk.StackTransitionType.CROSSFADE,
         });
-        this._window.add(this._mainStack);
+        this.add(this._mainStack);
 
         let scroll = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER });
 
@@ -233,11 +295,7 @@ class Application extends Gtk.Application {
         this._mainStack.add_named(scroll, 'listing');
         this._mainStack.add_named(new EmptyPlaceholder(), 'placeholder');
 
-        this._shellProxy = new GnomeShellProxy(Gio.DBus.session, 'org.gnome.Shell', '/org/gnome/Shell');
-        this._shellProxy.connectSignal('ExtensionStateChanged',
-            this._onExtensionStateChanged.bind(this));
-
-        this._window.show_all();
+        this.show_all();
     }
 
     _sortList(row1, row2) {
@@ -309,40 +367,8 @@ class Application extends Gtk.Application {
         if (this._startupUuid)
             this._showPrefs(this._startupUuid);
         this._startupUuid = null;
-        this._skipMainWindow = false;
         this._loaded = true;
     }
-
-    vfunc_activate() {
-        this._window.present();
-    }
-
-    vfunc_startup() {
-        super.vfunc_startup();
-
-        this._buildUI();
-        this._scanExtensions();
-    }
-
-    vfunc_command_line(commandLine) {
-        this.activate();
-        let args = commandLine.get_arguments();
-
-        if (args.length) {
-            let uuid = args[0];
-
-            this._skipMainWindow = true;
-
-            // Strip off "extension:///" prefix which fakes a URI, if it exists
-            uuid = stripPrefix(uuid, "extension:///");
-
-            if (!this._loaded)
-                this._startupUuid = uuid;
-            else if (!this._showPrefs(uuid))
-                this._skipMainWindow = false;
-        }
-        return 0;
-    }
 });
 
 var Expander = GObject.registerClass({


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