From e76b24e813b4c53b479adcb8d610637bf1e852a0 Mon Sep 17 00:00:00 2001 From: Julian Schacher Date: Mon, 5 Jul 2021 08:41:08 +0200 Subject: [PATCH] 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). --- src/prefs-box-order-item-row.ui | 10 ++++++++- src/prefsModules/PrefsBoxOrderItemRow.js | 27 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/prefs-box-order-item-row.ui b/src/prefs-box-order-item-row.ui index a82e225..2c8e424 100644 --- a/src/prefs-box-order-item-row.ui +++ b/src/prefs-box-order-item-row.ui @@ -32,7 +32,15 @@ - + + start + True + + + + + view-more-symbolic + diff --git a/src/prefsModules/PrefsBoxOrderItemRow.js b/src/prefsModules/PrefsBoxOrderItemRow.js index b3fda58..b62ab5c 100644 --- a/src/prefsModules/PrefsBoxOrderItemRow.js +++ b/src/prefsModules/PrefsBoxOrderItemRow.js @@ -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); + } });