From 9969d17a688d6d8e1764d7242fd4c8b838ec2228 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 10 Dec 2023 14:32:02 +0100 Subject: Adding upstream version 20231210. Signed-off-by: Daniel Baumann --- extensions/45/middleclickclose/src/prefs.js | 108 ++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 extensions/45/middleclickclose/src/prefs.js (limited to 'extensions/45/middleclickclose/src/prefs.js') diff --git a/extensions/45/middleclickclose/src/prefs.js b/extensions/45/middleclickclose/src/prefs.js new file mode 100644 index 0000000..91d9f13 --- /dev/null +++ b/extensions/45/middleclickclose/src/prefs.js @@ -0,0 +1,108 @@ +/** + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +**/ + +import Adw from 'gi://Adw'; +import Gtk from 'gi://Gtk'; +import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; + +import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js'; + +export default class MiddleClickClosePreferences extends ExtensionPreferences { + getPreferencesWidget() { + let page = new Adw.PreferencesPage(); + let group = new Adw.PreferencesGroup(); + + group.add(this.buildPreference("close-button", { + nicks: { + left: _("Left"), + middle: _("Middle"), + right: _("Right"), + 'button 4': _("Button 4"), + 'button 5': _("Button 5"), + 'button 6': _("Button 6"), + 'button 7': _("Button 7"), + 'button 8': _("Button 8"), + 'button 9': _("Button 9"), + }, + })); + + group.add(this.buildPreference("rearrange-delay", { + step: 50, + })); + + page.add(group); + return page; + } + + buildPreference(key, opts) { + opts ??= {} + + const settings = this.getSettings(); + const setting = settings.create_action(key); + const schema = settings.settings_schema.get_key(key); + + opts.title ??= schema.get_summary() || schema.get_name(); + opts.subtitle ??= schema.get_description(); + + const ty = schema.get_value_type().dup_string(); + const [range_ty, range] = schema.get_range().recursiveUnpack(); + + if (range_ty == "enum") { + opts.nicks ??= {}; + let row = new Adw.ComboRow({ + title: opts.title, + subtitle: opts.subtitle, + model: new Gtk.StringList({ strings: range.map(nick => opts.nicks[nick]) }), + selected: range.indexOf(setting.state.unpack()), + }); + + row.connect('notify::selected', () => { + setting.activate(GLib.Variant.new_string(range[row.selected])); + }); + + return row; + } else if (range_ty == "range") { + opts.lower ??= range[0] + opts.upper ??= range[1] + } + + if (["i"].includes(ty)) { + let adjustment = new Gtk.Adjustment({ + lower: opts.lower, + upper: opts.upper, + step_increment: opts.step, + value: setting.state.unpack(), + }); + + let row = new Adw.SpinRow({ + title: opts.title, + subtitle: opts.subtitle, + numeric: true, + adjustment, + }); + + adjustment.connect("value-changed", adj => { + setting.activate(GLib.Variant.new_int32(adj.value)); + }); + + return row; + } + + // Yeah... I'm not gonna implement a full introspector here. Just add whatever is required + // when needed. + throw new GObject.NotImplementedError(); + } +}; -- cgit v1.2.3