mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 15:19:09 +00:00
Refactor: Build Menu in UI file
This commit is contained in:
parent
e07411f9fd
commit
503fdcb90d
@ -16,9 +16,11 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child type="suffix">
|
<child type="suffix">
|
||||||
<object class="GtkMenuButton" id="menu-button">
|
<object class="GtkMenuButton">
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="icon-name">view-more-symbolic</property>
|
<property name="icon-name">view-more-symbolic</property>
|
||||||
|
<property name="tooltip-text">Options</property>
|
||||||
|
<property name="menu-model">optionsMenuModel</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="flat"/>
|
<class name="flat"/>
|
||||||
</style>
|
</style>
|
||||||
@ -40,4 +42,12 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</template>
|
</template>
|
||||||
|
<menu id="optionsMenuModel">
|
||||||
|
<section>
|
||||||
|
<item>
|
||||||
|
<attribute name="label">Forget</attribute>
|
||||||
|
<attribute name="action">options.forget</attribute>
|
||||||
|
</item>
|
||||||
|
</section>
|
||||||
|
</menu>
|
||||||
</interface>
|
</interface>
|
||||||
|
|||||||
@ -14,15 +14,14 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
GTypeName: "PrefsBoxOrderItemRow",
|
GTypeName: "PrefsBoxOrderItemRow",
|
||||||
Template: Me.dir.get_child("ui").get_child("prefs-box-order-item-row.ui").get_uri(),
|
Template: Me.dir.get_child("ui").get_child("prefs-box-order-item-row.ui").get_uri(),
|
||||||
InternalChildren: [
|
InternalChildren: [
|
||||||
"item-name-display-label",
|
"item-name-display-label"
|
||||||
"menu-button"
|
|
||||||
]
|
]
|
||||||
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
||||||
constructor(params = {}, item) {
|
constructor(params = {}, item) {
|
||||||
super(params);
|
super(params);
|
||||||
|
|
||||||
this.#associateItem(item);
|
this.#associateItem(item);
|
||||||
this.#configureMenu();
|
this.#setupActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,23 +39,22 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the menu.
|
* Setup actions.
|
||||||
*/
|
*/
|
||||||
#configureMenu() {
|
#setupActions() {
|
||||||
let menu = new Gio.Menu();
|
const actionGroup = new Gio.SimpleActionGroup();
|
||||||
menu.append("Forget", `prefsBoxOrderItemRow-${this.item}.forget`);
|
|
||||||
this._menu_button.set_menu_model(menu);
|
|
||||||
|
|
||||||
const forgetAction = new Gio.SimpleAction({ name: "forget" });
|
const forgetAction = new Gio.SimpleAction({
|
||||||
forgetAction.connect("activate", () => {
|
name: "forget"
|
||||||
|
});
|
||||||
|
forgetAction.connect("activate", (_action, _params) => {
|
||||||
const parentListBox = this.get_parent();
|
const parentListBox = this.get_parent();
|
||||||
parentListBox.remove(this);
|
parentListBox.remove(this);
|
||||||
parentListBox.saveBoxOrderToSettings();
|
parentListBox.saveBoxOrderToSettings();
|
||||||
});
|
})
|
||||||
|
|
||||||
const actionGroup = new Gio.SimpleActionGroup();
|
|
||||||
actionGroup.add_action(forgetAction);
|
actionGroup.add_action(forgetAction);
|
||||||
this.insert_action_group(`prefsBoxOrderItemRow-${this.item}`, actionGroup);
|
|
||||||
|
this.insert_action_group(`options`, actionGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDragPrepare(_source, x, y) {
|
onDragPrepare(_source, x, y) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user