[gnome-shell-extensions/wip/fmuellner/gtk4: 13/13] wip: Port to GTK4
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions/wip/fmuellner/gtk4: 13/13] wip: Port to GTK4
- Date: Mon, 4 May 2020 13:12:42 +0000 (UTC)
commit d8b65e1ec07cd64241e41941dacce2abeb6a4e79
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 | 30 ++++---------------
extensions/user-theme/prefs.js | 53 +++++++++++++++------------------
extensions/window-list/prefs.js | 2 --
extensions/workspace-indicator/prefs.js | 35 +++++++---------------
4 files changed, 40 insertions(+), 80 deletions(-)
---
diff --git a/extensions/auto-move-windows/prefs.js b/extensions/auto-move-windows/prefs.js
index 1324451..9b7762c 100644
--- a/extensions/auto-move-windows/prefs.js
+++ b/extensions/auto-move-windows/prefs.js
@@ -40,8 +40,8 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
valign: Gtk.Align.START,
+ show_separators: true,
});
- this._list.set_header_func(this._updateHeader.bind(this));
box.add(this._list);
const context = this._list.get_style_context();
@@ -84,12 +84,10 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._sync();
this.connect('destroy', () => this._settings.run_dispose());
-
- this.show_all();
}
_onAddActivated() {
- const dialog = new NewRuleDialog(this.get_toplevel());
+ const dialog = new NewRuleDialog(this.get_root());
dialog.connect('response', (dlg, id) => {
const appInfo = id === Gtk.ResponseType.OK
? dialog.get_widget().get_app_info() : null;
@@ -101,6 +99,7 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
}
dialog.destroy();
});
+ dialog.show();
}
_onRemoveActivated(action, param) {
@@ -144,12 +143,6 @@ class AutoMoveSettingsWidget extends Gtk.ScrolledWindow {
this._settings.unblock_signal_handler(this._changedId);
this._updateAction.enabled = true;
}
-
- _updateHeader(row, before) {
- if (!before || row.get_header())
- return;
- row.set_header(new Gtk.Separator());
- }
});
const RuleRow = GObject.registerClass({
@@ -212,21 +205,14 @@ const RuleRow = GObject.registerClass({
const button = new Gtk.Button({
action_name: 'rules.remove',
action_target: new GLib.Variant('s', this.id),
- image: new Gtk.Image({
- icon_name: 'edit-delete-symbolic',
- pixel_size: 16,
- }),
+ icon_name: 'edit-delete-symbolic',
});
box.add(button);
this.add(box);
- this.connect('notify::value', () => {
- const actionGroup = this.get_action_group('rules');
- actionGroup.activate_action('update', null);
- });
-
- this.show_all();
+ this.connect('notify::value',
+ () => this.activate_action('rules.update', null));
}
get id() {
@@ -250,8 +236,6 @@ class NewRuleRow extends Gtk.ListBoxRow {
margin_start: 12,
margin_end: 12,
}));
-
- this.show_all();
}
});
@@ -273,8 +257,6 @@ class NewRuleDialog extends Gtk.AppChooserDialog {
this.get_widget().connect('application-selected',
this._updateSensitivity.bind(this));
this._updateSensitivity();
-
- this.show();
}
_updateSensitivity() {
diff --git a/extensions/user-theme/prefs.js b/extensions/user-theme/prefs.js
index 241e3c9..6ee38b3 100644
--- a/extensions/user-theme/prefs.js
+++ b/extensions/user-theme/prefs.js
@@ -30,13 +30,16 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
this._list = new Gtk.ListBox({
selection_mode: Gtk.SelectionMode.NONE,
+ 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();
@@ -90,11 +93,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) {
@@ -121,27 +123,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);
@@ -159,22 +160,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.;
}
});
@@ -182,8 +180,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 58ebf2a..0a6cabd 100644
--- a/extensions/window-list/prefs.js
+++ b/extensions/window-list/prefs.js
@@ -101,8 +101,6 @@ class WindowListPrefsWidget extends Gtk.Box {
});
this._settings.bind('display-all-workspaces', check, 'active', Gio.SettingsBindFlags.DEFAULT);
this.add(check);
-
- this.show_all();
}
});
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]