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

@ -37,6 +37,24 @@ var PrefsBoxOrderListBox = GObject.registerClass({
_init(params = {}, boxOrder) {
super._init(params);
this._settings = ExtensionUtils.getSettings();
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);
}
});