extensionPrefs: Split out window class
Currently the main window is a plain Gtk.ApplicationWindow that is built and managed from within the application. As the application becomes more complex, it makes sense to decouple the two and handle the window from a separate ExtensionsWindow class. Not least this is a prerequisite of using a widget template for the window. https://gitlab.gnome.org/GNOME/gnome-shell/issues/1968
This commit is contained in:
parent
9916989272
commit
f49e20bbae
@ -30,18 +30,80 @@ class Application extends Gtk.Application {
|
|||||||
application_id: 'org.gnome.shell.ExtensionPrefs',
|
application_id: 'org.gnome.shell.ExtensionPrefs',
|
||||||
flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
||||||
});
|
});
|
||||||
|
|
||||||
this._startupUuid = null;
|
|
||||||
this._loaded = false;
|
|
||||||
this._skipMainWindow = false;
|
|
||||||
this._shellProxy = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get shellProxy() {
|
get shellProxy() {
|
||||||
return this._shellProxy;
|
return this._shellProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfunc_activate() {
|
||||||
|
this._window.present();
|
||||||
|
}
|
||||||
|
|
||||||
|
vfunc_startup() {
|
||||||
|
super.vfunc_startup();
|
||||||
|
|
||||||
|
this._shellProxy = new GnomeShellProxy(Gio.DBus.session, 'org.gnome.Shell', '/org/gnome/Shell');
|
||||||
|
this._window = new ExtensionsWindow({ application: this });
|
||||||
|
}
|
||||||
|
|
||||||
|
vfunc_command_line(commandLine) {
|
||||||
|
let args = commandLine.get_arguments();
|
||||||
|
|
||||||
|
if (args.length) {
|
||||||
|
let uuid = args[0];
|
||||||
|
|
||||||
|
// Strip off "extension:///" prefix which fakes a URI, if it exists
|
||||||
|
uuid = stripPrefix(uuid, 'extension:///');
|
||||||
|
|
||||||
|
this._window.openPrefs(uuid);
|
||||||
|
} else {
|
||||||
|
this.activate();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var ExtensionsWindow = GObject.registerClass(
|
||||||
|
class ExtensionsWindow extends Gtk.ApplicationWindow {
|
||||||
|
_init(params) {
|
||||||
|
super._init(params);
|
||||||
|
|
||||||
|
this._startupUuid = null;
|
||||||
|
this._loaded = false;
|
||||||
|
this._prefsDialog = null;
|
||||||
|
|
||||||
|
this._buildUI();
|
||||||
|
|
||||||
|
this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
|
||||||
|
this._settings.bind('disable-user-extensions',
|
||||||
|
this._killSwitch, 'active',
|
||||||
|
Gio.SettingsBindFlags.DEFAULT | Gio.SettingsBindFlags.INVERT_BOOLEAN);
|
||||||
|
|
||||||
|
this._extensionSelector.set_sort_func(this._sortList.bind(this));
|
||||||
|
this._extensionSelector.set_header_func(this._updateHeader.bind(this));
|
||||||
|
|
||||||
|
this._shellProxy.connectSignal('ExtensionStateChanged',
|
||||||
|
this._onExtensionStateChanged.bind(this));
|
||||||
|
|
||||||
|
this._scanExtensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
get _shellProxy() {
|
||||||
|
return this.application.shellProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
openPrefs(uuid) {
|
||||||
|
if (!this._loaded)
|
||||||
|
this._startupUuid = uuid;
|
||||||
|
else if (!this._showPrefs(uuid))
|
||||||
|
this.present();
|
||||||
|
}
|
||||||
|
|
||||||
_showPrefs(uuid) {
|
_showPrefs(uuid) {
|
||||||
|
if (this._prefsDialog)
|
||||||
|
return false;
|
||||||
|
|
||||||
let row = this._extensionSelector.get_children().find(c => {
|
let row = this._extensionSelector.get_children().find(c => {
|
||||||
return c.uuid === uuid && c.hasPrefs;
|
return c.uuid === uuid && c.hasPrefs;
|
||||||
});
|
});
|
||||||
@ -57,29 +119,33 @@ class Application extends Gtk.Application {
|
|||||||
widget = this._buildErrorUI(row, e);
|
widget = this._buildErrorUI(row, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dialog = new Gtk.Window({
|
this._prefsDialog = new Gtk.Window({
|
||||||
modal: !this._skipMainWindow,
|
application: this.application,
|
||||||
|
default_width: 600,
|
||||||
|
default_height: 400,
|
||||||
|
modal: this.visible,
|
||||||
type_hint: Gdk.WindowTypeHint.DIALOG,
|
type_hint: Gdk.WindowTypeHint.DIALOG,
|
||||||
|
window_position: Gtk.WindowPosition.CENTER,
|
||||||
});
|
});
|
||||||
dialog.set_titlebar(new Gtk.HeaderBar({
|
|
||||||
|
this._prefsDialog.set_titlebar(new Gtk.HeaderBar({
|
||||||
show_close_button: true,
|
show_close_button: true,
|
||||||
title: row.name,
|
title: row.name,
|
||||||
visible: true,
|
visible: true,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (this._skipMainWindow) {
|
if (this.visible)
|
||||||
this.add_window(dialog);
|
this._prefsDialog.transient_for = this;
|
||||||
if (this._window)
|
|
||||||
this._window.destroy();
|
|
||||||
this._window = dialog;
|
|
||||||
this._window.window_position = Gtk.WindowPosition.CENTER;
|
|
||||||
} else {
|
|
||||||
dialog.transient_for = this._window;
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.set_default_size(600, 400);
|
this._prefsDialog.connect('destroy', () => {
|
||||||
dialog.add(widget);
|
this._prefsDialog = null;
|
||||||
dialog.show();
|
|
||||||
|
if (!this.visible)
|
||||||
|
this.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
this._prefsDialog.add(widget);
|
||||||
|
this._prefsDialog.show();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -200,27 +266,23 @@ class Application extends Gtk.Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildUI() {
|
_buildUI() {
|
||||||
this._window = new Gtk.ApplicationWindow({ application: this,
|
this.set({
|
||||||
window_position: Gtk.WindowPosition.CENTER });
|
window_position: Gtk.WindowPosition.CENTER,
|
||||||
|
default_width: 800,
|
||||||
this._window.set_default_size(800, 500);
|
default_height: 500,
|
||||||
|
});
|
||||||
|
|
||||||
this._titlebar = new Gtk.HeaderBar({ show_close_button: true,
|
this._titlebar = new Gtk.HeaderBar({ show_close_button: true,
|
||||||
title: _("Shell Extensions") });
|
title: _("Shell Extensions") });
|
||||||
this._window.set_titlebar(this._titlebar);
|
this.set_titlebar(this._titlebar);
|
||||||
|
|
||||||
let killSwitch = new Gtk.Switch({ valign: Gtk.Align.CENTER });
|
this._killSwitch = new Gtk.Switch({ valign: Gtk.Align.CENTER });
|
||||||
this._titlebar.pack_end(killSwitch);
|
this._titlebar.pack_end(this._killSwitch);
|
||||||
|
|
||||||
this._settings = new Gio.Settings({ schema_id: 'org.gnome.shell' });
|
|
||||||
this._settings.bind('disable-user-extensions', killSwitch, 'active',
|
|
||||||
Gio.SettingsBindFlags.DEFAULT |
|
|
||||||
Gio.SettingsBindFlags.INVERT_BOOLEAN);
|
|
||||||
|
|
||||||
this._mainStack = new Gtk.Stack({
|
this._mainStack = new Gtk.Stack({
|
||||||
transition_type: Gtk.StackTransitionType.CROSSFADE,
|
transition_type: Gtk.StackTransitionType.CROSSFADE,
|
||||||
});
|
});
|
||||||
this._window.add(this._mainStack);
|
this.add(this._mainStack);
|
||||||
|
|
||||||
let scroll = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER });
|
let scroll = new Gtk.ScrolledWindow({ hscrollbar_policy: Gtk.PolicyType.NEVER });
|
||||||
|
|
||||||
@ -233,11 +295,7 @@ class Application extends Gtk.Application {
|
|||||||
this._mainStack.add_named(scroll, 'listing');
|
this._mainStack.add_named(scroll, 'listing');
|
||||||
this._mainStack.add_named(new EmptyPlaceholder(), 'placeholder');
|
this._mainStack.add_named(new EmptyPlaceholder(), 'placeholder');
|
||||||
|
|
||||||
this._shellProxy = new GnomeShellProxy(Gio.DBus.session, 'org.gnome.Shell', '/org/gnome/Shell');
|
this.show_all();
|
||||||
this._shellProxy.connectSignal('ExtensionStateChanged',
|
|
||||||
this._onExtensionStateChanged.bind(this));
|
|
||||||
|
|
||||||
this._window.show_all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sortList(row1, row2) {
|
_sortList(row1, row2) {
|
||||||
@ -309,40 +367,8 @@ class Application extends Gtk.Application {
|
|||||||
if (this._startupUuid)
|
if (this._startupUuid)
|
||||||
this._showPrefs(this._startupUuid);
|
this._showPrefs(this._startupUuid);
|
||||||
this._startupUuid = null;
|
this._startupUuid = null;
|
||||||
this._skipMainWindow = false;
|
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vfunc_activate() {
|
|
||||||
this._window.present();
|
|
||||||
}
|
|
||||||
|
|
||||||
vfunc_startup() {
|
|
||||||
super.vfunc_startup();
|
|
||||||
|
|
||||||
this._buildUI();
|
|
||||||
this._scanExtensions();
|
|
||||||
}
|
|
||||||
|
|
||||||
vfunc_command_line(commandLine) {
|
|
||||||
this.activate();
|
|
||||||
let args = commandLine.get_arguments();
|
|
||||||
|
|
||||||
if (args.length) {
|
|
||||||
let uuid = args[0];
|
|
||||||
|
|
||||||
this._skipMainWindow = true;
|
|
||||||
|
|
||||||
// Strip off "extension:///" prefix which fakes a URI, if it exists
|
|
||||||
uuid = stripPrefix(uuid, "extension:///");
|
|
||||||
|
|
||||||
if (!this._loaded)
|
|
||||||
this._startupUuid = uuid;
|
|
||||||
else if (!this._showPrefs(uuid))
|
|
||||||
this._skipMainWindow = false;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var Expander = GObject.registerClass({
|
var Expander = GObject.registerClass({
|
||||||
|
Loading…
Reference in New Issue
Block a user