diff --git a/src/prefsModules/PrefsBoxOrderItemRow.js b/src/prefsModules/PrefsBoxOrderItemRow.js index 3ca63ae..0043841 100644 --- a/src/prefsModules/PrefsBoxOrderItemRow.js +++ b/src/prefsModules/PrefsBoxOrderItemRow.js @@ -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); } diff --git a/src/prefsModules/PrefsBoxOrderListBox.js b/src/prefsModules/PrefsBoxOrderListBox.js index 6e93561..3f6ed91 100644 --- a/src/prefsModules/PrefsBoxOrderListBox.js +++ b/src/prefsModules/PrefsBoxOrderListBox.js @@ -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); + } });