From 3127f4a8981184e90946f12bdff6c105b4c8107a Mon Sep 17 00:00:00 2001 From: kramo <93832451+kra-mo@users.noreply.github.com> Date: Mon, 15 May 2023 18:17:49 +0200 Subject: [PATCH] Handle the user flipping a switch back --- src/preferences.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/preferences.py b/src/preferences.py index 21d0b14..dff11bd 100644 --- a/src/preferences.py +++ b/src/preferences.py @@ -76,7 +76,11 @@ class PreferencesWindow(Adw.PreferencesWindow): sgdb_animated_switch = Gtk.Template.Child() removed_games = set() + + # Whether to import after closing the window import_changed = False + # Widgets and their properties to check whether to import after closing the window + import_changed_widgets = {} def __init__(self, win, **kwargs): super().__init__(**kwargs) @@ -300,9 +304,21 @@ class PreferencesWindow(Adw.PreferencesWindow): ) def set_import_changed(self, widget, param): - if widget.get_property(param.name): + if widget not in self.import_changed_widgets: self.import_changed = True + self.import_changed_widgets[widget] = ( + param.name, + not widget.get_property(param.name), + ) def check_import(self, *_args): if self.import_changed: - self.win.get_application().on_import_action() + # This checks whether any of the switches that did actually change their state + # would have an effect on the outcome of the import action + # and if they would, it initiates it. + + if any( + (value := widget.get_property(prop[0])) and value != prop[1] + for widget, prop in self.import_changed_widgets.items() + ): + self.win.get_application().on_import_action()