extensionPrefs: Use actions for row controls
Actions are another mean to separate state and interactions from the UI. Start using them for the existing controls before adding more in follow-up commits. https://gitlab.gnome.org/GNOME/gnome-shell/issues/1968
This commit is contained in:
parent
1d72f28a1c
commit
059524b007
@ -350,11 +350,6 @@ var ExtensionsWindow = GObject.registerClass({
|
|||||||
|
|
||||||
_addExtensionRow(extension) {
|
_addExtensionRow(extension) {
|
||||||
let row = new ExtensionRow(extension);
|
let row = new ExtensionRow(extension);
|
||||||
|
|
||||||
row.prefsButton.connect('clicked', () => {
|
|
||||||
this._showPrefs(row.uuid);
|
|
||||||
});
|
|
||||||
|
|
||||||
row.show_all();
|
row.show_all();
|
||||||
this._extensionsList.add(row);
|
this._extensionsList.add(row);
|
||||||
}
|
}
|
||||||
@ -474,13 +469,9 @@ var Expander = GObject.registerClass({
|
|||||||
var ExtensionRow = GObject.registerClass({
|
var ExtensionRow = GObject.registerClass({
|
||||||
GTypeName: 'ExtensionRow',
|
GTypeName: 'ExtensionRow',
|
||||||
Template: 'resource:///org/gnome/shell/ui/extension-row.ui',
|
Template: 'resource:///org/gnome/shell/ui/extension-row.ui',
|
||||||
Children: [
|
|
||||||
'prefsButton',
|
|
||||||
],
|
|
||||||
InternalChildren: [
|
InternalChildren: [
|
||||||
'nameLabel',
|
'nameLabel',
|
||||||
'descriptionLabel',
|
'descriptionLabel',
|
||||||
'switch',
|
|
||||||
],
|
],
|
||||||
}, class ExtensionRow extends Gtk.ListBoxRow {
|
}, class ExtensionRow extends Gtk.ListBoxRow {
|
||||||
_init(extension) {
|
_init(extension) {
|
||||||
@ -490,22 +481,39 @@ var ExtensionRow = GObject.registerClass({
|
|||||||
this._extension = extension;
|
this._extension = extension;
|
||||||
this._prefsModule = null;
|
this._prefsModule = null;
|
||||||
|
|
||||||
|
this._actionGroup = new Gio.SimpleActionGroup();
|
||||||
|
this.insert_action_group('row', this._actionGroup);
|
||||||
|
|
||||||
|
let action;
|
||||||
|
action = new Gio.SimpleAction({
|
||||||
|
name: 'show-prefs',
|
||||||
|
enabled: this.hasPrefs,
|
||||||
|
});
|
||||||
|
action.connect('activate', () => this.get_toplevel().openPrefs(this.uuid));
|
||||||
|
this._actionGroup.add_action(action);
|
||||||
|
|
||||||
|
action = new Gio.SimpleAction({
|
||||||
|
name: 'enabled',
|
||||||
|
state: new GLib.Variant('b', false),
|
||||||
|
});
|
||||||
|
action.connect('activate', () => {
|
||||||
|
let state = action.get_state();
|
||||||
|
action.change_state(new GLib.Variant('b', !state.get_boolean()));
|
||||||
|
});
|
||||||
|
action.connect('change-state', (a, state) => {
|
||||||
|
if (state.get_boolean())
|
||||||
|
this._app.shellProxy.EnableExtensionRemote(this.uuid);
|
||||||
|
else
|
||||||
|
this._app.shellProxy.DisableExtensionRemote(this.uuid);
|
||||||
|
});
|
||||||
|
this._actionGroup.add_action(action);
|
||||||
|
|
||||||
let name = GLib.markup_escape_text(this.name, -1);
|
let name = GLib.markup_escape_text(this.name, -1);
|
||||||
this._nameLabel.label = name;
|
this._nameLabel.label = name;
|
||||||
|
|
||||||
let desc = this._extension.metadata.description.split('\n')[0];
|
let desc = this._extension.metadata.description.split('\n')[0];
|
||||||
this._descriptionLabel.label = desc;
|
this._descriptionLabel.label = desc;
|
||||||
|
|
||||||
this.prefsButton.visible = this.hasPrefs;
|
|
||||||
|
|
||||||
this._notifyActiveId = this._switch.connect('notify::active', () => {
|
|
||||||
if (this._switch.active)
|
|
||||||
this._app.shellProxy.EnableExtensionRemote(this.uuid);
|
|
||||||
else
|
|
||||||
this._app.shellProxy.DisableExtensionRemote(this.uuid);
|
|
||||||
});
|
|
||||||
this._switch.connect('state-set', () => true);
|
|
||||||
|
|
||||||
this.connect('destroy', this._onDestroy.bind(this));
|
this.connect('destroy', this._onDestroy.bind(this));
|
||||||
|
|
||||||
this._extensionStateChangedId = this._app.shellProxy.connectSignal(
|
this._extensionStateChangedId = this._app.shellProxy.connectSignal(
|
||||||
@ -538,11 +546,9 @@ var ExtensionRow = GObject.registerClass({
|
|||||||
_updateState() {
|
_updateState() {
|
||||||
let state = this._extension.state === ExtensionState.ENABLED;
|
let state = this._extension.state === ExtensionState.ENABLED;
|
||||||
|
|
||||||
this._switch.block_signal_handler(this._notifyActiveId);
|
let action = this._actionGroup.lookup('enabled');
|
||||||
this._switch.state = state;
|
action.set_state(new GLib.Variant('b', state));
|
||||||
this._switch.unblock_signal_handler(this._notifyActiveId);
|
action.enabled = this._canToggle();
|
||||||
|
|
||||||
this._switch.sensitive = this._canToggle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDestroy() {
|
_onDestroy() {
|
||||||
|
@ -27,9 +27,14 @@
|
|||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="prefsButton">
|
<object class="GtkButton" id="prefsButton">
|
||||||
<property name="no_show_all">True</property>
|
<property name="no_show_all">True</property>
|
||||||
|
<property name="visible"
|
||||||
|
bind-source="prefsButton"
|
||||||
|
bind-property="sensitive"
|
||||||
|
bind-flags="sync-create"/>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
|
<property name="action-name">row.show-prefs</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="circular"/>>
|
<class name="circular"/>>
|
||||||
<class name="image-button"/>>
|
<class name="image-button"/>>
|
||||||
@ -46,10 +51,11 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSwitch" id="switch">
|
<object class="GtkSwitch">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
|
<property name="action-name">row.enabled</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="height">2</property>
|
<property name="height">2</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user