forked from corecoding/Vitals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuItem.js
77 lines (59 loc) · 1.79 KB
/
menuItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import St from 'gi://St'
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
export const MenuItem = GObject.registerClass({
Signals: {
'toggle': { param_types: [Clutter.Event.$gtype] },
},
}, class MenuItem extends PopupMenu.PopupBaseMenuItem {
_init(icon, key, label, value, checked) {
super._init({ reactive: true });
this._checked = checked;
this._updateOrnament();
this._key = key;
this._gIcon = icon;
// add icon
this.add_child(new St.Icon({ style_class: 'popup-menu-icon', gicon : this._gIcon }));
// add label
this._labelActor = new St.Label({ text: label });
this.add_child(this._labelActor);
// add value
this._valueLabel = new St.Label({ text: value });
this._valueLabel.set_x_align(Clutter.ActorAlign.END);
this._valueLabel.set_x_expand(true);
this._valueLabel.set_y_expand(true);
this.add_child(this._valueLabel);
this.actor._delegate = this;
}
get checked() {
return this._checked;
}
get key() {
return this._key;
}
get gicon() {
return this._gIcon;
}
set value(value) {
this._valueLabel.text = value;
}
get value() {
return this._valueLabel.text;
}
// prevents menu from being closed
activate(event) {
this._checked = !this._checked;
this._updateOrnament();
this.emit('toggle', event);
}
_updateOrnament() {
if (this._checked)
this.setOrnament(PopupMenu.Ornament.CHECK);
else
this.setOrnament(PopupMenu.Ornament.NONE);
}
get label() {
return this._labelActor.text;
}
});