diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 16:02:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-08 16:02:53 +0000 |
commit | 4d8b071804d73b7a733f2b7696fde40caf8800bb (patch) | |
tree | 86aefc1c0ea9c596bab0ecbc0c054a2378d6cd13 /extensions/44/vertical-workspaces/lib/optionsFactory.js | |
parent | Updating 44/no-overview to version 44 [68db01d]. (diff) | |
download | gnome-shell-extensions-extra-4d8b071804d73b7a733f2b7696fde40caf8800bb.tar.xz gnome-shell-extensions-extra-4d8b071804d73b7a733f2b7696fde40caf8800bb.zip |
Updating 44/vertical-workspaces to version 37+20231208 [0d82192].
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/44/vertical-workspaces/lib/optionsFactory.js')
-rw-r--r-- | extensions/44/vertical-workspaces/lib/optionsFactory.js | 251 |
1 files changed, 55 insertions, 196 deletions
diff --git a/extensions/44/vertical-workspaces/lib/optionsFactory.js b/extensions/44/vertical-workspaces/lib/optionsFactory.js index da62dd1..df6c970 100644 --- a/extensions/44/vertical-workspaces/lib/optionsFactory.js +++ b/extensions/44/vertical-workspaces/lib/optionsFactory.js @@ -9,41 +9,35 @@ 'use strict'; -const { Gtk, Gio, GObject } = imports.gi; +const Adw = imports.gi.Adw; +const Gtk = imports.gi.Gtk; +const Gio = imports.gi.Gio; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); -const Settings = Me.imports.lib.settings; - -const shellVersion = Settings.shellVersion; +let Me; // gettext -const _ = Settings._; +let _; // = Settings._; -const ProfileNames = [ - _('GNOME 3'), - _('GNOME 40+ - Bottom Hot Edge'), - _('Hot Corner Centric - Top Left Hot Corner'), - _('Dock Overview - Bottom Hot Edge'), -]; +function init(me) { + Me = me; + _ = Me.gettext; +} -// libadwaita is available starting with GNOME Shell 42. -let Adw = null; -try { - Adw = imports.gi.Adw; -} catch (e) {} +function cleanGlobals() { + Me = null; + _ = null; +} function _newImageFromIconName(name) { return Gtk.Image.new_from_icon_name(name); } var ItemFactory = class ItemFactory { - constructor(gOptions) { - this._gOptions = gOptions; - this._settings = this._gOptions._gsettings; + constructor() { + this._settings = Me.Opt._gsettings; } - getRowWidget(text, caption, widget, variable, options = []) { + getRowWidget(text, caption, widget, variable, options = [], dependsOn) { let item = []; let label; if (widget) { @@ -81,8 +75,8 @@ var ItemFactory = class ItemFactory { let key; - if (variable && this._gOptions.options[variable]) { - const opt = this._gOptions.options[variable]; + if (variable && Me.Opt.options[variable]) { + const opt = Me.Opt.options[variable]; key = opt[1]; } @@ -95,6 +89,11 @@ var ItemFactory = class ItemFactory { this._connectComboBox(widget, key, variable, options); else if (widget._isDropDown) this._connectDropDown(widget, key, variable, options); + + if (dependsOn) { + const dKey = Me.Opt.options[dependsOn][1]; + this._settings.bind(dKey, widget, 'sensitive', Gio.SettingsBindFlags.GET); + } } return item; @@ -111,7 +110,7 @@ var ItemFactory = class ItemFactory { _connectComboBox(widget, key, variable, options) { let model = widget.get_model(); widget._comboMap = {}; - const currentValue = this._gOptions.get(variable); + const currentValue = Me.Opt.get(variable); for (const [label, value] of options) { let iter; model.set(iter = model.append(), [0, 1], [label, value]); @@ -120,8 +119,8 @@ var ItemFactory = class ItemFactory { widget._comboMap[value] = iter; } - this._gOptions.connect(`changed::${key}`, () => { - widget.set_active_iter(widget._comboMap[this._gOptions.get(variable, true)]); + Me.Opt.connect(`changed::${key}`, () => { + widget.set_active_iter(widget._comboMap[Me.Opt.get(variable, true)]); }); widget.connect('changed', () => { const [success, iter] = widget.get_active_iter(); @@ -129,17 +128,17 @@ var ItemFactory = class ItemFactory { if (!success) return; - this._gOptions.set(variable, model.get_value(iter, 1)); + Me.Opt.set(variable, model.get_value(iter, 1)); }); } _connectDropDown(widget, key, variable, options) { const model = widget.get_model(); - const currentValue = this._gOptions.get(variable); + const currentValue = Me.Opt.get(variable); for (let i = 0; i < options.length; i++) { const text = options[i][0]; const id = options[i][1]; - model.append(new DropDownItem({ text, id })); + model.append(new DropDownItemVW({ text, id })); if (id === currentValue) widget.set_selected(i); } @@ -157,11 +156,11 @@ var ItemFactory = class ItemFactory { widget.connect('notify::selected-item', dropDown => { const item = dropDown.get_selected_item(); - this._gOptions.set(variable, item.id); + Me.Opt.set(variable, item.id); }); - this._gOptions.connect(`changed::${key}`, () => { - const newId = this._gOptions.get(variable, true); + Me.Opt.connect(`changed::${key}`, () => { + const newId = Me.Opt.get(variable, true); for (let i = 0; i < options.length; i++) { const id = options[i][1]; if (id === newId) @@ -214,7 +213,7 @@ var ItemFactory = class ItemFactory { newDropDown() { const dropDown = new Gtk.DropDown({ model: new Gio.ListStore({ - item_type: DropDownItem, + item_type: DropDownItemVW, }), halign: Gtk.Align.END, valign: Gtk.Align.CENTER, @@ -255,11 +254,11 @@ var ItemFactory = class ItemFactory { newLinkButton(uri) { const linkBtn = new Gtk.LinkButton({ - label: shellVersion < 42 ? 'Click Me!' : '', uri, halign: Gtk.Align.END, valign: Gtk.Align.CENTER, hexpand: true, + icon_name: 'emblem-symbolic-link', }); return linkBtn; } @@ -298,18 +297,23 @@ var ItemFactory = class ItemFactory { entry.set_text(opt.get(`profileName${profileIndex}`)); entry.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, 'edit-clear-symbolic'); entry.set_icon_activatable(Gtk.EntryIconPosition.SECONDARY, true); - entry.connect('icon-press', e => e.set_text('')); - entry.connect('changed', e => opt.set(`profileName${profileIndex}`, e.get_text())); const resetProfile = this.newButton(); resetProfile.set({ tooltip_text: _('Reset profile to defaults'), - icon_name: 'edit-delete-symbolic', + icon_name: 'document-revert-symbolic', hexpand: false, css_classes: ['destructive-action'], }); function setName() { + const ProfileNames = [ + _('GNOME 3'), + _('GNOME 40+ - Bottom Hot Edge'), + _('Hot Corner Centric - Top Left Hot Corner'), + _('Dock Overview - Bottom Hot Edge'), + ]; + let name = opt.get(`profileName${profileIndex}`, true); if (!name) name = ProfileNames[profileIndex - 1]; @@ -317,6 +321,10 @@ var ItemFactory = class ItemFactory { } setName(); + + entry.connect('icon-press', e => e.set_text('')); + entry.connect('changed', e => opt.set(`profileName${profileIndex}`, e.get_text())); + resetProfile.connect('clicked', () => { reset(profileIndex); setName(); @@ -366,7 +374,7 @@ var ItemFactory = class ItemFactory { valign: Gtk.Align.CENTER, hexpand: true, css_classes: ['destructive-action'], - icon_name: 'edit-delete-symbolic', + icon_name: 'document-revert-symbolic', }); btn.connect('clicked', () => { @@ -382,7 +390,7 @@ var ItemFactory = class ItemFactory { var AdwPrefs = class { constructor(gOptions) { - this._gOptions = gOptions; + Me.Opt = gOptions; } getFilledWindow(window, pages) { @@ -457,158 +465,9 @@ var AdwPrefs = class { } }; -var LegacyPrefs = class { - constructor(gOptions) { - this._gOptions = gOptions; - } - - getPrefsWidget(pages) { - const prefsWidget = new Gtk.Box({ - orientation: Gtk.Orientation.VERTICAL, - }); - const stack = new Gtk.Stack({ - hexpand: true, - }); - const stackSwitcher = new Gtk.StackSwitcher({ - halign: Gtk.Align.CENTER, - hexpand: true, - }); - - const context = stackSwitcher.get_style_context(); - context.add_class('caption'); - - stackSwitcher.set_stack(stack); - stack.set_transition_duration(300); - stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT); - - const pageProperties = { - hscrollbar_policy: Gtk.PolicyType.NEVER, - vscrollbar_policy: Gtk.PolicyType.AUTOMATIC, - vexpand: true, - hexpand: true, - visible: true, - }; - - const pagesBtns = []; - - for (let page of pages) { - const name = page.name; - const title = page.title; - const iconName = page.iconName; - const optionList = page.optionList; - - stack.add_named(this._getLegacyPage(optionList, pageProperties), name); - pagesBtns.push( - [new Gtk.Label({ label: title }), _newImageFromIconName(iconName, Gtk.IconSize.BUTTON)] - ); - } - - let stBtn = stackSwitcher.get_first_child ? stackSwitcher.get_first_child() : null; - for (let i = 0; i < pagesBtns.length; i++) { - const box = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, spacing: 6, visible: true }); - const icon = pagesBtns[i][1]; - icon.margin_start = 30; - icon.margin_end = 30; - box.append(icon); - box.append(pagesBtns[i][0]); - if (stackSwitcher.get_children) { - stBtn = stackSwitcher.get_children()[i]; - stBtn.add(box); - } else { - stBtn.set_child(box); - stBtn.visible = true; - stBtn = stBtn.get_next_sibling(); - } - } - - if (stack.show_all) - stack.show_all(); - if (stackSwitcher.show_all) - stackSwitcher.show_all(); - - prefsWidget.append(stack); - - if (prefsWidget.show_all) - prefsWidget.show_all(); - - prefsWidget._stackSwitcher = stackSwitcher; - - return prefsWidget; - } - - _getLegacyPage(optionList, pageProperties) { - const page = new Gtk.ScrolledWindow(pageProperties); - const mainBox = new Gtk.Box({ - orientation: Gtk.Orientation.VERTICAL, - spacing: 5, - homogeneous: false, - margin_start: 30, - margin_end: 30, - margin_top: 12, - margin_bottom: 12, - }); - - let context = page.get_style_context(); - context.add_class('background'); - - let frame; - let frameBox; - for (let item of optionList) { - // label can be plain text for Section Title - // or GtkBox for Option - const option = item[0]; - const widget = item[1]; - - if (!widget) { - const lbl = new Gtk.Label({ - label: option, - xalign: 0, - margin_bottom: 4, - }); - - context = lbl.get_style_context(); - context.add_class('heading'); - - mainBox.append(lbl); - - frame = new Gtk.Frame({ - margin_bottom: 16, - }); - - frameBox = new Gtk.ListBox({ - selection_mode: null, - }); - - mainBox.append(frame); - frame.set_child(frameBox); - continue; - } - - const grid = new Gtk.Grid({ - column_homogeneous: false, - column_spacing: 20, - margin_start: 8, - margin_end: 8, - margin_top: 8, - margin_bottom: 8, - hexpand: true, - }); - - grid.attach(option, 0, 0, 5, 1); - - if (widget) - grid.attach(widget, 5, 0, 2, 1); - - frameBox.append(grid); - } - page.set_child(mainBox); - - return page; - } -}; - -const DropDownItem = GObject.registerClass({ - GTypeName: 'DropdownItem', +const { GObject } = imports.gi; +const DropDownItemVW = GObject.registerClass({ + GTypeName: 'DropDownItemVW', Properties: { 'text': GObject.ParamSpec.string( 'text', @@ -622,10 +481,11 @@ const DropDownItem = GObject.registerClass({ 'Id', 'Item id stored in settings', GObject.ParamFlags.READWRITE, - 0, 100, 0 + // min, max, default + -2147483648, 2147483647, 0 ), }, -}, class DropDownItem extends GObject.Object { +}, class DropDownItemVW extends GObject.Object { get text() { return this._text; } @@ -641,5 +501,4 @@ const DropDownItem = GObject.registerClass({ set id(id) { this._id = id; } -} -); +}); |