popupMenu: Turn Switch state into a GObject property
A property is often more convenient than a method, as it can be used with bind_property() and friends. https://gitlab.gnome.org/GNOME/gnome-shell/issues/239
This commit is contained in:
parent
6eacbeb203
commit
4e26e0e53c
@ -305,25 +305,44 @@ class PopupSeparatorMenuItem extends PopupBaseMenuItem {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var Switch = GObject.registerClass(
|
var Switch = GObject.registerClass({
|
||||||
class Switch extends St.Bin {
|
Properties: {
|
||||||
|
'state': GObject.ParamSpec.boolean(
|
||||||
|
'state', 'state', 'state',
|
||||||
|
GObject.ParamFlags.READWRITE,
|
||||||
|
false),
|
||||||
|
},
|
||||||
|
}, class Switch extends St.Bin {
|
||||||
_init(state) {
|
_init(state) {
|
||||||
super._init({ style_class: 'toggle-switch',
|
this._state = false;
|
||||||
accessible_role: Atk.Role.CHECK_BOX,
|
|
||||||
can_focus: true });
|
super._init({
|
||||||
this.setToggleState(state);
|
style_class: 'toggle-switch',
|
||||||
|
accessible_role: Atk.Role.CHECK_BOX,
|
||||||
|
can_focus: true,
|
||||||
|
state,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setToggleState(state) {
|
get state() {
|
||||||
|
return this._state;
|
||||||
|
}
|
||||||
|
|
||||||
|
set state(state) {
|
||||||
|
if (this._state === state)
|
||||||
|
return;
|
||||||
|
|
||||||
if (state)
|
if (state)
|
||||||
this.add_style_pseudo_class('checked');
|
this.add_style_pseudo_class('checked');
|
||||||
else
|
else
|
||||||
this.remove_style_pseudo_class('checked');
|
this.remove_style_pseudo_class('checked');
|
||||||
this.state = state;
|
|
||||||
|
this._state = state;
|
||||||
|
this.notify('state');
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.setToggleState(!this.state);
|
this.state = !this.state;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -393,7 +412,7 @@ var PopupSwitchMenuItem = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setToggleState(state) {
|
setToggleState(state) {
|
||||||
this._switch.setToggleState(state);
|
this._switch.state = state;
|
||||||
this.checkAccessibleState();
|
this.checkAccessibleState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user