Refactor: Install forget action using install_action as well

This commit is contained in:
Julian 2023-10-04 03:37:36 +02:00
parent 9b7ab0614c
commit a77c6d2f2b
Signed by: julian
GPG Key ID: 094C2AC34192FA11
2 changed files with 7 additions and 22 deletions

View File

@ -55,7 +55,7 @@
<section> <section>
<item> <item>
<attribute name="label">Forget</attribute> <attribute name="label">Forget</attribute>
<attribute name="action">options.forget</attribute> <attribute name="action">row.forget</attribute>
</item> </item>
</section> </section>
</menu> </menu>

View File

@ -21,6 +21,12 @@ export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
} }
} }
}, this); }, this);
this.install_action("row.forget", null, (self, _actionName, _param) => {
const parentListBox = self.get_parent();
parentListBox.removeRow(self);
parentListBox.saveBoxOrderToSettings();
parentListBox.determineRowMoveActionEnable();
});
this.install_action("row.move-up", null, (self, _actionName, _param) => self.emit("move", "up")); 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")); this.install_action("row.move-down", null, (self, _actionName, _param) => self.emit("move", "down"));
} }
@ -32,7 +38,6 @@ export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
super(params); super(params);
this.#associateItem(item); this.#associateItem(item);
this.#setupActions();
} }
/** /**
@ -52,26 +57,6 @@ export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
} }
} }
/**
* Setup actions.
*/
#setupActions() {
const actionGroup = new Gio.SimpleActionGroup();
const forgetAction = new Gio.SimpleAction({
name: "forget"
});
forgetAction.connect("activate", (_action, _params) => {
const parentListBox = this.get_parent();
parentListBox.removeRow(this);
parentListBox.saveBoxOrderToSettings();
parentListBox.determineRowMoveActionEnable();
});
actionGroup.add_action(forgetAction);
this.insert_action_group("options", actionGroup);
}
onDragPrepare(_source, x, y) { onDragPrepare(_source, x, y) {
const value = new GObject.Value(); const value = new GObject.Value();
value.init(PrefsBoxOrderItemRow); value.init(PrefsBoxOrderItemRow);