From 81de41dac1b1ff534db715395addd8d4c7f0625a Mon Sep 17 00:00:00 2001 From: Emanuele Petriglia Date: Sun, 22 Sep 2019 10:44:41 +0200 Subject: [PATCH 1/2] Add a confirmation dialog before applying a config --- xfce4-panel-profiles/xfce4-panel-profiles.py | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/xfce4-panel-profiles/xfce4-panel-profiles.py b/xfce4-panel-profiles/xfce4-panel-profiles.py index c3a7ca8..34b7bc5 100644 --- a/xfce4-panel-profiles/xfce4-panel-profiles.py +++ b/xfce4-panel-profiles/xfce4-panel-profiles.py @@ -264,7 +264,11 @@ class XfcePanelProfiles: def on_apply_clicked(self, widget): filename = self.get_selected_filename() - self.load_configuration(filename) + + dialog = PanelConfirmDialog(self.window) + if dialog.run() == Gtk.ResponseType.ACCEPT: + self.load_configuration(filename) + dialog.destroy() def delete_configuration(self, filename): if os.path.isfile(filename): @@ -337,6 +341,28 @@ class PanelSaveDialog(Gtk.MessageDialog): def set_save_name(self, name): self.entry.set_text(name.strip()) + +class PanelConfirmDialog(Gtk.MessageDialog): + '''Ask to the user if he wants to apply a configuration, because the current + configuration will be lost.''' + + def __init__(self, parent=None): + message = _("Do you want to apply this configuration?\n" + " The current configuration will be lost!") + + Gtk.MessageDialog.__init__( + self, transient_for=parent, modal=True, + message_type=Gtk.MessageType.QUESTION, + text=message) + + self.add_buttons( + _("Cancel"), Gtk.ResponseType.CANCEL, + _("Apply Configuration"), Gtk.ResponseType.ACCEPT + ) + + self.set_default_icon_name("dialog-information") + self.set_default_response(Gtk.ResponseType.ACCEPT) + if __name__ == "__main__": import sys -- 2.21.0 From 44a03f823f0e4ae18321591f7c7d796771e74d5f Mon Sep 17 00:00:00 2001 From: Emanuele Petriglia Date: Sun, 22 Sep 2019 11:17:34 +0200 Subject: [PATCH 2/2] Add option to create a backup before applying --- xfce4-panel-profiles/xfce4-panel-profiles.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xfce4-panel-profiles/xfce4-panel-profiles.py b/xfce4-panel-profiles/xfce4-panel-profiles.py index 34b7bc5..9f0e900 100644 --- a/xfce4-panel-profiles/xfce4-panel-profiles.py +++ b/xfce4-panel-profiles/xfce4-panel-profiles.py @@ -267,6 +267,9 @@ class XfcePanelProfiles: dialog = PanelConfirmDialog(self.window) if dialog.run() == Gtk.ResponseType.ACCEPT: + if dialog.backup.get_active(): + self.on_save_clicked(dialog) + self.load_configuration(filename) dialog.destroy() @@ -363,6 +366,13 @@ class PanelConfirmDialog(Gtk.MessageDialog): self.set_default_icon_name("dialog-information") self.set_default_response(Gtk.ResponseType.ACCEPT) + self.backup = Gtk.CheckButton.new() + self.backup.set_label(_("Make a backup of the current configuration")) + + box = self.get_message_area() + box.pack_start(self.backup, True, True, 0) + box.show_all() + if __name__ == "__main__": import sys -- 2.21.0