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:
Florian Müllner 2024-12-16 14:21:18 +01:00 committed by Marge Bot
parent 6dbb2eef50
commit 296e5c32e4

View File

@ -531,6 +531,12 @@ export const Switch = 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]}},
}, class PopupSwitchMenuItem extends PopupBaseMenuItem {
_init(text, active, params) {
@ -602,12 +608,20 @@ export const PopupSwitchMenuItem = GObject.registerClass({
return this._switch.state;
}
set state(state) {
if (this._switch.state === state)
return;
this._switch.set({state});
}
setToggleState(state) {
this._switch.state = state;
this.set({state});
}
_onToggled() {
this.emit('toggled', this._switch.state);
this.notify('state');
this._checkAccessibleState();
}