mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 07:09:07 +00: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
38
data/ui/prefs-box-order-item-options-dialog.ui
Normal file
38
data/ui/prefs-box-order-item-options-dialog.ui
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="PrefsBoxOrderItemOptionsDialog" parent="AdwDialog">
|
||||
<!-- Same as the default-width of AdwPreferencesWindow.-->
|
||||
<property name="content-width">640</property>
|
||||
<child>
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar"></object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="AdwPreferencesPage">
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<child>
|
||||
<object class="AdwComboRow" id="visibility-row">
|
||||
<property name="title">Visibility</property>
|
||||
<property name="subtitle">Forcefully hide or show an item or just don't affect its visibility. This option applies every time the top bar gets reordered, an items visiblity might be influenced by other factors and this option might not work for every item.</property>
|
||||
<property name="model">
|
||||
<object class="GtkStringList">
|
||||
<items>
|
||||
<item>Default</item>
|
||||
<item>Forcefully Hide</item>
|
||||
<item>Forcefully Show</item>
|
||||
</items>
|
||||
</object>
|
||||
</property>
|
||||
<signal name="notify::selected-item" handler="onVisibilityRowSelectionChanged"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
@ -46,6 +46,12 @@
|
||||
<attribute name="action">row.move-down</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label">Options</attribute>
|
||||
<attribute name="action">row.options</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label">Forget</attribute>
|
||||
|
||||
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…
x
Reference in New Issue
Block a user