Skip to content

Commit

Permalink
app/accellabel: use #private properties
Browse files Browse the repository at this point in the history
  • Loading branch information
amezin committed Feb 2, 2025
1 parent eeacc13 commit c1bdacb
Showing 1 changed file with 43 additions and 49 deletions.
92 changes: 43 additions & 49 deletions ddterm/app/accellabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,101 +14,95 @@ export const AccelLabel = GObject.registerClass({
},
},
class DDTermAccelLabel extends Gtk.Label {
_init(params) {
this._name = null;
this._target_value = null;
this._toplevel = null;
this._keys_handler = null;

super._init(params);

this.connect('destroy', () => {
if (this._keys_handler) {
this.get_toplevel().disconnect(this._keys_handler);
this._keys_handler = null;
}
});
#name = null;
#target_value = null;
#toplevel = null;
#keys_handler = null;

constructor(params) {
super(params);

this.on_hierarchy_changed();
this.connect('destroy', this.#disconnect.bind(this));
this.connect('hierarchy-changed', this.#update_hierarchy.bind(this));
this.#update_hierarchy();
}

#disconnect() {
if (this.#keys_handler) {
this.#toplevel.disconnect(this.#keys_handler);
this.#keys_handler = null;
this.#toplevel = null;
}
}

get action_name() {
return this._name;
return this.#name;
}

vfunc_get_action_name() {
return this._name;
return this.#name;
}

get action_target() {
return this._target_value;
return this.#target_value;
}

vfunc_get_action_target_value() {
return this._target_value;
return this.#target_value;
}

set action_name(value) {
this.set_action_name(value);
}

vfunc_set_action_name(value) {
if (this._name === value)
if (this.#name === value)
return;

this._name = value;
this.update_label();
this.#name = value;
this.#update_label();
}

set action_target(value) {
this.set_action_target_value(value);
}

vfunc_set_action_target_value(value) {
if (this._target_value === value)
if (this.#target_value === value)
return;

if (value && this._target_value && value.equal(this._target_value))
if (value && this.#target_value && value.equal(this.#target_value))
return;

this._target_value = value;
this.update_label();
this.#target_value = value;
this.#update_label();
}

on_hierarchy_changed() {
if (this._keys_handler) {
this._toplevel.disconnect(this._keys_handler);
this._keys_handler = null;
this._toplevel = null;
}

this._toplevel = this.get_toplevel();
#update_hierarchy() {
this.#disconnect();
this.#toplevel = this.get_toplevel();

if (this._toplevel instanceof Gtk.Window) {
this._keys_handler = this._toplevel.connect(
'keys-changed',
() => this.update_label()
);
if (this.#toplevel instanceof Gtk.Window) {
this.#keys_handler =
this.#toplevel.connect('keys-changed', this.#update_label.bind(this));
}

this.update_label();
this.#update_label();
}

_get_label() {
if (!this._name)
#get_label() {
if (!this.#name)
return '';

const action = Gio.Action.print_detailed_name(this._name, this._target_value);
const toplevel = this.get_toplevel();
const action = Gio.Action.print_detailed_name(this.#name, this.#target_value);
const toplevel = this.#toplevel;

if (!(toplevel instanceof Gtk.Window))
return '';

for (const shortcut of toplevel.application?.get_accels_for_action(action) || []) {
try {
return Gtk.accelerator_get_label(
...Gtk.accelerator_parse(shortcut)
);
return Gtk.accelerator_get_label(...Gtk.accelerator_parse(shortcut));
} catch (ex) {
logError(ex);
}
Expand All @@ -117,7 +111,7 @@ class DDTermAccelLabel extends Gtk.Label {
return '';
}

update_label() {
this.label = this._get_label();
#update_label() {
this.label = this.#get_label();
}
});

0 comments on commit c1bdacb

Please sign in to comment.