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:
Julian 2021-07-05 08:41:08 +02:00
parent 309e2c07b9
commit e76b24e813
Signed by: julian
GPG Key ID: 094C2AC34192FA11
2 changed files with 35 additions and 2 deletions

View File

@ -32,7 +32,15 @@
</object> </object>
</child> </child>
<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> </child>
</object> </object>
</child> </child>

View File

@ -21,6 +21,7 @@
const Gtk = imports.gi.Gtk; const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk; const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject; const GObject = imports.gi.GObject;
const ExtensionUtils = imports.misc.extensionUtils; const ExtensionUtils = imports.misc.extensionUtils;
@ -29,12 +30,16 @@ const Me = ExtensionUtils.getCurrentExtension();
var PrefsBoxOrderItemRow = GObject.registerClass({ var PrefsBoxOrderItemRow = GObject.registerClass({
GTypeName: "PrefsBoxOrderItemRow", GTypeName: "PrefsBoxOrderItemRow",
Template: Me.dir.get_child("prefs-box-order-item-row.ui").get_uri(), 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 { }, class PrefsBoxOrderItemRow extends Gtk.ListBoxRow {
_init(params = {}, scrollManager, item) { _init(params = {}, scrollManager, item) {
super._init(params); super._init(params);
this._associateItem(item); this._associateItem(item);
this._configureMenu();
// Make `this` draggable by creating a drag source and adding it to // Make `this` draggable by creating a drag source and adding it to
// `this`. // `this`.
@ -124,4 +129,24 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
// Otherwise just set it to `item`. // Otherwise just set it to `item`.
else this._item_name_display_label.set_label(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);
}
}); });