Skip to content
  • Florian Müllner's avatar
    extensions: Make ExtensionPreferences more flexible · 797df4f5
    Florian Müllner authored
    Extensions must now export a class with a fillPreferencesWindow()
    method in their prefs. That is less convenient for extensions
    with simple preferences than the old buildPrefsWidget() hook, as
    they must wrap their widget in page/group widgets.
    
    Address this by adding a default fillPreferencesWindow() implementation
    that calls a getPreferencesWidget() method and wraps it as necessary.
    
    This is flexible enough to support different cases fairly conveniently,
    from simple single-widget prefs over tweaking the window to complex
    multi-page prefs:
    
    ```js
    class SimplePreferences extends ExtensionPreferences {
        getPreferencesWidget() {
            return new SimplePrefsWidget();
        }
    }
    
    class TinkerPreferences extends ExtensionPreferences {
        getPreferencesWidget() {
            return new SimplePrefsWidget();
        }
    
        fillPreferencesWindow(window) {
            super.fillPreferencesWindow(window);
    
            window.set_default_size(123, 456);
        }
    }
    
    class FullPreferences extends ExtensionPreferences {
        fillPreferencesWindow(window) {
            const page1 = new GeneralPage();
            window.add(page1);
    
            const page2 = new FoobarPage();
            window.add(page2);
        }
    }
    ```
    
    Part-of: <!2838>
    797df4f5