mirror of
https://gitlab.gnome.org/june/top-bar-organizer.git
synced 2026-11-10 12:00:51 +01:00
feature: add settings UI for control. how to affect an items visibility
Add settings UI for controlling how the extension should affect a top bar items visibility (whether to try to forcefully hide or show an item or not affect its visibility at all).
This commit is contained in:
parent
0d51b81041
commit
fdbacdd683
2 changed files with 112 additions and 0 deletions
58
src/prefsModules/PrefsBoxOrderItemOptionsDialog.ts
Normal file
58
src/prefsModules/PrefsBoxOrderItemOptionsDialog.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
"use strict";
|
||||
|
||||
import GObject from "gi://GObject";
|
||||
import Adw from "gi://Adw";
|
||||
import GLib from "gi://GLib";
|
||||
import type Gio from "gi://Gio";
|
||||
import type Gtk from "gi://Gtk";
|
||||
|
||||
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
|
||||
|
||||
export default class PrefsBoxOrderItemOptionsDialog extends Adw.Dialog {
|
||||
static {
|
||||
GObject.registerClass({
|
||||
GTypeName: "PrefsBoxOrderItemOptionsDialog",
|
||||
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-item-options-dialog.ui", GLib.UriFlags.NONE),
|
||||
InternalChildren: [
|
||||
"visibility-row",
|
||||
],
|
||||
}, this);
|
||||
}
|
||||
|
||||
declare _visibility_row: Adw.ComboRow;
|
||||
#settings: Gio.Settings;
|
||||
item: string;
|
||||
|
||||
constructor(params = {}, item: string) {
|
||||
super(params);
|
||||
|
||||
// Associate `this` with an item.
|
||||
this.item = item;
|
||||
// Load the settings.
|
||||
this.#settings = ExtensionPreferences.lookupByURL(import.meta.url)!.getSettings();
|
||||
}
|
||||
|
||||
onVisibilityRowSelectionChanged(): void {
|
||||
const visibility = (this._visibility_row.get_selected_item() as Gtk.StringObject).get_string();
|
||||
const itemsToHide = new Set(this.#settings.get_strv("hide"));
|
||||
const itemsToShow = new Set(this.#settings.get_strv("show"));
|
||||
|
||||
switch (visibility) {
|
||||
case "Forcefully Hide":
|
||||
itemsToHide.add(this.item)
|
||||
itemsToShow.delete(this.item);
|
||||
break;
|
||||
case "Forcefully Show":
|
||||
itemsToHide.delete(this.item)
|
||||
itemsToShow.add(this.item);
|
||||
break;
|
||||
case "Default":
|
||||
itemsToHide.delete(this.item)
|
||||
itemsToShow.delete(this.item);
|
||||
break;
|
||||
}
|
||||
|
||||
this.#settings.set_strv("hide", Array.from(itemsToHide));
|
||||
this.#settings.set_strv("show", Array.from(itemsToShow));
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import GObject from "gi://GObject";
|
|||
import Adw from "gi://Adw";
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
import PrefsBoxOrderItemOptionsDialog from "./PrefsBoxOrderItemOptionsDialog.js";
|
||||
import type PrefsBoxOrderListBox from "./PrefsBoxOrderListBox.js";
|
||||
|
||||
export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
||||
|
|
@ -25,6 +26,15 @@ export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
|||
parentListBox.saveBoxOrderToSettings();
|
||||
parentListBox.determineRowMoveActionEnable();
|
||||
});
|
||||
this.install_action("row.options", null, (self, _actionName, _param) => {
|
||||
const itemOptionsDialog = new PrefsBoxOrderItemOptionsDialog({
|
||||
// Get the title from self as the constructor of
|
||||
// PrefsBoxOrderItemRow already processes the item name into a
|
||||
// nice title.
|
||||
title: (self as PrefsBoxOrderItemRow).get_title()
|
||||
}, (self as PrefsBoxOrderItemRow).item);
|
||||
itemOptionsDialog.present(self);
|
||||
});
|
||||
this.install_action("row.move-up", null, (self, _actionName, _param) => self.emit("move", "up"));
|
||||
this.install_action("row.move-down", null, (self, _actionName, _param) => self.emit("move", "down"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue