diff --git a/prefs.js b/prefs.js index 87273f3..e002708 100644 --- a/prefs.js +++ b/prefs.js @@ -30,6 +30,8 @@ const GeneralPage = Me.imports.src.prefs.GeneralPage.GeneralPage; // we might consider to improve its layout... // ////////////////////////////////////////////////////////////////////////////////////////// +const EFFECT_TYPES = [FirePage, MatrixPage, TVEffectPage, TRexPage]; + var PreferencesDialog = class PreferencesDialog { // ------------------------------------------------------------ constructor / destructor @@ -47,44 +49,70 @@ var PreferencesDialog = class PreferencesDialog { this._builder.add_from_resource(`/ui/common/main-menu.ui`); this._builder.add_from_resource(`/ui/${utils.isGTK4() ? 'gtk4' : 'gtk3'}/prefs.ui`); - this._generalPage = new GeneralPage(this._settings, this._builder); - this._firePage = new FirePage(this._settings, this._builder); - this._matrixPage = new MatrixPage(this._settings, this._builder); - this._tvEffectPage = new TVEffectPage(this._settings, this._builder); - this._trexPage = new TRexPage(this._settings, this._builder); + this._generalPAge = new GeneralPage(this._settings, this._builder); + + this._effects = []; + EFFECT_TYPES.forEach(Type => { + const [minMajor, minMinor] = Type.getMinShellVersion(); + if (utils.shellVersionIsAtLeast(minMajor, minMinor)) { + this._effects.push(new Type(this._settings, this._builder)); + } + }); // This is our top-level widget which we will return later. this._widget = this._builder.get_object('settings-widget'); - // Add a menu to the title bar of the preferences dialog. + // Some things can only be done once the widget is shown as we do not have access to + // the toplevel widget before. this._widget.connect('realize', (widget) => { const window = utils.isGTK4() ? widget.get_root() : widget.get_toplevel(); // Show the version number in the title bar. window.set_title(`Burn-My-Windows ${Me.metadata.version}`); - // Add the menu. - const menu = this._builder.get_object('menu-button'); - window.get_titlebar().pack_end(menu); + // Add the main menu to the title bar. + { + // Add the menu button to the title bar. + const menu = this._builder.get_object('menu-button'); + window.get_titlebar().pack_end(menu); - // Populate the actions. - const group = Gio.SimpleActionGroup.new(); + // Populate the menu with actions. + const group = Gio.SimpleActionGroup.new(); + window.insert_action_group('prefs', group); - const addAction = (name, uri) => { - const action = Gio.SimpleAction.new(name, null); - action.connect('activate', () => Gtk.show_uri(null, uri, Gdk.CURRENT_TIME)); - group.add_action(action); - }; + const addAction = (name, uri) => { + const action = Gio.SimpleAction.new(name, null); + action.connect('activate', () => Gtk.show_uri(null, uri, Gdk.CURRENT_TIME)); + group.add_action(action); + }; - // clang-format off - addAction('homepage', 'https://github.com/Schneegans/Burn-My-Windows'); - addAction('changelog', 'https://github.com/Schneegans/Burn-My-Windows/blob/main/docs/changelog.md'); - addAction('bugs', 'https://github.com/Schneegans/Burn-My-Windows/issues'); - addAction('donate-paypal', 'https://www.paypal.com/donate/?hosted_button_id=3F7UFL8KLVPXE'); - addAction('donate-github', 'https://github.com/sponsors/Schneegans'); - // clang-format on + // clang-format off + addAction('homepage', 'https://github.com/Schneegans/Burn-My-Windows'); + addAction('changelog', 'https://github.com/Schneegans/Burn-My-Windows/blob/main/docs/changelog.md'); + addAction('bugs', 'https://github.com/Schneegans/Burn-My-Windows/issues'); + addAction('donate-paypal', 'https://www.paypal.com/donate/?hosted_button_id=3F7UFL8KLVPXE'); + addAction('donate-github', 'https://github.com/sponsors/Schneegans'); + // clang-format on + } - window.insert_action_group('prefs', group); + // Populate the close-effects drop-down menu. + { + const group = Gio.SimpleActionGroup.new(); + window.insert_action_group('close-effects', group); + + const menu = this._builder.get_object('close-effect-menu'); + + this._effects.forEach(effect => { + const prefix = effect.constructor.getSettingsPrefix(); + const label = effect.constructor.getLabel(); + + const action = this._settings.create_action(`${prefix}-close-effect`); + group.add_action(action); + + menu.append_item( + Gio.MenuItem.new(label, `close-effects.${prefix}-close-effect`)); + }); + } }); // As we do not have something like a destructor, we just listen for the destroy diff --git a/resources/ui/gtk3/generalPage.ui b/resources/ui/gtk3/generalPage.ui index ddecbf9..9c952b8 100644 --- a/resources/ui/gtk3/generalPage.ui +++ b/resources/ui/gtk3/generalPage.ui @@ -1,6 +1,8 @@ + + vertical 60 @@ -54,21 +56,8 @@ - Effects - - - - - - - edit-clear-symbolic - 1 - - - Reset to Default Value - + Choose Effects + close-effect-menu diff --git a/resources/ui/gtk4/generalPage.ui b/resources/ui/gtk4/generalPage.ui index 6146516..193c826 100644 --- a/resources/ui/gtk4/generalPage.ui +++ b/resources/ui/gtk4/generalPage.ui @@ -1,6 +1,8 @@ + + vertical 60 @@ -54,16 +56,8 @@ - Effects - - - - - edit-clear-symbolic - Reset to Default Value - + Choose Effects + close-effect-menu diff --git a/src/prefs/FirePage.js b/src/prefs/FirePage.js index 66a700b..dbeadea 100644 --- a/src/prefs/FirePage.js +++ b/src/prefs/FirePage.js @@ -25,6 +25,20 @@ const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; var FirePage = class FirePage extends PrefsPage { + // ---------------------------------------------------------------------- static methods + + static getMinShellVersion() { + return [3, 36]; + } + + static getSettingsPrefix() { + return 'fire'; + } + + static getLabel() { + return 'Fire'; + } + // ------------------------------------------------------------ constructor / destructor constructor(settings, builder) { @@ -60,16 +74,6 @@ var FirePage = class FirePage extends PrefsPage { stack.add_titled(this._builder.get_object('fire-prefs'), 'fire', 'Fire'); } - // ---------------------------------------------------------------------- public methods - - getEnabledKey() { - return 'fire-close-effect'; - } - - getAnimationTime() { - return this._settings.get_int('fire-animation-time'); - } - // ----------------------------------------------------------------------- private stuff // This populates the preset dropdown menu for the fire options. diff --git a/src/prefs/MatrixPage.js b/src/prefs/MatrixPage.js index e6dbf47..4ab405f 100644 --- a/src/prefs/MatrixPage.js +++ b/src/prefs/MatrixPage.js @@ -23,15 +23,25 @@ const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; var MatrixPage = class MatrixPage extends PrefsPage { + // ---------------------------------------------------------------------- static methods + + static getMinShellVersion() { + return [40, 0]; + } + + static getSettingsPrefix() { + return 'matrix'; + } + + static getLabel() { + return 'Matrix'; + } + // ------------------------------------------------------------ constructor / destructor constructor(settings, builder) { super(settings, builder); - if (!utils.shellVersionIsAtLeast(40, 0)) { - return; - } - this._builder.add_from_resource('/ui/gtk4/matrixPage.ui'); // Bind all properties. @@ -44,14 +54,4 @@ var MatrixPage = class MatrixPage extends PrefsPage { const stack = this._builder.get_object('main-stack'); stack.add_titled(this._builder.get_object('matrix-prefs'), 'matrix', 'Matrix'); } - - // ---------------------------------------------------------------------- public methods - - getEnabledKey() { - return 'matrix-close-effect'; - } - - getAnimationTime() { - return this._settings.get_int('matrix-animation-time'); - } } \ No newline at end of file diff --git a/src/prefs/TRexPage.js b/src/prefs/TRexPage.js index 633cfff..113b02c 100644 --- a/src/prefs/TRexPage.js +++ b/src/prefs/TRexPage.js @@ -23,15 +23,25 @@ const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; var TRexPage = class TRexPage extends PrefsPage { + // ---------------------------------------------------------------------- static methods + + static getMinShellVersion() { + return [40, 0]; + } + + static getSettingsPrefix() { + return 'trex'; + } + + static getLabel() { + return 'T-Rex Attack'; + } + // ------------------------------------------------------------ constructor / destructor constructor(settings, builder) { super(settings, builder); - if (!utils.shellVersionIsAtLeast(40, 0)) { - return; - } - this._builder.add_from_resource('/ui/gtk4/trexPage.ui'); // Bind all properties. @@ -44,14 +54,4 @@ var TRexPage = class TRexPage extends PrefsPage { const stack = this._builder.get_object('main-stack'); stack.add_titled(this._builder.get_object('trex-prefs'), 'trex', 'T-Rex Attack'); } - - // ---------------------------------------------------------------------- public methods - - getEnabledKey() { - return 'trex-close-effect'; - } - - getAnimationTime() { - return this._settings.get_int('trex-animation-time'); - } } \ No newline at end of file diff --git a/src/prefs/TVEffectPage.js b/src/prefs/TVEffectPage.js index 284bd1b..b919597 100644 --- a/src/prefs/TVEffectPage.js +++ b/src/prefs/TVEffectPage.js @@ -23,6 +23,20 @@ const PrefsPage = Me.imports.src.prefs.PrefsPage.PrefsPage; var TVEffectPage = class TVEffectPage extends PrefsPage { + // ---------------------------------------------------------------------- static methods + + static getMinShellVersion() { + return [3, 36]; + } + + static getSettingsPrefix() { + return 'tv'; + } + + static getLabel() { + return 'TV Effect'; + } + // ------------------------------------------------------------ constructor / destructor constructor(settings, builder) { @@ -37,14 +51,4 @@ var TVEffectPage = class TVEffectPage extends PrefsPage { const stack = this._builder.get_object('main-stack'); stack.add_titled(this._builder.get_object('tv-prefs'), 'tv', 'TV Effect'); } - - // ---------------------------------------------------------------------- public methods - - getEnabledKey() { - return 'tv-close-effect'; - } - - getAnimationTime() { - return this._settings.get_int('tv-animation-time'); - } } \ No newline at end of file