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:
June 2021-07-05 07:46:08 +02:00
commit bd69f816eb
No known key found for this signature in database
GPG key ID: 094C2AC34192FA11
2 changed files with 21 additions and 28 deletions

View file

@ -99,37 +99,12 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
}
}
/// Finally save the box orders to settings.
const settings = ExtensionUtils.getSettings();
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);
/// Finally save the box order(/s) to settings.
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.
if (ownListBox !== valueListBox) {
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);
}
if (ownListBox !== valueListBox) valueListBox.saveBoxOrderToSettings();
});
this.add_controller(dropTarget);
}