mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 15:19:09 +00:00
Refactor: Move logic for saving box order to PrefsBoxOrderListBox
Move the logic for saving the box order represented by a `PrefsBoxOrderListBox` (and its `PrefsBoxOrderItemRows`) to the `PrefsBoxOrderListBox` class. This makes the code cleaner and allows for easy reuse of the logic in the future.
This commit is contained in:
parent
28fb67ad4d
commit
bd69f816eb
@ -99,37 +99,12 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finally save the box orders to settings.
|
/// Finally save the box order(/s) to settings.
|
||||||
const settings = ExtensionUtils.getSettings();
|
ownListBox.saveBoxOrderToSettings();
|
||||||
|
|
||||||
let updatedBoxOrder = [ ];
|
|
||||||
for (let potentialListBoxRow of ownListBox) {
|
|
||||||
// Only process PrefsBoxOrderItemRows.
|
|
||||||
if (potentialListBoxRow.constructor.$gtype.name !== "PrefsBoxOrderItemRow") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = potentialListBoxRow.item;
|
|
||||||
updatedBoxOrder.push(item);
|
|
||||||
}
|
|
||||||
settings.set_strv(ownListBox.boxOrder, updatedBoxOrder);
|
|
||||||
|
|
||||||
// If the list boxes of `this` and the drop value were different,
|
// 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
|
// save an updated box order for the list were the drop value was in
|
||||||
// as well.
|
// as well.
|
||||||
if (ownListBox !== valueListBox) {
|
if (ownListBox !== valueListBox) valueListBox.saveBoxOrderToSettings();
|
||||||
let updatedBoxOrder = [ ];
|
|
||||||
for (let potentialListBoxRow of valueListBox) {
|
|
||||||
// Only process PrefsBoxOrderItemRows.
|
|
||||||
if (potentialListBoxRow.constructor.$gtype.name !== "PrefsBoxOrderItemRow") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = potentialListBoxRow.item;
|
|
||||||
updatedBoxOrder.push(item);
|
|
||||||
}
|
|
||||||
settings.set_strv(valueListBox.boxOrder, updatedBoxOrder);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.add_controller(dropTarget);
|
this.add_controller(dropTarget);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,6 +37,24 @@ var PrefsBoxOrderListBox = GObject.registerClass({
|
|||||||
_init(params = {}, boxOrder) {
|
_init(params = {}, boxOrder) {
|
||||||
super._init(params);
|
super._init(params);
|
||||||
|
|
||||||
|
this._settings = ExtensionUtils.getSettings();
|
||||||
|
|
||||||
this.boxOrder = boxOrder;
|
this.boxOrder = boxOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the box order represented by `this` (and its
|
||||||
|
* `PrefsBoxOrderItemRows`) to settings.
|
||||||
|
*/
|
||||||
|
saveBoxOrderToSettings() {
|
||||||
|
let currentBoxOrder = [ ];
|
||||||
|
for (let potentialPrefsBoxOrderItemRow of this) {
|
||||||
|
// Only process PrefsBoxOrderItemRows.
|
||||||
|
if (potentialPrefsBoxOrderItemRow.constructor.$gtype.name !== "PrefsBoxOrderItemRow") continue;
|
||||||
|
|
||||||
|
const item = potentialPrefsBoxOrderItemRow.item;
|
||||||
|
currentBoxOrder.push(item);
|
||||||
|
}
|
||||||
|
this._settings.set_strv(this.boxOrder, currentBoxOrder);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user