mirror of
https://gitlab.gnome.org/june/top-bar-organizer.git
synced 2026-01-11 16:53:51 +01:00
Feature: Add move up and down buttons to make the prefs keyboard access.
Don't use CONSTRUCT_ONLY anymore to be able to use private properties (or any properties at all it seems).
This commit is contained in:
parent
a1188d5684
commit
9b7ab0614c
6 changed files with 219 additions and 34 deletions
|
|
@ -7,13 +7,24 @@ import GObject from "gi://GObject";
|
|||
import Adw from "gi://Adw";
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
const PrefsBoxOrderItemRow = GObject.registerClass({
|
||||
GTypeName: "PrefsBoxOrderItemRow",
|
||||
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-item-row.ui", GLib.UriFlags.NONE),
|
||||
InternalChildren: [
|
||||
"item-name-display-label"
|
||||
]
|
||||
}, class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
||||
export default class PrefsBoxOrderItemRow extends Adw.ActionRow {
|
||||
static {
|
||||
GObject.registerClass({
|
||||
GTypeName: "PrefsBoxOrderItemRow",
|
||||
Template: GLib.uri_resolve_relative(import.meta.url, "../ui/prefs-box-order-item-row.ui", GLib.UriFlags.NONE),
|
||||
InternalChildren: [
|
||||
"item-name-display-label"
|
||||
],
|
||||
Signals: {
|
||||
"move": {
|
||||
param_types: [GObject.TYPE_STRING]
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
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"));
|
||||
}
|
||||
|
||||
#drag_starting_point_x;
|
||||
#drag_starting_point_y;
|
||||
|
||||
|
|
@ -52,8 +63,9 @@ const PrefsBoxOrderItemRow = GObject.registerClass({
|
|||
});
|
||||
forgetAction.connect("activate", (_action, _params) => {
|
||||
const parentListBox = this.get_parent();
|
||||
parentListBox.remove(this);
|
||||
parentListBox.removeRow(this);
|
||||
parentListBox.saveBoxOrderToSettings();
|
||||
parentListBox.determineRowMoveActionEnable();
|
||||
});
|
||||
actionGroup.add_action(forgetAction);
|
||||
|
||||
|
|
@ -101,7 +113,7 @@ const PrefsBoxOrderItemRow = GObject.registerClass({
|
|||
const valuePosition = value.get_index();
|
||||
|
||||
// Remove the drop value from its list box.
|
||||
valueListBox.remove(value);
|
||||
valueListBox.removeRow(value);
|
||||
|
||||
// Since an element got potentially removed from the list of `this`,
|
||||
// get the position of `this` again.
|
||||
|
|
@ -115,31 +127,31 @@ const PrefsBoxOrderItemRow = GObject.registerClass({
|
|||
|| (ownListBox.boxOrder === "center-box-order" && valueListBox.boxOrder === "left-box-order")) {
|
||||
// If the list box of the drop value comes before the list
|
||||
// box of `this`, add the drop value after `this`.
|
||||
ownListBox.insert(value, updatedOwnPosition + 1);
|
||||
ownListBox.insertRow(value, updatedOwnPosition + 1);
|
||||
} else {
|
||||
// Otherwise, add the drop value where `this` currently is.
|
||||
ownListBox.insert(value, updatedOwnPosition);
|
||||
ownListBox.insertRow(value, updatedOwnPosition);
|
||||
}
|
||||
} else {
|
||||
if (valuePosition < ownPosition) {
|
||||
// If the drop value was before `this`, add the drop value
|
||||
// after `this`.
|
||||
ownListBox.insert(value, updatedOwnPosition + 1);
|
||||
ownListBox.insertRow(value, updatedOwnPosition + 1);
|
||||
} else {
|
||||
// Otherwise, add the drop value where `this` currently is.
|
||||
ownListBox.insert(value, updatedOwnPosition);
|
||||
ownListBox.insertRow(value, updatedOwnPosition);
|
||||
}
|
||||
}
|
||||
|
||||
/// Finally save the box order(/s) to settings.
|
||||
/// Finally save the box order(/s) to settings and make sure move
|
||||
/// actions are correctly enabled/disabled.
|
||||
ownListBox.saveBoxOrderToSettings();
|
||||
// If the list boxes of `this` and the drop value were different,
|
||||
// save an updated box order for the list were the drop value was in
|
||||
// as well.
|
||||
ownListBox.determineRowMoveActionEnable();
|
||||
// If the list boxes of `this` and the drop value were different, handle
|
||||
// the former list box of the drop value as well.
|
||||
if (ownListBox !== valueListBox) {
|
||||
valueListBox.saveBoxOrderToSettings();
|
||||
valueListBox.determineRowMoveActionEnable();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default PrefsBoxOrderItemRow;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue