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