dbusServides/extensions: Use Adw.PreferencesWindow
Adapt the new GNOME platform API for the upcoming 42. This makes sure that we get the latest version of the stylesheet, as well as support for the new dark mode. Using the dedicated preference API also gives extensions with more complex preferences an easier and standardized way for implementing multi-page preferences. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2012>
This commit is contained in:
parent
089fd315dd
commit
7a8b636028
@ -1,3 +1,5 @@
|
|||||||
|
.error-page preferencespage { margin: 30px; }
|
||||||
|
|
||||||
.expander { padding: 12px; }
|
.expander { padding: 12px; }
|
||||||
.expander.expanded { border: 0 solid @borders; border-bottom-width: 1px; }
|
.expander.expanded { border: 0 solid @borders; border-bottom-width: 1px; }
|
||||||
.expander-toolbar {
|
.expander-toolbar {
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
/* exported ExtensionPrefsDialog */
|
/* exported ExtensionPrefsDialog */
|
||||||
|
|
||||||
const { Gdk, Gio, GObject, Gtk } = imports.gi;
|
const { Adw, Gdk, Gio, GLib, GObject, Gtk } = imports.gi;
|
||||||
|
|
||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
|
|
||||||
var ExtensionPrefsDialog = GObject.registerClass({
|
var ExtensionPrefsDialog = GObject.registerClass({
|
||||||
GTypeName: 'ExtensionPrefsDialog',
|
GTypeName: 'ExtensionPrefsDialog',
|
||||||
}, class ExtensionPrefsDialog extends Gtk.Window {
|
}, class ExtensionPrefsDialog extends Adw.PreferencesWindow {
|
||||||
_init(extension) {
|
_init(extension) {
|
||||||
super._init({
|
super._init({
|
||||||
title: extension.metadata.name,
|
title: extension.metadata.name,
|
||||||
default_width: 600,
|
default_width: 600,
|
||||||
default_height: 400,
|
default_height: 400,
|
||||||
|
search_enabled: false,
|
||||||
});
|
});
|
||||||
this.set_titlebar(new Gtk.HeaderBar());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ExtensionUtils.installImporter(extension);
|
ExtensionUtils.installImporter(extension);
|
||||||
@ -26,12 +26,52 @@ var ExtensionPrefsDialog = GObject.registerClass({
|
|||||||
prefsModule.init(extension.metadata);
|
prefsModule.init(extension.metadata);
|
||||||
|
|
||||||
const widget = prefsModule.buildPrefsWidget();
|
const widget = prefsModule.buildPrefsWidget();
|
||||||
this.set_child(widget);
|
const page = this._wrapWidget(widget);
|
||||||
|
this.add(page);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.set_child(new ExtensionPrefsErrorPage(extension, e));
|
this._showErrorPage(e);
|
||||||
logError(e, 'Failed to open preferences');
|
logError(e, 'Failed to open preferences');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set titlebar(w) {
|
||||||
|
this.set_titlebar(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
|
set_titlebar() {
|
||||||
|
// intercept fatal libadwaita error, show error page instead
|
||||||
|
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
|
||||||
|
this._showErrorPage(
|
||||||
|
new Error('set_titlebar() is not supported for Adw.Window'));
|
||||||
|
return GLib.SOURCE_REMOVE;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_showErrorPage(e) {
|
||||||
|
while (this.visible_page)
|
||||||
|
this.remove(this.visible_page);
|
||||||
|
|
||||||
|
const extension = ExtensionUtils.getCurrentExtension();
|
||||||
|
this.add(new ExtensionPrefsErrorPage(extension, e));
|
||||||
|
}
|
||||||
|
|
||||||
|
_wrapWidget(widget) {
|
||||||
|
if (widget instanceof Adw.PreferencesPage)
|
||||||
|
return widget;
|
||||||
|
|
||||||
|
const page = new Adw.PreferencesPage();
|
||||||
|
if (widget instanceof Adw.PreferencesGroup) {
|
||||||
|
page.add(widget);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
const group = new Adw.PreferencesGroup();
|
||||||
|
group.add(widget);
|
||||||
|
page.add(group);
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const ExtensionPrefsErrorPage = GObject.registerClass({
|
const ExtensionPrefsErrorPage = GObject.registerClass({
|
||||||
@ -43,7 +83,7 @@ const ExtensionPrefsErrorPage = GObject.registerClass({
|
|||||||
'revealer',
|
'revealer',
|
||||||
'errorView',
|
'errorView',
|
||||||
],
|
],
|
||||||
}, class ExtensionPrefsErrorPage extends Gtk.Widget {
|
}, class ExtensionPrefsErrorPage extends Adw.PreferencesPage {
|
||||||
static _classInit(klass) {
|
static _classInit(klass) {
|
||||||
super._classInit(klass);
|
super._classInit(klass);
|
||||||
|
|
||||||
@ -61,9 +101,8 @@ const ExtensionPrefsErrorPage = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_init(extension, error) {
|
_init(extension, error) {
|
||||||
super._init({
|
super._init();
|
||||||
layout_manager: new Gtk.BinLayout(),
|
|
||||||
});
|
|
||||||
this._addCustomStylesheet();
|
this._addCustomStylesheet();
|
||||||
|
|
||||||
this._uuid = extension.uuid;
|
this._uuid = extension.uuid;
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
imports.gi.versions.Gdk = '4.0';
|
imports.gi.versions.Gdk = '4.0';
|
||||||
imports.gi.versions.Gtk = '4.0';
|
imports.gi.versions.Gtk = '4.0';
|
||||||
|
|
||||||
const { GObject, Gtk } = imports.gi;
|
const { Adw, GObject } = imports.gi;
|
||||||
const pkg = imports.package;
|
const pkg = imports.package;
|
||||||
|
|
||||||
const { DBusService } = imports.dbusService;
|
const { DBusService } = imports.dbusService;
|
||||||
const { ExtensionsService } = imports.extensionsService;
|
const { ExtensionsService } = imports.extensionsService;
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
Gtk.init();
|
Adw.init();
|
||||||
pkg.initFormat();
|
pkg.initFormat();
|
||||||
|
|
||||||
GObject.gtypeNameBasedOnJSPath = true;
|
GObject.gtypeNameBasedOnJSPath = true;
|
||||||
|
@ -1,107 +1,100 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<interface>
|
<interface>
|
||||||
<template class="ExtensionPrefsErrorPage" parent="GtkWidget">
|
<template class="ExtensionPrefsErrorPage" parent="AdwPreferencesPage">
|
||||||
|
<style>
|
||||||
|
<class name="error-page"/>
|
||||||
|
</style>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow">
|
<object class="AdwPreferencesGroup">
|
||||||
<property name="hscrollbar-policy">never</property>
|
|
||||||
<property name="propagate-natural-height">True</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkViewport">
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">12</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkLabel">
|
||||||
<property name="orientation">vertical</property>
|
<property name="label" translatable="yes">Something’s gone wrong</property>
|
||||||
<property name="margin-start">100</property>
|
<attributes>
|
||||||
<property name="margin-end">100</property>
|
<attribute name="scale" value="1.44"/> <!-- x-large -->
|
||||||
<property name="margin-top">100</property>
|
</attributes>
|
||||||
<property name="margin-bottom">60</property>
|
<style>
|
||||||
<property name="spacing">12</property>
|
<class name="dim-label"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="label" translatable="yes">We’re very sorry, but there’s been a problem: the settings for this extension can’t be displayed. We recommend that you report the issue to the extension authors.</property>
|
||||||
|
<property name="justify">center</property>
|
||||||
|
<property name="wrap">True</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame">
|
||||||
|
<property name="margin-top">12</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel">
|
<object class="GtkBox">
|
||||||
<property name="label" translatable="yes">Something’s gone wrong</property>
|
<property name="hexpand">True</property>
|
||||||
<attributes>
|
<property name="orientation">vertical</property>
|
||||||
<attribute name="scale" value="1.44"/> <!-- x-large -->
|
|
||||||
</attributes>
|
|
||||||
<style>
|
|
||||||
<class name="dim-label"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">We’re very sorry, but there’s been a problem: the settings for this extension can’t be displayed. We recommend that you report the issue to the extension authors.</property>
|
|
||||||
<property name="justify">center</property>
|
|
||||||
<property name="wrap">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkFrame">
|
|
||||||
<property name="margin-top">12</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox" id="expander">
|
||||||
<property name="hexpand">True</property>
|
<property name="spacing">6</property>
|
||||||
<property name="orientation">vertical</property>
|
<style>
|
||||||
|
<class name="expander"/>
|
||||||
|
</style>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="expander">
|
<object class="GtkImage" id="expanderArrow">
|
||||||
<property name="spacing">6</property>
|
<property name="icon-name">pan-end-symbolic</property>
|
||||||
<style>
|
|
||||||
<class name="expander"/>
|
|
||||||
</style>
|
|
||||||
<child>
|
|
||||||
<object class="GtkImage" id="expanderArrow">
|
|
||||||
<property name="icon-name">pan-end-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Technical Details</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkRevealer" id="revealer">
|
<object class="GtkLabel">
|
||||||
|
<property name="label" translatable="yes">Technical Details</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkRevealer" id="revealer">
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTextView" id="errorView">
|
||||||
|
<property name="monospace">True</property>
|
||||||
|
<property name="editable">False</property>
|
||||||
|
<property name="wrap-mode">word</property>
|
||||||
|
<property name="left-margin">12</property>
|
||||||
|
<property name="right-margin">12</property>
|
||||||
|
<property name="top-margin">12</property>
|
||||||
|
<property name="bottom-margin">12</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="orientation">vertical</property>
|
<style>
|
||||||
|
<class name="expander-toolbar"/>
|
||||||
|
</style>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkTextView" id="errorView">
|
<object class="GtkButton">
|
||||||
<property name="monospace">True</property>
|
<property name="receives-default">True</property>
|
||||||
<property name="editable">False</property>
|
<property name="action-name">page.copy-error</property>
|
||||||
<property name="wrap-mode">word</property>
|
<property name="has-frame">False</property>
|
||||||
<property name="left-margin">12</property>
|
<property name="icon-name">edit-copy-symbolic</property>
|
||||||
<property name="right-margin">12</property>
|
|
||||||
<property name="top-margin">12</property>
|
|
||||||
<property name="bottom-margin">12</property>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkButton" id="homeButton">
|
||||||
<style>
|
<property name="visible"
|
||||||
<class name="expander-toolbar"/>
|
bind-source="homeButton"
|
||||||
</style>
|
bind-property="sensitive"
|
||||||
<child>
|
bind-flags="sync-create"/>
|
||||||
<object class="GtkButton">
|
<property name="hexpand">True</property>
|
||||||
<property name="receives-default">True</property>
|
<property name="halign">end</property>
|
||||||
<property name="action-name">page.copy-error</property>
|
<property name="label" translatable="yes">Homepage</property>
|
||||||
<property name="has-frame">False</property>
|
<property name="tooltip-text" translatable="yes">Visit extension homepage</property>
|
||||||
<property name="icon-name">edit-copy-symbolic</property>
|
<property name="receives-default">True</property>
|
||||||
</object>
|
<property name="has-frame">False</property>
|
||||||
</child>
|
<property name="action-name">page.show-url</property>
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="homeButton">
|
|
||||||
<property name="visible"
|
|
||||||
bind-source="homeButton"
|
|
||||||
bind-property="sensitive"
|
|
||||||
bind-flags="sync-create"/>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="halign">end</property>
|
|
||||||
<property name="label" translatable="yes">Homepage</property>
|
|
||||||
<property name="tooltip-text" translatable="yes">Visit extension homepage</property>
|
|
||||||
<property name="receives-default">True</property>
|
|
||||||
<property name="has-frame">False</property>
|
|
||||||
<property name="action-name">page.show-url</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
Loading…
Reference in New Issue
Block a user