mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 07:09:07 +00:00
Feature: Add forget action for top bar items
This forget action removes the top bar item from the top bar order representation, which is present in the settings, and then saves the top bar order. This action is intended for forgetting top bar items, which aren't present in the top bar anymore, so that the user can clean up their settings. So if an item isn't in the top bar at the time of action activation, activating the action removes it from the saved top bar order. If an item is in the top bar at the time of action activation, the item position just gets lost (since it gets automatically re-added to the top bar order).
This commit is contained in:
parent
309e2c07b9
commit
e76b24e813
@ -32,7 +32,15 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="item-name-display-label"/>
|
||||
<object class="GtkLabel" id="item-name-display-label">
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="menu-button">
|
||||
<property name="icon-name">view-more-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
|
||||
const Gtk = imports.gi.Gtk;
|
||||
const Gdk = imports.gi.Gdk;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GObject = imports.gi.GObject;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
@ -29,12 +30,16 @@ const Me = ExtensionUtils.getCurrentExtension();
|
||||
var PrefsBoxOrderItemRow = GObject.registerClass({
|
||||
GTypeName: "PrefsBoxOrderItemRow",
|
||||
Template: Me.dir.get_child("prefs-box-order-item-row.ui").get_uri(),
|
||||
InternalChildren: ["item-name-display-label"]
|
||||
InternalChildren: [
|
||||
"item-name-display-label",
|
||||
"menu-button"
|
||||
]
|
||||
}, class PrefsBoxOrderItemRow extends Gtk.ListBoxRow {
|
||||
_init(params = {}, scrollManager, item) {
|
||||
super._init(params);
|
||||
|
||||
this._associateItem(item);
|
||||
this._configureMenu();
|
||||
|
||||
// Make `this` draggable by creating a drag source and adding it to
|
||||
// `this`.
|
||||
@ -124,4 +129,24 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
||||
// Otherwise just set it to `item`.
|
||||
else this._item_name_display_label.set_label(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the menu.
|
||||
*/
|
||||
_configureMenu() {
|
||||
let menu = new Gio.Menu();
|
||||
menu.append("Forget", `prefsBoxOrderItemRow-${this.item}.forget`);
|
||||
this._menu_button.set_menu_model(menu);
|
||||
|
||||
const forgetAction = new Gio.SimpleAction({ name: "forget" });
|
||||
forgetAction.connect("activate", () => {
|
||||
const parentListBox = this.get_parent();
|
||||
parentListBox.remove(this);
|
||||
parentListBox.saveBoxOrderToSettings();
|
||||
});
|
||||
|
||||
const actionGroup = new Gio.SimpleActionGroup();
|
||||
actionGroup.add_action(forgetAction);
|
||||
this.insert_action_group(`prefsBoxOrderItemRow-${this.item}`, actionGroup);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user