Repository: napari/napari

Issue:
Cancel doesn't work on preference dialog
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->
The cancel button on the preferences dialog isn't working properly.  I think its possible that the function I removed in the last PR that I thought was unnecessary was actually necessary. 
## To Reproduce

Steps to reproduce the behavior:

1.
2.
3.

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

## Environment

 - Please copy and paste the information at napari info option in help menubar here:

 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->



Discussion:
No worries, fixing in a followup sounds good. thanks for making the issue
I just found the problem.  It wasn't the function that I thought.  I will get it done this weekend!

Resolving patch:
diff --git a/napari/_qt/dialogs/preferences_dialog.py b/napari/_qt/dialogs/preferences_dialog.py
--- a/napari/_qt/dialogs/preferences_dialog.py
+++ b/napari/_qt/dialogs/preferences_dialog.py
@@ -72,8 +72,10 @@ def make_dialog(self):
 
         settings_list = [ApplicationSettings(), PluginSettings()]
         cnt = 0
+        # Because there are multiple pages, need to keep a list of values sets.
+        self._values_orig_set_list = []
+        self._values_set_list = []
         for key, setting in SETTINGS.schemas().items():
-
             schema = json.loads(setting['json_schema'])
             # need to remove certain properties that will not be displayed on the GUI
             properties = schema.pop('properties')
@@ -84,7 +86,8 @@ def make_dialog(self):
 
             cnt += 1
             schema['properties'] = properties
-
+            self._values_orig_set_list.append(set(values.items()))
+            self._values_set_list.append(set(values.items()))
             self.add_page(schema, values)
 
     def restore_defaults(self):
@@ -116,7 +119,16 @@ def on_click_ok(self):
 
     def on_click_cancel(self):
         """Restores the settings in place when dialog was launched."""
-        self.check_differences(self._values_orig_set, self._values_set)
+        # Need to check differences for each page.
+        for n in range(self._stack.count()):
+            # Must set the current row so that the proper set list is updated
+            # in check differences.
+            self._list.setCurrentRow(n)
+            self.check_differences(
+                self._values_orig_set_list[n],
+                self._values_set_list[n],
+            )
+        self._list.setCurrentRow(0)
         self.close()
 
     def add_page(self, schema, values):
@@ -145,15 +157,16 @@ def build_page_dialog(self, schema, values):
         values : dict
             Dictionary of current values set in preferences.
         """
-        self._values_orig_set = set(values.items())
-        self._values_set = set(values.items())
 
         builder = WidgetBuilder()
         form = builder.create_form(schema, {})
         # set state values for widget
         form.widget.state = values
         form.widget.on_changed.connect(
-            lambda d: self.check_differences(set(d.items()), self._values_set)
+            lambda d: self.check_differences(
+                set(d.items()),
+                self._values_set_list[self._list.currentIndex().row()],
+            )
         )
 
         return form
@@ -178,7 +191,9 @@ def check_differences(self, new_set, values_set):
             for val in different_values:
                 try:
                     setattr(SETTINGS._settings[page], val[0], val[1])
-                    self._values_set = new_set
+                    self._values_set_list[
+                        self._list.currentIndex().row()
+                    ] = new_set
                 except:  # noqa: E722
                     continue
 


Test patch: