🔧 Show support dialog programmatically

This commit is contained in:
Simon Schneegans
2023-06-06 06:03:59 +02:00
parent 78d4e79925
commit 6cc26d0dbc
4 changed files with 117 additions and 190 deletions
+117 -62
View File
@@ -401,26 +401,35 @@ var PreferencesDialog = class PreferencesDialog {
const count = this._settings.get_int('prefs-open-count') + 1; const count = this._settings.get_int('prefs-open-count') + 1;
this._settings.set_int('prefs-open-count', count); this._settings.set_int('prefs-open-count', count);
if (count % 10 == 0) { // if (count % 10 == 0) {
const dialog = this._builder.get_object('support-dialog'); const dialog = this._createMessageDialog(
dialog.set_transient_for(window); 'Do you want to support Burn-My-Windows?',
dialog.connect('response', (dialog, response) => { `If only one out of ten users would support this project with 1$ / month, I could work full-time on open-source projects!
if ((utils.isADW() && response === 'never') ||
(!utils.isADW() && response === 2)) {
this._settings.set_boolean('show-support-dialog', false);
}
if (!utils.isADW()) { Ko-fi: <a href='https://ko-fi.com/schneegans'>https://ko-fi.com/schneegans</a>
dialog.close(); GitHub: <a href='https://github.com/sponsors/schneegans'>https://github.com/sponsors/schneegans</a>`,
window, [
{
label: 'Do not show this again!',
destructive: true,
default: false,
action: () => {
this._settings.set_boolean('show-support-dialog', false);
}
},
{
label: 'Maybe later...',
destructive: false,
default: true,
} }
}); ]);
if (utils.isGTK4()) { if (utils.isGTK4()) {
dialog.show(); dialog.show();
} else { } else {
dialog.show_all(); dialog.show_all();
}
} }
// }
} }
// Populate the menu with actions. // Populate the menu with actions.
@@ -621,56 +630,38 @@ var PreferencesDialog = class PreferencesDialog {
// This action shows a confirmation dialog. Upon user approval, the currently // This action shows a confirmation dialog. Upon user approval, the currently
// active profile is deleted. We use the more beautiful Adw.MessageDialog if it is // active profile is deleted. We use the more beautiful Adw.MessageDialog if it is
// available (usually on GNOME 43 and beyond). // available (usually on GNOME 43 and beyond).
let deleteProfileDialog; const deleteProfileDialog = this._createMessageDialog(
const dialogTitle = _('Delete this Profile?'); _('Delete this Profile?'),
const dialogSubtitle = _( _('The current effect profile with all its effect settings will be permanently lost.'),
'The current effect profile with all its effect settings will be permanently lost.'); window, [
{
label: _('Cancel'),
destructive: false,
default: true,
},
{
label: _('Delete'),
destructive: true,
default: false,
action: () => {
// Stop editing the current profile.
this._builder.get_object('edit-profile-button').active = false;
if (utils.isADW() && Adw.MessageDialog) { // Delete the currently active profile.
deleteProfileDialog = this._profileManager.deleteProfile(this._activeProfile.path);
new Adw.MessageDialog({heading: dialogTitle, body: dialogSubtitle});
deleteProfileDialog.add_response('cancel', _('Cancel'));
deleteProfileDialog.add_response('delete', _('Delete'));
deleteProfileDialog.set_response_appearance('delete',
Adw.ResponseAppearance.DESTRUCTIVE);
deleteProfileDialog.set_default_response('cancel');
deleteProfileDialog.set_close_response('cancel');
} else {
deleteProfileDialog = new Gtk.MessageDialog({
text: dialogTitle,
secondary_text: dialogSubtitle,
modal: true,
title: '',
buttons: Gtk.ButtonsType.OK_CANCEL
});
}
if (utils.isGTK4()) { // Select another one.
deleteProfileDialog.set_hide_on_close(true); this._settings.set_string('active-profile',
} this._profileManager.getProfiles()[0].path);
deleteProfileDialog.set_transient_for(window); // The number of profiles has changed, so we have to update the profile
// selection menu.
deleteProfileDialog.connect('response', (dialog, response) => { this._updateProfileMenu();
if (response == 'delete' || response == Gtk.ResponseType.OK) { }
// Stop editing the current profile. }
this._builder.get_object('edit-profile-button').active = false; ]);
// Delete the currently active profile.
this._profileManager.deleteProfile(this._activeProfile.path);
// Select another one.
this._settings.set_string('active-profile',
this._profileManager.getProfiles()[0].path);
// The number of profiles has changed, so we have to update the profile
// selection menu.
this._updateProfileMenu();
}
dialog.hide();
});
// This action deletes the currently active profile.
const deleteProfileAction = Gio.SimpleAction.new('profile-delete', null); const deleteProfileAction = Gio.SimpleAction.new('profile-delete', null);
deleteProfileAction.connect('activate', () => { deleteProfileAction.connect('activate', () => {
deleteProfileDialog.show(); deleteProfileDialog.show();
@@ -1003,6 +994,70 @@ var PreferencesDialog = class PreferencesDialog {
window.show_all(); window.show_all();
} }
} }
_createMessageDialog(title, message, window, buttons) {
let dialog;
if (utils.isADW() && Adw.MessageDialog) {
dialog = new Adw.MessageDialog({
heading: title,
body: message,
body_use_markup: true,
modal: true,
});
buttons.forEach((button, i) => {
const response = i.toString();
dialog.add_response(response, button.label);
if (button.default) {
dialog.set_default_response(response);
dialog.set_close_response(response);
}
if (button.destructive) {
dialog.set_response_appearance(response, Adw.ResponseAppearance.DESTRUCTIVE);
}
});
} else {
dialog = new Gtk.MessageDialog({
text: title,
secondary_text: message,
secondary_use_markup: true,
modal: true,
title: '',
});
buttons.forEach((button, i) => {
dialog.add_button(button.label, i);
if (button.default) {
dialog.set_default_response(i);
}
});
}
if (utils.isGTK4()) {
dialog.set_hide_on_close(true);
}
dialog.set_transient_for(window);
dialog.connect('response', (dialog, response) => {
const i = parseInt(response);
const button = buttons[i];
if (button && button.action) {
button.action();
}
dialog.hide();
});
return dialog;
}
} }
// This is used for setting up the translations. // This is used for setting up the translations.
-34
View File
@@ -37,40 +37,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
</style> </style>
</object> </object>
<!-- This dialog is occasionaly shown to ask the user for support. -->
<object class="AdwMessageDialog" id="support-dialog">
<property name="heading">Do you want to support Burn-My-Windows?</property>
<property name="body">If only one out of ten users would support this project with 1$ / month, I could work full-time on open-source projects!</property>
<property name="default-response">later</property>
<property name="close-response">later</property>
<responses>
<response id="never" appearance="destructive">Do not show this again!</response>
<response id="later">Maybe later...</response>
</responses>
<property name="extra-child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="use-markup">true</property>
<property name="label">Support me on Ko-fi: &lt;a href='https://ko-fi.com/schneegans'&gt;https://ko-fi.com/schneegans&lt;/a&gt;</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="use-markup">true</property>
<property name="label">Support me on GitHub: &lt;a href='https://github.com/sponsors/schneegans'&gt;https://github.com/sponsors/schneegans&lt;/a&gt;</property>
</object>
</child>
</object>
</property>
</object>
<object class="AdwFlap" id="profile-editor-flap"> <object class="AdwFlap" id="profile-editor-flap">
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="fold-threshold-policy">natural</property> <property name="fold-threshold-policy">natural</property>
-49
View File
@@ -67,55 +67,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
</style> </style>
</object> </object>
<!-- This dialog is occasionaly shown to ask the user for support. -->
<object class="GtkMessageDialog" id="support-dialog">
<property name="text">Do you want to support Burn-My-Windows?</property>
<property name="secondary-text">If only one out of ten users would support this project with 1$ / month, I could work full-time on open-source projects!</property>
<property name="modal">true</property>
<child internal-child="vbox">
<object class="GtkBox">
<child internal-child="message_area">
<object class="GtkBox">
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="use-markup">true</property>
<property name="label">Support me on Ko-fi: &lt;a href='https://ko-fi.com/schneegans'&gt;https://ko-fi.com/schneegans&lt;/a&gt;</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="use-markup">true</property>
<property name="label">Support me on GitHub: &lt;a href='https://github.com/sponsors/schneegans'&gt;https://github.com/sponsors/schneegans&lt;/a&gt;</property>
</object>
</child>
</object>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox">
<child>
<object class="GtkButton" id="support_never_button">
<property name="label">Do not show this again!</property>
</object>
</child>
<child>
<object class="GtkButton" id="support_later_button">
<property name="label">Maybe later...</property>
</object>
</child>
</object>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1" default="true">support_later_button</action-widget>
<action-widget response="2">support_never_button</action-widget>
</action-widgets>
</object>
<object class="GtkStack" id="general-prefs"> <object class="GtkStack" id="general-prefs">
<property name="transition-type">over-down-up</property> <property name="transition-type">over-down-up</property>
-45
View File
@@ -33,51 +33,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
</style> </style>
</object> </object>
<!-- This dialog is occasionaly shown to ask the user for support. -->
<object class="GtkMessageDialog" id="support-dialog">
<property name="text">Do you want to support Burn-My-Windows?</property>
<property name="secondary-text">If only one out of ten users would support this project with 1$ / month, I could work full-time on open-source projects!</property>
<property name="modal">true</property>
<child internal-child="message_area">
<object class="GtkBox">
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="use-markup">true</property>
<property name="label">Support me on Ko-fi: &lt;a href='https://ko-fi.com/schneegans'&gt;https://ko-fi.com/schneegans&lt;/a&gt;</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="hexpand">true</property>
<property name="halign">start</property>
<property name="use-markup">true</property>
<property name="label">Support me on GitHub: &lt;a href='https://github.com/sponsors/schneegans'&gt;https://github.com/sponsors/schneegans&lt;/a&gt;</property>
</object>
</child>
</object>
</child>
<child internal-child="action_area">
<object class="GtkBox">
<child>
<object class="GtkButton" id="support_never_button">
<property name="label">Do not show this again!</property>
</object>
</child>
<child>
<object class="GtkButton" id="support_later_button">
<property name="label">Maybe later...</property>
</object>
</child>
</object>
</child>
<action-widgets>
<action-widget response="1" default="true">support_later_button</action-widget>
<action-widget response="2">support_never_button</action-widget>
</action-widgets>
</object>
<object class="GtkStack" id="general-prefs"> <object class="GtkStack" id="general-prefs">
<property name="transition-type">over-down-up</property> <property name="transition-type">over-down-up</property>