[Bf-blender-cvs] [741f29d499e] master: Preferences: auto-save on exit

Campbell Barton noreply at git.blender.org
Mon May 13 08:29:53 CEST 2019


Commit: 741f29d499eaaa5c10be218a632f9b6fab67840e
Author: Campbell Barton
Date:   Mon May 13 15:59:27 2019 +1000
Branches: master
https://developer.blender.org/rB741f29d499eaaa5c10be218a632f9b6fab67840e

Preferences: auto-save on exit

Save modified preferences on exit by default,
with the option to disable this.

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/intern/wm_init_exit.c

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index ca82c5fb264..0033ae18264 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -30,18 +30,28 @@ from bpy.app.translations import contexts as i18n_contexts
 class USERPREF_HT_header(Header):
     bl_space_type = 'PREFERENCES'
 
-    def draw(self, _context):
+    @staticmethod
+    def draw_buttons(layout, context, *, is_vertical=False):
+        if is_vertical:
+            sub = layout.column(align=True)
+        else:
+            sub = layout.row(align=True)
+
+        sub.operator("wm.save_userpref")
+        sub.operator("wm.read_userpref")
+        sub.operator("wm.read_factory_userpref")
+
+        prefs = context.preferences
+        layout.prop(prefs, "use_preferences_save")
+
+    def draw(self, context):
         layout = self.layout
         layout.operator_context = 'EXEC_AREA'
 
         layout.template_header()
 
         layout.separator_spacer()
-
-        row = layout.row(align=True)
-        row.operator("wm.save_userpref")
-        row.operator("wm.read_userpref")
-        row.operator("wm.read_factory_userpref")
+        self.draw_buttons(layout, context)
 
 
 class USERPREF_PT_navigation_bar(Panel):
@@ -77,17 +87,14 @@ class USERPREF_PT_save_preferences(Panel):
 
         return False
 
-    def draw(self, _context):
+    def draw(self, context):
         layout = self.layout
         layout.operator_context = 'EXEC_AREA'
 
         layout.scale_x = 1.3
         layout.scale_y = 1.3
 
-        col = layout.column(align=True)
-        col.operator("wm.save_userpref")
-        col.operator("wm.read_userpref")
-        col.operator("wm.read_factory_userpref")
+        USERPREF_HT_header.draw_buttons(layout, context, is_vertical=True)
 
 
 # Panel mix-in.
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index b03686ca241..16275c96eec 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -27,7 +27,7 @@
  * \note Use #STRINGIFY() rather than defining with quotes.
  */
 #define BLENDER_VERSION 280
-#define BLENDER_SUBVERSION 61
+#define BLENDER_SUBVERSION 62
 /** Several breakages with 280, e.g. collections vs layers. */
 #define BLENDER_MINVERSION 280
 #define BLENDER_MINSUBVERSION 0
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index 6ac0e8f2c74..24eac507945 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -43,7 +43,7 @@
 /* Disallow access to global userdef. */
 #define U (_error_)
 
-static void do_versions_theme(UserDef *userdef, bTheme *btheme)
+static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
 {
 
 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver)
@@ -580,10 +580,7 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
     }
   }
 
-  /**
-   * Include next version bump.
-   */
-  {
+  if (!USER_VERSION_ATLEAST(280, 62)) {
     /* (keep this block even if it becomes empty). */
     if (userdef->vbotimeout == 0) {
       userdef->vbocollectrate = 60;
@@ -593,6 +590,15 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
     if (userdef->lookdev_sphere_size == 0) {
       userdef->lookdev_sphere_size = 150;
     }
+
+    userdef->pref_flag |= USER_PREF_FLAG_SAVE;
+  }
+
+  /**
+   * Include next version bump.
+   */
+  {
+    /* pass */
   }
 
   if (userdef->pixelsize == 0.0f) {
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 3d0bdee0cab..d42263660d2 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -549,8 +549,12 @@ typedef struct UserDef {
   /** #eUserPref_Flag. */
   int flag;
   /** #eDupli_ID_Flags. */
-  int dupflag;
-  int savetime;
+  short dupflag;
+  /**
+   * #eUserPref_PrefFlag preferences for the preferences. */
+  char pref_flag;
+  char savetime;
+  char _pad4[4];
   /** FILE_MAXDIR length. */
   char tempdir[768];
   char fontdir[768];
@@ -844,6 +848,10 @@ typedef enum eUserPref_Flag {
   USER_TOOLTIPS_PYTHON = (1 << 26),
 } eUserPref_Flag;
 
+typedef enum eUserPref_PrefFlag {
+  USER_PREF_FLAG_SAVE = (1 << 0),
+} eUserPref_PrefFlag;
+
 /** #bPathCompare.flag */
 typedef enum ePathCompare_Flag {
   USER_PATHCMP_GLOB = (1 << 0),
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 8e33100714e..3cfb1bbc2c7 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -5687,6 +5687,11 @@ void RNA_def_userdef(BlenderRNA *brna)
                                     NULL);
   RNA_def_property_ui_text(prop, "Studio Lights", "");
 
+  /* Preferences Flags */
+  prop = RNA_def_property(srna, "use_preferences_save", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "pref_flag", USER_PREF_FLAG_SAVE);
+  RNA_def_property_ui_text(prop, "Save on Exit", "Save modified preferences on exit");
+
   rna_def_userdef_view(brna);
   rna_def_userdef_edit(brna);
   rna_def_userdef_input(brna);
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 0112faf6b2c..9abfa657536 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -475,12 +475,11 @@ void WM_exit_ext(bContext *C, const bool do_python)
       ED_screen_exit(C, win, WM_window_get_active_screen(win));
     }
 
-    /* Disable until we have a revert button. */
-#if 0
     if (U.runtime.is_dirty) {
-      BKE_blendfile_userdef_write_all(NULL);
+      if (U.pref_flag & USER_PREF_FLAG_SAVE) {
+        BKE_blendfile_userdef_write_all(NULL);
+      }
     }
-#endif
   }
 
   BLI_timer_free();



More information about the Bf-blender-cvs mailing list