[Bf-blender-cvs] [fcb534e336c] master: UI: alternate fix for T65702, handling of auto-saving userprefs

Campbell Barton noreply at git.blender.org
Wed Jun 12 04:32:59 CEST 2019


Commit: fcb534e336c3b9d9065c5bbc9143bcc305497975
Author: Campbell Barton
Date:   Wed Jun 12 12:21:21 2019 +1000
Branches: master
https://developer.blender.org/rBfcb534e336c3b9d9065c5bbc9143bcc305497975

UI: alternate fix for T65702, handling of auto-saving userprefs

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.

===================================================================

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

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index d99df2eced7..35c4a5ec5a1 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -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"
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 79f7cdf6d5a..8da5237b7f9 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -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
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index f0a3c7f4d5f..9ffb4cb4821 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -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,
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 3a1c164c88e..1feab316010 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -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)



More information about the Bf-blender-cvs mailing list