mirror of
https://gitlab.gnome.org/julianschacher/top-bar-organizer.git
synced 2025-10-27 15:19:09 +00:00
Refactor: Let PrefsBoxOrderItemRow handle item association
Let `PrefsBoxOrderItemRow` handle the association of itself with an item itself. Doing so makes the code cleaner, since the association isn't done externally anymore.
This commit is contained in:
parent
bd69f816eb
commit
309e2c07b9
14
src/prefs.js
14
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user