🔧 Add close-effects menu

This commit is contained in:
Simon Schneegans
2022-01-09 13:05:34 +01:00
parent e3f0288eaf
commit 7ec9609d7a
7 changed files with 116 additions and 97 deletions
+52 -24
View File
@@ -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
+4 -15
View File
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="close-effect-menu"></menu>
<object class="GtkBox" id="general-prefs">
<property name="orientation">vertical</property>
<property name="margin-start">60</property>
@@ -54,21 +56,8 @@
</child>
<child>
<object class="GtkMenuButton" id="close-effect-button">
<property name="label">Effects</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-close-animation">
<child>
<object class="GtkImage">
<property name="icon-name">edit-clear-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
<property name="tooltip-text">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
<property name="label">Choose Effects</property>
<property name="menu-model">close-effect-menu</property>
</object>
</child>
</object>
+4 -10
View File
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="close-effect-menu"></menu>
<object class="GtkBox" id="general-prefs">
<property name="orientation">vertical</property>
<property name="margin-start">60</property>
@@ -54,16 +56,8 @@
</child>
<child>
<object class="GtkMenuButton" id="close-effect-button">
<property name="label">Effects</property>
</object>
</child>
<child>
<object class="GtkButton" id="reset-close-animation">
<property name="icon-name">edit-clear-symbolic</property>
<property name="tooltip-text">Reset to Default Value</property>
<style>
<class name="flat" />
</style>
<property name="label">Choose Effects</property>
<property name="menu-model">close-effect-menu</property>
</object>
</child>
</object>
+14 -10
View File
@@ -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.
+14 -14
View File
@@ -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');
}
}
+14 -14
View File
@@ -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');
}
}
+14 -10
View File
@@ -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');
}
}