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:
June 2021-07-05 07:58:01 +02:00
commit 309e2c07b9
No known key found for this signature in database
GPG key ID: 094C2AC34192FA11
2 changed files with 19 additions and 15 deletions

View file

@ -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);
}
});