2023-07-10 03:53:45 +00:00
|
|
|
import Adw from 'gi://Adw';
|
2023-07-01 00:11:37 +00:00
|
|
|
import GObject from 'gi://GObject';
|
|
|
|
|
2023-07-10 04:04:07 +00:00
|
|
|
import {ExtensionBase, GettextWrapper} from './sharedInternals.js';
|
2023-07-09 10:47:05 +00:00
|
|
|
import {extensionManager} from '../extensionsService.js';
|
|
|
|
|
2023-07-01 00:11:37 +00:00
|
|
|
export class ExtensionPreferences extends ExtensionBase {
|
2023-07-10 08:33:31 +00:00
|
|
|
static lookupByUUID(uuid) {
|
|
|
|
return extensionManager.lookup(uuid)?.stateObj ?? null;
|
|
|
|
}
|
|
|
|
|
2023-07-10 05:06:17 +00:00
|
|
|
static defineTranslationFunctions(url) {
|
|
|
|
const wrapper = new GettextWrapper(this, url);
|
|
|
|
return wrapper.defineTranslationFunctions();
|
|
|
|
}
|
|
|
|
|
2023-07-01 00:11:37 +00:00
|
|
|
/**
|
2023-07-10 03:53:45 +00:00
|
|
|
* Get the single widget that implements
|
|
|
|
* the extension's preferences.
|
2023-07-01 00:11:37 +00:00
|
|
|
*
|
2023-07-10 03:53:45 +00:00
|
|
|
* @returns {Gtk.Widget}
|
2023-07-01 00:11:37 +00:00
|
|
|
*/
|
2023-07-10 03:53:45 +00:00
|
|
|
getPreferencesWidget() {
|
2023-07-01 00:11:37 +00:00
|
|
|
throw new GObject.NotImplementedError();
|
|
|
|
}
|
2023-07-10 03:53:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill the preferences window with preferences.
|
|
|
|
*
|
|
|
|
* The default implementation adds the widget
|
|
|
|
* returned by getPreferencesWidget().
|
|
|
|
*
|
|
|
|
* @param {Adw.PreferencesWindow} window - the preferences window
|
|
|
|
*/
|
|
|
|
fillPreferencesWindow(window) {
|
|
|
|
const widget = this.getPreferencesWidget();
|
|
|
|
const page = this._wrapWidget(widget);
|
|
|
|
window.add(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
_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;
|
|
|
|
}
|
2023-07-01 00:11:37 +00:00
|
|
|
}
|
2023-07-16 23:13:06 +00:00
|
|
|
|
|
|
|
export const {
|
|
|
|
gettext, ngettext, pgettext,
|
|
|
|
} = ExtensionPreferences.defineTranslationFunctions();
|