UI: alternate fix for T65702, handling of auto-saving userprefs
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jun 2019 02:21:21 +0000 (12:21 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jun 2019 02:30:49 +0000 (12:30 +1000)
The behavior for loading factory settings wasn't clear for users.

This commit changes the behavior:

- Loading factory settings always disables auto-save
  for the current session.
- The internal setting to skip saving on exit is now exposed
  in the preferences (when enabled).
- The menu item "Load Factory Settings (Temporary)" has been removed
  since it's always temporary.

This way users can always reset factory settings without
having to consider the combination of options that might cause their
preferences to be overwritten at exit.

If they want to enable auto-save for the current session
this can be done from the preferences.

release/scripts/startup/bl_ui/space_topbar.py
release/scripts/startup/bl_ui/space_userpref.py
source/blender/python/intern/bpy_app.c
source/blender/windowmanager/intern/wm_files.c

index d99df2e..35c4a5e 100644 (file)
@@ -334,15 +334,6 @@ class TOPBAR_MT_file_defaults(Menu):
         if app_template:
             props.app_template = app_template
 
-        if prefs.use_preferences_save:
-            props = layout.operator(
-                "wm.read_factory_settings",
-                text="Load Factory Settings (Temporary)"
-            )
-            if app_template:
-                props.app_template = app_template
-            props.use_temporary_preferences = True
-
 
 class TOPBAR_MT_app_about(Menu):
     bl_label = "About"
index 79f7cdf..8da5237 100644 (file)
@@ -40,10 +40,21 @@ class USERPREF_HT_header(Header):
 
         row = layout.row()
         row.menu("USERPREF_MT_save_load", text="", icon='COLLAPSEMENU')
-        if not prefs.use_preferences_save:
-            sub_revert = row.row(align=True)
-            sub_revert.active = prefs.is_dirty
-            sub_revert.operator("wm.save_userpref")
+        if prefs.use_preferences_save:
+            if bpy.app.use_userpref_skip_save_on_exit:
+                # We should have an 'alert' icon, for now use 'error'.
+                sub = row.row(align=True)
+                props = sub.operator(
+                    "wm.context_toggle",
+                    text="Skip Auto-Save",
+                    icon='CHECKBOX_HLT',
+                )
+                props.module = "bpy.app"
+                props.data_path = "use_userpref_skip_save_on_exit"
+        else:
+            sub = row.row(align=True)
+            sub.active = prefs.is_dirty
+            sub.operator("wm.save_userpref")
 
     def draw(self, context):
         layout = self.layout
index f0a3c7f..9ffb4cb 100644 (file)
@@ -508,6 +508,12 @@ static PyGetSetDef bpy_app_getsets[] = {
      (char *)bpy_app_global_flag_doc,
      (void *)G_FLAG_EVENT_SIMULATE},
 
+    {(char *)"use_userpref_skip_save_on_exit",
+     bpy_app_global_flag_get,
+     bpy_app_global_flag_set,
+     (char *)bpy_app_global_flag_doc,
+     (void *)G_FLAG_USERPREF_NO_SAVE_ON_EXIT},
+
     {(char *)"binary_path_python",
      bpy_app_binary_path_python_get,
      NULL,
index 3a1c164..1feab31 100644 (file)
@@ -1742,9 +1742,7 @@ void WM_OT_save_userpref(wmOperatorType *ot)
 /**
  * When reading preferences, there are some exceptions for values which are reset.
  */
-static void wm_userpref_read_exceptions(UserDef *userdef_curr,
-                                        const UserDef *userdef_prev,
-                                        const bool use_factory_settings)
+static void wm_userpref_read_exceptions(UserDef *userdef_curr, const UserDef *userdef_prev)
 {
 #define USERDEF_RESTORE(member) \
   { \
@@ -1755,13 +1753,6 @@ static void wm_userpref_read_exceptions(UserDef *userdef_curr,
   /* Current visible preferences category. */
   USERDEF_RESTORE(userpref);
 
-  if (use_factory_settings) {
-    /* Preferences about the preferences.
-     * Technically correct not to reset however this causes issues in practice.
-     * Since loading factory settings will then overwrite your preferences on exit, see: T65702. */
-    USERDEF_RESTORE(pref_flag);
-  }
-
 #undef USERDEF_RESTORE
 }
 
@@ -1837,7 +1828,10 @@ static int wm_userpref_read_exec(bContext *C, wmOperator *op)
                    WM_init_state_app_template_get(),
                    NULL);
 
-  wm_userpref_read_exceptions(&U, &U_backup, use_factory_settings);
+  wm_userpref_read_exceptions(&U, &U_backup);
+  if (use_factory_settings) {
+    G.f |= G_FLAG_USERPREF_NO_SAVE_ON_EXIT;
+  }
 
   Main *bmain = CTX_data_main(C);
 
@@ -1933,7 +1927,6 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
   PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");
   const bool use_splash = !use_factory_settings && RNA_boolean_get(op->ptr, "use_splash");
   const bool use_empty_data = RNA_boolean_get(op->ptr, "use_empty");
-  const bool use_temporary_preferences = RNA_boolean_get(op->ptr, "use_temporary_preferences");
 
   if (prop_app_template && RNA_property_is_set(op->ptr, prop_app_template)) {
     RNA_property_string_get(op->ptr, prop_app_template, app_template_buf);
@@ -1964,10 +1957,12 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
   if (use_splash) {
     WM_init_splash(C);
   }
-  SET_FLAG_FROM_TEST(G.f, use_temporary_preferences, G_FLAG_USERPREF_NO_SAVE_ON_EXIT);
 
   if (use_userdef) {
-    wm_userpref_read_exceptions(&U, &U_backup, use_factory_settings);
+    wm_userpref_read_exceptions(&U, &U_backup);
+    if (use_factory_settings) {
+      G.f |= G_FLAG_USERPREF_NO_SAVE_ON_EXIT;
+    }
   }
 
   return OPERATOR_FINISHED;
@@ -2009,13 +2004,6 @@ static void read_homefile_props(wmOperatorType *ot)
 
   prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
   RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
-
-  prop = RNA_def_boolean(ot->srna,
-                         "use_temporary_preferences",
-                         false,
-                         "Temporary Preferences",
-                         "Don't save preferences on exit");
-  RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 }
 
 void WM_OT_read_homefile(wmOperatorType *ot)