🎉 Add a preview button to each effect page

This commit is contained in:
Simon Schneegans
2022-01-23 06:44:28 +01:00
parent b2f11f494d
commit 242625ee9f
17 changed files with 226 additions and 91 deletions
-8
View File
@@ -277,10 +277,6 @@ Remember to replace any occurrence of `simple-fade` with your effect's nick-name
<object class="GtkBox" id="simple-fade-prefs"> <object class="GtkBox" id="simple-fade-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
@@ -422,10 +418,6 @@ Remember to replace any occurrence of `simple-fade` with your effect's nick-name
<object class="GtkBox" id="simple-fade-prefs"> <object class="GtkBox" id="simple-fade-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
+112 -4
View File
@@ -13,7 +13,7 @@
'use strict'; 'use strict';
const {Gio, Gtk, Gdk} = imports.gi; const {Gio, Gtk, Gdk, GLib, GObject} = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils; const ExtensionUtils = imports.misc.extensionUtils;
const Me = imports.misc.extensionUtils.getCurrentExtension(); const Me = imports.misc.extensionUtils.getCurrentExtension();
@@ -31,6 +31,9 @@ const ALL_EFFECTS = [
Me.imports.src.Wisps.Wisps, 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 // // 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 // // 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'); 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. // Store a reference to the settings object.
this._settings = ExtensionUtils.getSettings(); this._settings = ExtensionUtils.getSettings();
@@ -82,10 +88,16 @@ var PreferencesDialog = class PreferencesDialog {
ALL_EFFECTS.forEach(Effect => { ALL_EFFECTS.forEach(Effect => {
const [minMajor, minMinor] = Effect.getMinShellVersion(); const [minMajor, minMinor] = Effect.getMinShellVersion();
if (utils.shellVersionIsAtLeast(minMajor, minMinor)) { if (utils.shellVersionIsAtLeast(minMajor, minMinor)) {
const page = Effect.getPreferences(this);
if (page) { const page = new BurnMyWindowsEffectPage(Effect, this);
stack.add_titled(page, Effect.getNick(), Effect.getLabel());
// 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); 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 // ----------------------------------------------------------------------- private stuff
// Searches for a reset button for the given settings key and make it reset the settings // 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); 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... // Nothing to do for now...
-4
View File
@@ -17,10 +17,6 @@
<object class="GtkBox" id="energize-a-prefs"> <object class="GtkBox" id="energize-a-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -17,10 +17,6 @@
<object class="GtkBox" id="energize-b-prefs"> <object class="GtkBox" id="energize-b-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-17
View File
@@ -24,10 +24,6 @@
<object class="GtkBox" id="fire-prefs"> <object class="GtkBox" id="fire-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
@@ -81,19 +77,6 @@
</child> </child>
</object> </object>
</child> </child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkFrame">
<child>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<style>
<class name="rich-list" />
</style>
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBoxRow">
-4
View File
@@ -10,10 +10,6 @@
<object class="GtkBox" id="tv-prefs"> <object class="GtkBox" id="tv-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -17,10 +17,6 @@
<object class="GtkBox" id="wisps-prefs"> <object class="GtkBox" id="wisps-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
+57
View File
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0" />
<template class="BurnMyWindowsEffectPage" parent="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="hexpand">1</property>
<property name="spacing">10</property>
<child>
<object class="GtkBox">
<child>
<object class="GtkLabel" id="label">
<property name="xalign">0</property>
<property name="hexpand">1</property>
<style>
<class name="large-title" />
</style>
</object>
</child>
<child>
<object class="GtkButton" id="button">
<property name="valign">fill</property>
<property name="child">
<object class="GtkBox">
<property name="margin_start">8</property>
<property name="margin_end">8</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="icon_name">media-playback-start-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<property name="label" translatable="yes">Preview the Effect</property>
</object>
</child>
</object>
</property>
<style>
<class name="suggested-action" />
<class name="pill-button" />
</style>
</object>
</child>
</object>
</child>
</template>
</interface>
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="broken-glass-prefs"> <object class="GtkBox" id="broken-glass-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="energize-a-prefs"> <object class="GtkBox" id="energize-a-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="energize-b-prefs"> <object class="GtkBox" id="energize-b-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-18
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="fire-prefs"> <object class="GtkBox" id="fire-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
@@ -42,20 +38,6 @@
</child> </child>
</object> </object>
</child> </child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkFrame">
<child>
<object class="GtkListBox">
<property name="selection-mode">none</property>
<property name="show-separators">1</property>
<style>
<class name="rich-list" />
</style>
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBoxRow">
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="matrix-prefs"> <object class="GtkBox" id="matrix-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="trex-prefs"> <object class="GtkBox" id="trex-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="tv-prefs"> <object class="GtkBox" id="tv-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
-4
View File
@@ -3,10 +3,6 @@
<object class="GtkBox" id="wisps-prefs"> <object class="GtkBox" id="wisps-prefs">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<child> <child>
<object class="GtkFrame"> <object class="GtkFrame">
+57
View File
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0" />
<template class="BurnMyWindowsEffectPage" parent="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-top">60</property>
<property name="margin-bottom">60</property>
<property name="margin-start">60</property>
<property name="margin-end">60</property>
<property name="hexpand">1</property>
<property name="spacing">10</property>
<child>
<object class="GtkBox">
<child>
<object class="GtkLabel" id="label">
<property name="xalign">0</property>
<property name="hexpand">1</property>
<style>
<class name="large-title" />
</style>
</object>
</child>
<child>
<object class="GtkButton" id="button">
<property name="valign">fill</property>
<property name="child">
<object class="GtkBox">
<property name="margin_start">8</property>
<property name="margin_end">8</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="icon_name">media-playback-start-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="halign">start</property>
<property name="label" translatable="yes">Preview the Effect</property>
</object>
</child>
</object>
</property>
<style>
<class name="suggested-action" />
<class name="pill-button" />
</style>
</object>
</child>
</object>
</child>
</template>
</interface>