popupMenu: Expose SwitchItem state as GObject property
This will allow using bindings instead of explicit signal connections. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3576>
This commit is contained in:

committed by
Marge Bot

parent
6dbb2eef50
commit
296e5c32e4
@ -531,6 +531,12 @@ export const Switch = GObject.registerClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const PopupSwitchMenuItem = GObject.registerClass({
|
export const PopupSwitchMenuItem = GObject.registerClass({
|
||||||
|
Properties: {
|
||||||
|
'state': GObject.ParamSpec.boolean(
|
||||||
|
'state', null, null,
|
||||||
|
GObject.ParamFlags.READWRITE,
|
||||||
|
false),
|
||||||
|
},
|
||||||
Signals: {'toggled': {param_types: [GObject.TYPE_BOOLEAN]}},
|
Signals: {'toggled': {param_types: [GObject.TYPE_BOOLEAN]}},
|
||||||
}, class PopupSwitchMenuItem extends PopupBaseMenuItem {
|
}, class PopupSwitchMenuItem extends PopupBaseMenuItem {
|
||||||
_init(text, active, params) {
|
_init(text, active, params) {
|
||||||
@ -602,12 +608,20 @@ export const PopupSwitchMenuItem = GObject.registerClass({
|
|||||||
return this._switch.state;
|
return this._switch.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set state(state) {
|
||||||
|
if (this._switch.state === state)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this._switch.set({state});
|
||||||
|
}
|
||||||
|
|
||||||
setToggleState(state) {
|
setToggleState(state) {
|
||||||
this._switch.state = state;
|
this.set({state});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onToggled() {
|
_onToggled() {
|
||||||
this.emit('toggled', this._switch.state);
|
this.emit('toggled', this._switch.state);
|
||||||
|
this.notify('state');
|
||||||
this._checkAccessibleState();
|
this._checkAccessibleState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user