diff --git a/docs/how-to-create-new-effects.md b/docs/how-to-create-new-effects.md index ede378a..c1a14f5 100644 --- a/docs/how-to-create-new-effects.md +++ b/docs/how-to-create-new-effects.md @@ -277,10 +277,6 @@ Remember to replace any occurrence of `simple-fade` with your effect's nick-name vertical - 60 - 60 - 60 - 60 @@ -422,10 +418,6 @@ Remember to replace any occurrence of `simple-fade` with your effect's nick-name vertical - 60 - 60 - 60 - 60 diff --git a/prefs.js b/prefs.js index c8a3c7a..78d2b3a 100644 --- a/prefs.js +++ b/prefs.js @@ -13,7 +13,7 @@ 'use strict'; -const {Gio, Gtk, Gdk} = imports.gi; +const {Gio, Gtk, Gdk, GLib, GObject} = imports.gi; const ExtensionUtils = imports.misc.extensionUtils; const Me = imports.misc.extensionUtils.getCurrentExtension(); @@ -31,6 +31,9 @@ const ALL_EFFECTS = [ Me.imports.src.Wisps.Wisps, ]; +// This template widget class is defined at the bottom of this file. +var BurnMyWindowsEffectPage = null; + ////////////////////////////////////////////////////////////////////////////////////////// // The preferences dialog is organized in pages, each of which is loaded from a // // separate ui file. There's one page with general options, all other paged are loaded // @@ -66,6 +69,9 @@ var PreferencesDialog = class PreferencesDialog { Gtk.IconTheme.get_default().add_resource_path('/img'); } + // Register the template widgets used in the settings dialog. + this._registerCustomClasses(); + // Store a reference to the settings object. this._settings = ExtensionUtils.getSettings(); @@ -82,10 +88,16 @@ var PreferencesDialog = class PreferencesDialog { ALL_EFFECTS.forEach(Effect => { const [minMajor, minMinor] = Effect.getMinShellVersion(); if (utils.shellVersionIsAtLeast(minMajor, minMinor)) { - const page = Effect.getPreferences(this); - if (page) { - stack.add_titled(page, Effect.getNick(), Effect.getLabel()); + + const page = new BurnMyWindowsEffectPage(Effect, this); + + // Add the Effect's preferences (if any). + const preferences = Effect.getPreferences(this); + if (preferences) { + this.gtkBoxAppend(page, preferences); } + + stack.add_titled(page, Effect.getNick(), Effect.getLabel()); } }); @@ -228,6 +240,17 @@ var PreferencesDialog = class PreferencesDialog { this._bindResetButton(settingsKey); } + // ----------------------------------------------------------------- GTK3 / GTK4 helpers + + // Appends the given child widget to the given Gtk.Box. + gtkBoxAppend(box, child) { + if (utils.isGTK4()) { + box.append(child); + } else { + box.pack_start(child, false, false, 0); + } + } + // ----------------------------------------------------------------------- private stuff // Searches for a reset button for the given settings key and make it reset the settings @@ -252,6 +275,91 @@ var PreferencesDialog = class PreferencesDialog { this._bindResetButton(settingsKey); } + + // Initializes template widgets used by the preferences dialog. + _registerCustomClasses() { + + // Each effect page is based on a template widget. This template contains the title + // and the preview button. + // clang-format off + BurnMyWindowsEffectPage = + GObject.registerClass({ + GTypeName: 'BurnMyWindowsEffectPage', + Template: `resource:///ui/${utils.getGTKString()}/effectPage.ui`, + InternalChildren: ['label', 'button'], + }, + class BurnMyWindowsEffectPage extends Gtk.Box { + _init(Effect, dialog) { + super._init(); + + // Set the effect's name as label. + this._label.label = Effect.getLabel(); + + // Open the preview window once the preview button is clicked. + this._button.connect('clicked', () => { + // Create a list of all currently enabled effects. + const enabledEffects = ALL_EFFECTS.filter(Effect => { + return dialog.getSettings().get_boolean(`${Effect.getNick()}-close-effect`); + }); + + // Disable all enabled effects temporarily. + enabledEffects.forEach(Effect => { + dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, false); + }); + + // Enable the to-be-previewed effect. + dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, true); + + // Create the preview-window. + const window = new Gtk.Window({ + title: `Preview for ${Effect.getLabel()}`, + default_width: 800, + default_height: 450, + modal: true, + transient_for: utils.isGTK4() ? this._button.get_root() : + this._button.get_toplevel() + }); + + const box = new Gtk.Box({ + orientation: Gtk.Orientation.VERTICAL, + valign: Gtk.Align.CENTER, + spacing: 10, + }); + + const label = Gtk.Label.new('Close this Window to Preview the Effect!'); + label.get_style_context().add_class('large-title'); + + const image = new Gtk.Image({ + icon_name: 'burn-my-windows-symbolic', + pixel_size: 128, + }); + + dialog.gtkBoxAppend(box, image); + dialog.gtkBoxAppend(box, label); + + if (utils.isGTK4()) { + window.set_child(box); + } else { + window.add(box); + } + + window.show(); + + // Restore settings when the window gets closed. + window.connect('unrealize', () => { + // Disable the to-be-previewed effect again. + dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, false); + + // Enable all previously enabled effects again. + enabledEffects.forEach(Effect => { + dialog.getSettings().set_boolean(`${Effect.getNick()}-close-effect`, true); + }); + }); + }); + } + }); + // clang-format on + } } // Nothing to do for now... diff --git a/resources/ui/gtk3/EnergizeA.ui b/resources/ui/gtk3/EnergizeA.ui index b292863..79afebc 100644 --- a/resources/ui/gtk3/EnergizeA.ui +++ b/resources/ui/gtk3/EnergizeA.ui @@ -17,10 +17,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk3/EnergizeB.ui b/resources/ui/gtk3/EnergizeB.ui index 080d2b6..051821d 100644 --- a/resources/ui/gtk3/EnergizeB.ui +++ b/resources/ui/gtk3/EnergizeB.ui @@ -17,10 +17,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk3/Fire.ui b/resources/ui/gtk3/Fire.ui index 688285c..4b43025 100644 --- a/resources/ui/gtk3/Fire.ui +++ b/resources/ui/gtk3/Fire.ui @@ -24,10 +24,6 @@ vertical - 60 - 60 - 60 - 60 @@ -81,19 +77,6 @@ - - - - - - - - - - none - diff --git a/resources/ui/gtk3/TVEffect.ui b/resources/ui/gtk3/TVEffect.ui index b992120..adebe01 100644 --- a/resources/ui/gtk3/TVEffect.ui +++ b/resources/ui/gtk3/TVEffect.ui @@ -10,10 +10,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk3/Wisps.ui b/resources/ui/gtk3/Wisps.ui index c14f1ff..ff096ae 100644 --- a/resources/ui/gtk3/Wisps.ui +++ b/resources/ui/gtk3/Wisps.ui @@ -17,10 +17,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk3/effectPage.ui b/resources/ui/gtk3/effectPage.ui new file mode 100644 index 0000000..5022669 --- /dev/null +++ b/resources/ui/gtk3/effectPage.ui @@ -0,0 +1,57 @@ + + + + + + + \ No newline at end of file diff --git a/resources/ui/gtk4/BrokenGlass.ui b/resources/ui/gtk4/BrokenGlass.ui index 7b77ca2..55c30eb 100644 --- a/resources/ui/gtk4/BrokenGlass.ui +++ b/resources/ui/gtk4/BrokenGlass.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/EnergizeA.ui b/resources/ui/gtk4/EnergizeA.ui index 92911d9..5236da0 100644 --- a/resources/ui/gtk4/EnergizeA.ui +++ b/resources/ui/gtk4/EnergizeA.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/EnergizeB.ui b/resources/ui/gtk4/EnergizeB.ui index 77f1e4d..786afcb 100644 --- a/resources/ui/gtk4/EnergizeB.ui +++ b/resources/ui/gtk4/EnergizeB.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/Fire.ui b/resources/ui/gtk4/Fire.ui index 346b2ee..52c503a 100644 --- a/resources/ui/gtk4/Fire.ui +++ b/resources/ui/gtk4/Fire.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 @@ -42,20 +38,6 @@ - - - - - - - - - - none - 1 - diff --git a/resources/ui/gtk4/Matrix.ui b/resources/ui/gtk4/Matrix.ui index 7f5a570..c6c7720 100644 --- a/resources/ui/gtk4/Matrix.ui +++ b/resources/ui/gtk4/Matrix.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/TRexAttack.ui b/resources/ui/gtk4/TRexAttack.ui index 2bfe567..b77e7f6 100644 --- a/resources/ui/gtk4/TRexAttack.ui +++ b/resources/ui/gtk4/TRexAttack.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/TVEffect.ui b/resources/ui/gtk4/TVEffect.ui index c64ecef..f49f0bc 100644 --- a/resources/ui/gtk4/TVEffect.ui +++ b/resources/ui/gtk4/TVEffect.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/Wisps.ui b/resources/ui/gtk4/Wisps.ui index fc89c31..8e5bcb2 100644 --- a/resources/ui/gtk4/Wisps.ui +++ b/resources/ui/gtk4/Wisps.ui @@ -3,10 +3,6 @@ vertical - 60 - 60 - 60 - 60 diff --git a/resources/ui/gtk4/effectPage.ui b/resources/ui/gtk4/effectPage.ui new file mode 100644 index 0000000..5022669 --- /dev/null +++ b/resources/ui/gtk4/effectPage.ui @@ -0,0 +1,57 @@ + + + + + + + \ No newline at end of file