popupMenu: Implement Switch as actor
Switch is used only by menu items, and implement it extending St.Bin https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/499
This commit is contained in:
parent
30861d4800
commit
6ecb0a4546
@ -291,26 +291,27 @@ class PopupSeparatorMenuItem extends PopupBaseMenuItem {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var Switch = class {
|
var Switch = GObject.registerClass(
|
||||||
constructor(state) {
|
class Switch extends St.Bin {
|
||||||
this.actor = new St.Bin({ style_class: 'toggle-switch',
|
_init(state) {
|
||||||
accessible_role: Atk.Role.CHECK_BOX,
|
super._init({ style_class: 'toggle-switch',
|
||||||
can_focus: true });
|
accessible_role: Atk.Role.CHECK_BOX,
|
||||||
|
can_focus: true });
|
||||||
this.setToggleState(state);
|
this.setToggleState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
setToggleState(state) {
|
setToggleState(state) {
|
||||||
if (state)
|
if (state)
|
||||||
this.actor.add_style_pseudo_class('checked');
|
this.add_style_pseudo_class('checked');
|
||||||
else
|
else
|
||||||
this.actor.remove_style_pseudo_class('checked');
|
this.remove_style_pseudo_class('checked');
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.setToggleState(!this.state);
|
this.setToggleState(!this.state);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
var PopupSwitchMenuItem = GObject.registerClass({
|
var PopupSwitchMenuItem = GObject.registerClass({
|
||||||
Signals: { 'toggled': { param_types: [GObject.TYPE_BOOLEAN] }, },
|
Signals: { 'toggled': { param_types: [GObject.TYPE_BOOLEAN] }, },
|
||||||
@ -334,7 +335,7 @@ class PopupSwitchMenuItem extends PopupBaseMenuItem {
|
|||||||
this._statusLabel = new St.Label({ text: '',
|
this._statusLabel = new St.Label({ text: '',
|
||||||
style_class: 'popup-status-menu-item'
|
style_class: 'popup-status-menu-item'
|
||||||
});
|
});
|
||||||
this._statusBin.child = this._switch.actor;
|
this._statusBin.child = this._switch;
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatus(text) {
|
setStatus(text) {
|
||||||
@ -344,7 +345,7 @@ class PopupSwitchMenuItem extends PopupBaseMenuItem {
|
|||||||
this.reactive = false;
|
this.reactive = false;
|
||||||
this.accessible_role = Atk.Role.MENU_ITEM;
|
this.accessible_role = Atk.Role.MENU_ITEM;
|
||||||
} else {
|
} else {
|
||||||
this._statusBin.child = this._switch.actor;
|
this._statusBin.child = this._switch;
|
||||||
this.reactive = true;
|
this.reactive = true;
|
||||||
this.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
this.accessible_role = Atk.Role.CHECK_MENU_ITEM;
|
||||||
}
|
}
|
||||||
@ -352,9 +353,8 @@ class PopupSwitchMenuItem extends PopupBaseMenuItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activate(event) {
|
activate(event) {
|
||||||
if (this._switch.actor.mapped) {
|
if (this._switch.mapped)
|
||||||
this.toggle();
|
this.toggle();
|
||||||
}
|
|
||||||
|
|
||||||
// we allow pressing space to toggle the switch
|
// we allow pressing space to toggle the switch
|
||||||
// without closing the menu
|
// without closing the menu
|
||||||
|
Loading…
Reference in New Issue
Block a user