dbusServices/extensions: Simplify actions handling

GTK4 has dedicated API for widget-specific actions, make use of that
instead of explicitly managing an action group.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2012>
This commit is contained in:
Florian Müllner 2021-07-30 00:58:18 +02:00 committed by Marge Bot
parent ae92c1c4eb
commit 089fd315dd

View File

@ -44,19 +44,32 @@ const ExtensionPrefsErrorPage = GObject.registerClass({
'errorView', 'errorView',
], ],
}, class ExtensionPrefsErrorPage extends Gtk.Widget { }, class ExtensionPrefsErrorPage extends Gtk.Widget {
static _classInit(klass) {
super._classInit(klass);
klass.install_action('page.copy-error',
null,
self => {
const clipboard = self.get_display().get_clipboard();
clipboard.set(self._errorMarkdown);
});
klass.install_action('page.show-url',
null,
self => Gtk.show_uri(self.get_root(), self._url, Gdk.CURRENT_TIME));
return klass;
}
_init(extension, error) { _init(extension, error) {
super._init({ super._init({
layout_manager: new Gtk.BinLayout(), layout_manager: new Gtk.BinLayout(),
}); });
this._addCustomStylesheet();
this._uuid = extension.uuid; this._uuid = extension.uuid;
this._url = extension.metadata.url || ''; this._url = extension.metadata.url || '';
this._actionGroup = new Gio.SimpleActionGroup(); this.action_set_enabled('page.show-url', this._url !== '');
this.insert_action_group('page', this._actionGroup);
this._initActions();
this._addCustomStylesheet();
this._gesture = new Gtk.GestureClick({ this._gesture = new Gtk.GestureClick({
button: 0, button: 0,
@ -106,27 +119,6 @@ const ExtensionPrefsErrorPage = GObject.registerClass({
this._expander.remove_css_class('expanded'); this._expander.remove_css_class('expanded');
} }
_initActions() {
let action;
action = new Gio.SimpleAction({ name: 'copy-error' });
action.connect('activate', () => {
const clipboard = this.get_display().get_clipboard();
clipboard.set(this._errorMarkdown);
});
this._actionGroup.add_action(action);
action = new Gio.SimpleAction({
name: 'show-url',
enabled: this._url !== '',
});
action.connect('activate', () => {
Gio.AppInfo.launch_default_for_uri(this._url,
this.get_display().get_app_launch_context());
});
this._actionGroup.add_action(action);
}
_addCustomStylesheet() { _addCustomStylesheet() {
let provider = new Gtk.CssProvider(); let provider = new Gtk.CssProvider();
let uri = 'resource:///org/gnome/Shell/Extensions/css/application.css'; let uri = 'resource:///org/gnome/Shell/Extensions/css/application.css';