Refactor: Move individual top bar box ordering into own method

Move the individual top bar box ordering into own method, so that this
method can be used elsewhere in the future to easily order a single box.
This commit is contained in:
Julian 2021-05-16 20:17:17 +02:00
parent 2f0ecddfc8
commit fd21ecb189
Signed by: julian
GPG Key ID: 094C2AC34192FA11

View File

@ -12,7 +12,7 @@ class Extension {
enable() { enable() {
this._addNewItemsToBoxOrders(); this._addNewItemsToBoxOrders();
this._orderTopBarItems(); this._orderTopBarItemsOfAllBoxes();
this._overwritePanelAddToPanelBox(); this._overwritePanelAddToPanelBox();
} }
@ -81,31 +81,47 @@ class Extension {
} }
/** /**
* This method orders the top bar items according to the configured box * This methods orders the top bar items of all boxes according to the
* orders. * configured box orders using `this._orderTopBarItems`.
*/ */
_orderTopBarItems() { _orderTopBarItemsOfAllBoxes() {
// Get valid box orders. this._orderTopBarItems("left");
const validLeftBoxOrder = this._createValidBoxOrder("left"); this._orderTopBarItems("center");
const validCenterBoxOrder = this._createValidBoxOrder("center"); this._orderTopBarItems("right");
const validRightBoxOrder = this._createValidBoxOrder("right"); }
// Go through the items (or rather their roles) of a box and order the /**
// box accordingly. * This method orders the top bar items of the specified box according to
const orderBox = (boxOrder, box) => { * the configured box orders.
for (let i = 0; i < boxOrder.length; i++) { * @param {string} box - The box to order.
const role = boxOrder[i]; */
// Get the indicator container associated with the current role. _orderTopBarItems(box) {
const associatedIndicatorContainer = Main.panel.statusArea[role].container; // Get the valid box order.
const validBoxOrder = this._createValidBoxOrder(box);
box.set_child_at_index(associatedIndicatorContainer, i); // Get the relevant box of `Main.panel`.
} let panelBox;
switch (box) {
case "left":
panelBox = Main.panel._leftBox;
break;
case "center":
panelBox = Main.panel._centerBox;
break;
case "right":
panelBox = Main.panel._rightBox;
break;
} }
// Order the top bar items. // Go through the items (or rather their roles) of the validBoxOrder and
orderBox(validLeftBoxOrder, Main.panel._leftBox); // order the panelBox accordingly.
orderBox(validCenterBoxOrder, Main.panel._centerBox); for (let i = 0; i < validBoxOrder.length; i++) {
orderBox(validRightBoxOrder, Main.panel._rightBox); const role = validBoxOrder[i];
// Get the indicator container associated with the current role.
const associatedIndicatorContainer = Main.panel.statusArea[role].container;
panelBox.set_child_at_index(associatedIndicatorContainer, i);
}
} }
/** /**