[gnome-shell-extensions] user-theme: Use libadwaita for preferences
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell-extensions] user-theme: Use libadwaita for preferences
- Date: Tue, 8 Feb 2022 19:26:04 +0000 (UTC)
commit 01537b401f68c5be9b549e711c18c4809af6c3ed
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Jul 30 07:29:33 2021 +0200
user-theme: Use libadwaita for preferences
libadwaita has now become stable and will be part of the GNOME 42
platform. Time to embrace it and get fancier preferences with
less code.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/209>
extensions/user-theme/prefs.js | 78 +++++++-----------------------------------
1 file changed, 13 insertions(+), 65 deletions(-)
---
diff --git a/extensions/user-theme/prefs.js b/extensions/user-theme/prefs.js
index 214da4a..c84e444 100644
--- a/extensions/user-theme/prefs.js
+++ b/extensions/user-theme/prefs.js
@@ -4,7 +4,7 @@
// we use async/await here to not block the mainloop, not to parallelize
/* eslint-disable no-await-in-loop */
-const { Gio, GLib, GObject, Gtk } = imports.gi;
+const { Adw, Gio, GLib, GObject, Gtk } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
@@ -19,31 +19,12 @@ Gio._promisify(Gio.FileEnumerator.prototype,
'next_files_async', 'next_files_finish');
const UserThemePrefsWidget = GObject.registerClass(
-class UserThemePrefsWidget extends Gtk.ScrolledWindow {
+class UserThemePrefsWidget extends Adw.PreferencesGroup {
_init() {
- super._init({
- hscrollbar_policy: Gtk.PolicyType.NEVER,
- });
-
- const box = new Gtk.Box();
- this.set_child(box);
-
- this._list = new Gtk.ListBox({
- selection_mode: Gtk.SelectionMode.NONE,
- show_separators: true,
- halign: Gtk.Align.CENTER,
- valign: Gtk.Align.START,
- hexpand: true,
- margin_start: 60,
- margin_end: 60,
- margin_top: 60,
- margin_bottom: 60,
- });
- this._list.get_style_context().add_class('frame');
- box.append(this._list);
+ super._init({ title: 'Themes' });
this._actionGroup = new Gio.SimpleActionGroup();
- this._list.insert_action_group('theme', this._actionGroup);
+ this.insert_action_group('theme', this._actionGroup);
this._settings = ExtensionUtils.getSettings();
this._actionGroup.add_action(
@@ -93,10 +74,10 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
}
_addTheme(name) {
- const row = new ThemeRow(name, this._settings);
+ const row = new ThemeRow(name);
this._rows.set(name, row);
- this._list.append(row);
+ this.add(row);
}
async _enumerateDir(dir) {
@@ -126,51 +107,18 @@ class UserThemePrefsWidget extends Gtk.ScrolledWindow {
});
const ThemeRow = GObject.registerClass(
-class ThemeRow extends Gtk.ListBoxRow {
- _init(name, settings) {
- this._name = name;
- this._settings = settings;
-
- const box = new Gtk.Box({
- spacing: 12,
- margin_start: 12,
- margin_end: 12,
- margin_top: 12,
- margin_bottom: 12,
- });
- super._init({
+class ThemeRow extends Adw.ActionRow {
+ _init(name) {
+ const check = new Gtk.CheckButton({
action_name: 'theme.name',
action_target: new GLib.Variant('s', name),
- child: box,
});
- box.append(new Gtk.Label({
- label: name || 'Default',
- hexpand: true,
- xalign: 0,
- max_width_chars: 25,
- width_chars: 25,
- }));
-
- this._checkmark = new Gtk.Image({
- icon_name: 'emblem-ok-symbolic',
- pixel_size: 16,
- });
- box.append(this._checkmark);
-
- const id = this._settings.connect('changed::name',
- this._syncCheckmark.bind(this));
- this._syncCheckmark();
-
- this.connect('destroy', () => {
- this._settings.disconnect(id);
- this._settings = null;
+ super._init({
+ title: name || 'Default',
+ activatable_widget: check,
});
- }
-
- _syncCheckmark() {
- const visible = this._name === this._settings.get_string('name');
- this._checkmark.opacity = visible ? 1. : 0;
+ this.add_prefix(check);
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]