diff --git a/src/prefs.js b/src/prefs.js index 4740bde..baf1ab7 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -99,19 +99,7 @@ var PrefsWidget = GObject.registerClass({ // Add the items of the given configured box order as // GtkListBoxRows. for (const item of boxOrder) { - const listBoxRow = new PrefsBoxOrderItemRow.PrefsBoxOrderItemRow({}, this._scrollManager); - - listBoxRow.item = item; - if (item.startsWith("appindicator-kstatusnotifieritem-")) { - // Set `item_name_display_label` of the `listBoxRow` to - // something nicer, if the associated item is an - // AppIndicator/KStatusNotifierItem item. - listBoxRow.item_name_display_label.set_label(item.replace("appindicator-kstatusnotifieritem-", "")); - } else { - // Otherwise just set the `item_name_display_label` of the - // `listBoxRow` to `item`. - listBoxRow.item_name_display_label.set_label(item); - } + const listBoxRow = new PrefsBoxOrderItemRow.PrefsBoxOrderItemRow({}, this._scrollManager, item); gtkListBox.append(listBoxRow); } diff --git a/src/prefsModules/PrefsBoxOrderItemRow.js b/src/prefsModules/PrefsBoxOrderItemRow.js index 0043841..b3fda58 100644 --- a/src/prefsModules/PrefsBoxOrderItemRow.js +++ b/src/prefsModules/PrefsBoxOrderItemRow.js @@ -29,11 +29,13 @@ const Me = ExtensionUtils.getCurrentExtension(); var PrefsBoxOrderItemRow = GObject.registerClass({ GTypeName: "PrefsBoxOrderItemRow", Template: Me.dir.get_child("prefs-box-order-item-row.ui").get_uri(), - Children: ["item-name-display-label"] + InternalChildren: ["item-name-display-label"] }, class PrefsBoxOrderItemRow extends Gtk.ListBoxRow { - _init(params = {}, scrollManager) { + _init(params = {}, scrollManager, item) { super._init(params); + this._associateItem(item); + // Make `this` draggable by creating a drag source and adding it to // `this`. let dragSource = new Gtk.DragSource(); @@ -108,4 +110,18 @@ var PrefsBoxOrderItemRow = GObject.registerClass({ }); this.add_controller(dropTarget); } + + /** + * Associate `this` with an item. + * @param {String} item + */ + _associateItem(item) { + this.item = item; + + // Set `this._item_name_display_label` to something nicer, if the + // associated item is an AppIndicator/KStatusNotifierItem item. + if (item.startsWith("appindicator-kstatusnotifieritem-")) this._item_name_display_label.set_label(item.replace("appindicator-kstatusnotifieritem-", "")); + // Otherwise just set it to `item`. + else this._item_name_display_label.set_label(item); + } });