[gnome-shell-extensions/wip/fmuellner/gtk4] wip: Port to GTK4



commit e8c927998fec6babf228ea094403d3be3557a274
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Apr 15 23:32:20 2020 +0200

    wip: Port to GTK4

 extensions/auto-move-windows/prefs.js   | 22 ++++++++------
 extensions/user-theme/prefs.js          | 53 +++++++++++++++------------------
 extensions/window-list/prefs.js         | 53 ++++++++++++++-------------------
 extensions/workspace-indicator/prefs.js | 35 +++++++---------------
 4 files changed, 69 insertions(+), 94 deletions(-)
---
diff --git a/extensions/auto-move-windows/prefs.js b/extensions/auto-move-windows/prefs.js
index 84f98ae..a404c33 100644
--- a/extensions/auto-move-windows/prefs.js
+++ b/extensions/auto-move-windows/prefs.js
@@ -24,8 +24,13 @@ const Columns = {
 
 const Widget = GObject.registerClass(
 class Widget extends Gtk.Grid {
-    _init(params) {
-        super._init(params);
+    _init() {
+        super._init({
+            margin_top: 12,
+            margin_bottom: 12,
+            margin_start: 12,
+            margin_end: 12,
+        });
         this.set_orientation(Gtk.Orientation.VERTICAL);
 
         this._settings = ExtensionUtils.getSettings();
@@ -79,7 +84,7 @@ class Widget extends Gtk.Grid {
 
         scrolled.add(this._treeView);
 
-        let toolbar = new Gtk.Toolbar({ icon_size: Gtk.IconSize.SMALL_TOOLBAR });
+        let toolbar = new Gtk.Box();
         toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR);
         this.add(toolbar);
 
@@ -119,7 +124,10 @@ class Widget extends Gtk.Grid {
         let grid = new Gtk.Grid({
             column_spacing: 10,
             row_spacing: 15,
-            margin: 10,
+            margin_top: 10,
+            margin_bottom: 10,
+            margin_start: 10,
+            margin_end: 10,
         });
         dialog._appChooser = new Gtk.AppChooserWidget({ show_all: true });
         dialog._appChooser.connect('application-selected', (w, appInfo) => {
@@ -167,7 +175,6 @@ class Widget extends Gtk.Grid {
 
             dialog.destroy();
         });
-        dialog.show_all();
     }
 
     _deleteSelected() {
@@ -275,8 +282,5 @@ function init() {
 }
 
 function buildPrefsWidget() {
-    let widget = new Widget({ margin: 12 });
-    widget.show_all();
-
-    return widget;
+    return new Widget();
 }
diff --git a/extensions/user-theme/prefs.js b/extensions/user-theme/prefs.js
index e22b6a3..0f8df62 100644
--- a/extensions/user-theme/prefs.js
+++ b/extensions/user-theme/prefs.js
@@ -29,13 +29,16 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
         this.add(box);
 
         this._list = new Gtk.ListBox({
+            show_separators: true,
             halign: Gtk.Align.CENTER,
             valign: Gtk.Align.START,
             hexpand: true,
-            margin: 60,
+            margin_top: 60,
+            margin_bottom: 60,
+            margin_start: 60,
+            margin_end: 60,
         });
         this._list.get_style_context().add_class('frame');
-        this._list.set_header_func(this._updateHeader.bind(this));
         box.add(this._list);
 
         this._actionGroup = new Gio.SimpleActionGroup();
@@ -89,11 +92,10 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
     }
 
     _addTheme(name) {
-        const row = new ThemeRow(name);
+        const row = new ThemeRow(name, this._settings);
         this._rows.set(name, row);
 
         this._list.add(row);
-        row.show_all();
     }
 
     async _enumerateDir(dir) {
@@ -120,27 +122,26 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
 
         return fileInfos.map(info => info.get_name());
     }
-
-    _updateHeader(row, before) {
-        if (!before || row.get_header())
-            return;
-        row.set_header(new Gtk.Separator());
-    }
 });
 
 const ThemeRow = GObject.registerClass(
 class ThemeRow extends Gtk.ListBoxRow {
-    _init(name) {
-        this._name = new GLib.Variant('s', name);
+    _init(name, settings) {
+        this._name = name;
+        this._settings = settings;
 
+        const target = new GLib.Variant('s', name);
         super._init({
             action_name: 'theme.name',
-            action_target: this._name,
+            action_target: target,
         });
 
         const box = new Gtk.Box({
             spacing: 12,
-            margin: 12,
+            margin_top: 12,
+            margin_bottom: 12,
+            margin_start: 12,
+            margin_end: 12,
         });
         this.add(box);
 
@@ -158,22 +159,19 @@ class ThemeRow extends Gtk.ListBoxRow {
         });
         box.add(this._checkmark);
 
-        box.show_all();
+        const id = this._settings.connect('changed::name',
+            this._syncCheckmark.bind(this));
+        this._syncCheckmark();
 
-        const id = this.connect('parent-set', () => {
-            this.disconnect(id);
-
-            const actionGroup = this.get_action_group('theme');
-            actionGroup.connect('action-state-changed::name',
-                this._syncCheckmark.bind(this));
-            this._syncCheckmark();
+        this.connect('destroy', () => {
+            this._settings.disconnect(id);
+            this._settings = null;
         });
     }
 
     _syncCheckmark() {
-        const actionGroup = this.get_action_group('theme');
-        const state = actionGroup.get_action_state('name');
-        this._checkmark.opacity = this._name.equal(state);
+        const visible = this._name === this._settings.get_string('name');
+        this._checkmark.opacity = visible ? 1. : 0.;
     }
 });
 
@@ -181,8 +179,5 @@ function init() {
 }
 
 function buildPrefsWidget() {
-    let widget = new UserThemePrefsWidget();
-    widget.show_all();
-
-    return widget;
+    return new UserThemePrefsWidget();
 }
diff --git a/extensions/window-list/prefs.js b/extensions/window-list/prefs.js
index a8e9146..7716704 100644
--- a/extensions/window-list/prefs.js
+++ b/extensions/window-list/prefs.js
@@ -1,7 +1,7 @@
 // -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
 /* exported init buildPrefsWidget */
 
-const { Gio, GObject, Gtk } = imports.gi;
+const { Gio, GLib, GObject, Gtk } = imports.gi;
 
 const Gettext = imports.gettext.domain('gnome-shell-extensions');
 const _ = Gettext.gettext;
@@ -15,12 +15,15 @@ function init() {
 
 const WindowListPrefsWidget = GObject.registerClass(
 class WindowListPrefsWidget extends Gtk.Grid {
-    _init(params) {
-        super._init(params);
-
-        this.margin = 24;
-        this.row_spacing = 6;
-        this.orientation = Gtk.Orientation.VERTICAL;
+    _init() {
+        super._init({
+            margin_top: 24,
+            margin_bottom: 24,
+            margin_start: 24,
+            margin_end: 24,
+            row_spacing: 6,
+            orientation: Gtk.Orientation.VERTICAL,
+        });
 
         let groupingLabel = '<b>%s</b>'.format(_('Window Grouping'));
         this.add(new Gtk.Label({
@@ -28,18 +31,20 @@ class WindowListPrefsWidget extends Gtk.Grid {
             halign: Gtk.Align.START,
         }));
 
-        let align = new Gtk.Alignment({ left_padding: 12 });
-        this.add(align);
-
         let grid = new Gtk.Grid({
             orientation: Gtk.Orientation.VERTICAL,
             row_spacing: 6,
             column_spacing: 6,
+            margin_start: 12,
         });
-        align.add(grid);
+        this.add(grid);
 
         this._settings = ExtensionUtils.getSettings();
-        let currentMode = this._settings.get_string('grouping-mode');
+        this._actionGroup = new Gio.SimpleActionGroup();
+        for (const key of this._settings.list_keys())
+            this._actionGroup.add_action(this._settings.create_action(key));
+        this.insert_action_group('window-list', this._actionGroup);
+
         let range = this._settings.get_range('grouping-mode');
         let modes = range.deep_unpack()[1].deep_unpack();
 
@@ -50,7 +55,6 @@ class WindowListPrefsWidget extends Gtk.Grid {
         };
 
         let radio = null;
-        let currentRadio = null;
         for (let i = 0; i < modes.length; i++) {
             let mode = modes[i];
             let label = modeLabels[mode];
@@ -60,43 +64,30 @@ class WindowListPrefsWidget extends Gtk.Grid {
             }
 
             radio = new Gtk.RadioButton({
-                active: !i,
                 label,
                 group: radio,
+                action_name: 'window-list.grouping-mode',
+                action_target: new GLib.Variant('s', mode),
             });
             grid.add(radio);
-
-            if (currentMode === mode)
-                currentRadio = radio;
-
-            radio.connect('toggled', button => {
-                if (button.active)
-                    this._settings.set_string('grouping-mode', mode);
-            });
         }
 
-        if (currentRadio)
-            currentRadio.active = true;
-
         let check = new Gtk.CheckButton({
             label: _('Show on all monitors'),
+            action_name: 'window-list.show-on-all-monitors',
             margin_top: 6,
         });
-        this._settings.bind('show-on-all-monitors', check, 'active', Gio.SettingsBindFlags.DEFAULT);
         this.add(check);
 
         check = new Gtk.CheckButton({
             label: _('Show windows from all workspaces'),
+            action_name: 'window-list.display-all-workspaces',
             margin_top: 6,
         });
-        this._settings.bind('display-all-workspaces', check, 'active', Gio.SettingsBindFlags.DEFAULT);
         this.add(check);
     }
 });
 
 function buildPrefsWidget() {
-    let widget = new WindowListPrefsWidget();
-    widget.show_all();
-
-    return widget;
+    return new WindowListPrefsWidget();
 }
diff --git a/extensions/workspace-indicator/prefs.js b/extensions/workspace-indicator/prefs.js
index 011953b..698acb1 100644
--- a/extensions/workspace-indicator/prefs.js
+++ b/extensions/workspace-indicator/prefs.js
@@ -1,7 +1,7 @@
 // -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
 /* exported init buildPrefsWidget */
 
-const { Gdk, Gio, GLib, GObject, Gtk, Pango } = imports.gi;
+const { Gio, GLib, GObject, Gtk, Pango } = imports.gi;
 
 const Gettext = imports.gettext.domain('gnome-shell-extensions');
 const _ = Gettext.gettext;
@@ -94,8 +94,6 @@ class WorkspaceSettingsWidget extends Gtk.ScrolledWindow {
         this._settings.connect(`changed::${WORKSPACE_KEY}`,
             this._sync.bind(this));
         this._sync();
-
-        this.show_all();
     }
 
     _getWorkspaceRows() {
@@ -129,6 +127,13 @@ class WorkspaceRow extends Gtk.ListBoxRow {
     _init(name) {
         super._init({ name });
 
+        const controller = new Gtk.ShortcutController();
+        controller.add_shortcut(new Gtk.Shortcut({
+            trigger: Gtk.ShortcutTrigger.parse_string('Escape'),
+            action: Gtk.CallbackAction.new(this._stopEdit.bind(this)),
+        }));
+        this.add_controller(controller);
+
         const box = new Gtk.Box({
             spacing: 12,
             margin_top: 6,
@@ -147,14 +152,10 @@ class WorkspaceRow extends Gtk.ListBoxRow {
             GObject.BindingFlags.SYNC_CREATE);
         box.add(label);
 
-        const image = new Gtk.Image({
-            icon_name: 'edit-delete-symbolic',
-            pixel_size: 16,
-        });
         const button = new Gtk.Button({
             action_name: 'workspaces.remove',
             action_target: new GLib.Variant('s', name),
-            image,
+            icon_name: 'edit-delete-symbolic',
         });
         box.add(button);
 
@@ -176,17 +177,11 @@ class WorkspaceRow extends Gtk.ListBoxRow {
                 return;
             this._stopEdit();
         });
-        this._entry.connect('key-press-event',
-            this._onEntryKeyPress.bind(this));
 
         this.connect('notify::name', () => {
             button.action_target = new GLib.Variant('s', this.name);
-
-            const actionGroup = this.get_action_group('workspaces');
-            actionGroup.activate_action('update', null);
+            this.activate_action('workspaces.update', null);
         });
-
-        this.show_all();
     }
 
     edit() {
@@ -199,14 +194,6 @@ class WorkspaceRow extends Gtk.ListBoxRow {
         this.grab_focus();
         this._stack.visible_child_name = 'display';
     }
-
-    _onEntryKeyPress(entry, event) {
-        const [, keyval] = event.get_keyval();
-        if (keyval !== Gdk.KEY_Escape)
-            return Gdk.EVENT_PROPAGATE;
-        this._stopEdit();
-        return Gdk.EVENT_STOP;
-    }
 });
 
 const NewWorkspaceRow = GObject.registerClass(
@@ -225,8 +212,6 @@ class NewWorkspaceRow extends Gtk.ListBoxRow {
             margin_start: 12,
             margin_end: 12,
         }));
-
-        this.show_all();
     }
 });
 


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