status/a11y: Simplify switch setup
Almost all switches represent boolean settings, which means we can use bindings instead of fiddling with signal handlers. As menu items have a `:sensitive` property, this also deals with handling keys' writability. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3576>
This commit is contained in:
parent
296e5c32e4
commit
6029380267
@ -118,17 +118,12 @@ class ATIndicator extends PanelMenu.Button {
|
||||
}
|
||||
|
||||
_buildItem(string, schema, key) {
|
||||
let settings = new Gio.Settings({schema_id: schema});
|
||||
let widget = this._buildItemExtended(string,
|
||||
settings.get_boolean(key),
|
||||
settings.is_writable(key),
|
||||
enabled => settings.set_boolean(key, enabled));
|
||||
const settings = new Gio.Settings({schema_id: schema});
|
||||
const widget = new PopupMenu.PopupSwitchMenuItem(string, false);
|
||||
settings.bind(key, widget, 'state', Gio.SettingsBindFlags.DEFAULT);
|
||||
|
||||
settings.connect(`changed::${key}`, () => {
|
||||
widget.setToggleState(settings.get_boolean(key));
|
||||
|
||||
this._queueSyncMenuVisibility();
|
||||
});
|
||||
widget.connect('toggled',
|
||||
() => this._queueSyncMenuVisibility());
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user