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

View File

@ -118,17 +118,12 @@ class ATIndicator extends PanelMenu.Button {
} }
_buildItem(string, schema, key) { _buildItem(string, schema, key) {
let settings = new Gio.Settings({schema_id: schema}); const settings = new Gio.Settings({schema_id: schema});
let widget = this._buildItemExtended(string, const widget = new PopupMenu.PopupSwitchMenuItem(string, false);
settings.get_boolean(key), settings.bind(key, widget, 'state', Gio.SettingsBindFlags.DEFAULT);
settings.is_writable(key),
enabled => settings.set_boolean(key, enabled));
settings.connect(`changed::${key}`, () => { widget.connect('toggled',
widget.setToggleState(settings.get_boolean(key)); () => this._queueSyncMenuVisibility());
this._queueSyncMenuVisibility();
});
return widget; return widget;
} }