[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47531] branches/soc-2012-bratwurst: Preferences are saved independently from the default startup project.

Jorge Rodriguez bs.vino at gmail.com
Wed Jun 6 20:16:54 CEST 2012


Revision: 47531
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47531
Author:   vino
Date:     2012-06-06 18:16:53 +0000 (Wed, 06 Jun 2012)
Log Message:
-----------
Preferences are saved independently from the default startup project. The preferences file omits most other data blocks and saves only user preferences. It's loaded before the startup blend is loaded, and the preferences information in the startup blend isn't loaded. "Save to defaults" in the preferences screen saves to the preferences blend instead of the default blend. Saving the homefile was renamed from "Save User Settings" to "Save Start-Up Project" for clarity.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_userpref.py
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c
    branches/soc-2012-bratwurst/source/blender/blenlib/BLI_path_util.h
    branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c
    branches/soc-2012-bratwurst/source/blender/windowmanager/WM_api.h
    branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_files.c
    branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_init_exit.c
    branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_userpref.py	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_userpref.py	2012-06-06 18:16:53 UTC (rev 47531)
@@ -84,7 +84,7 @@
         userpref = context.user_preferences
 
         layout.operator_context = 'EXEC_AREA'
-        layout.operator("wm.save_homefile", text="Save As Default")
+        layout.operator("wm.save_preferences", text="Save As Default")
 
         layout.operator_context = 'INVOKE_DEFAULT'
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_global.h	2012-06-06 18:16:53 UTC (rev 47531)
@@ -154,6 +154,8 @@
 #define G_FILE_RELATIVE_REMAP    (1 << 24)
 #define G_FILE_HISTORY           (1 << 25)
 #define G_FILE_MESH_COMPAT       (1 << 26)              /* BMesh option to save as older mesh format */
+#define G_FILE_PREFERENCES       (1 << 27)
+#define G_FILE_NO_DATA		     (1 << 28)
 
 /* G.windowstate */
 #define G_WINDOWSTATE_USERDEF       0

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/blender.c	2012-06-06 18:16:53 UTC (rev 47531)
@@ -251,11 +251,13 @@
 	sound_init_main(G.main);
 	
 	if (bfd->user) {
-		
-		/* only here free userdef themes... */
-		BKE_userdef_free();
-		
-		U = *bfd->user;
+		if (G.fileflags&G_FILE_PREFERENCES)
+		{
+			/* only here free userdef themes... */
+			BKE_userdef_free();
+			U = *bfd->user;
+		}
+
 		MEM_freeN(bfd->user);
 	}
 	
@@ -277,7 +279,7 @@
 	}
 	
 	/* this can happen when active scene was lib-linked, and doesn't exist anymore */
-	if (CTX_data_scene(C) == NULL) {
+	if (CTX_data_scene(C) == NULL && CTX_wm_screen(C) && bfd->main->scene.first) {
 		CTX_data_scene_set(C, bfd->main->scene.first);
 		CTX_wm_screen(C)->scene = CTX_data_scene(C);
 		curscene = CTX_data_scene(C);
@@ -323,7 +325,8 @@
 		BLI_strncpy(G.main->name, filepath, FILE_MAX);
 
 	/* baseflags, groups, make depsgraph, etc */
-	BKE_scene_set_background(G.main, CTX_data_scene(C));
+	if (CTX_data_scene(C))
+		BKE_scene_set_background(G.main, CTX_data_scene(C));
 	
 	MEM_freeN(bfd);
 
@@ -390,7 +393,7 @@
 	BlendFileData *bfd;
 	int retval = BKE_READ_FILE_OK;
 
-	if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) /* don't print user-pref loading */
+	if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL && strstr(filepath, BLENDER_PREFERENCES_FILE) == NULL) /* don't print user-pref loading */
 		printf("read blend: %s\n", filepath);
 
 	bfd = BLO_read_from_file(filepath, reports);

Modified: branches/soc-2012-bratwurst/source/blender/blenlib/BLI_path_util.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenlib/BLI_path_util.h	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/source/blender/blenlib/BLI_path_util.h	2012-06-06 18:16:53 UTC (rev 47531)
@@ -67,6 +67,7 @@
 #define BLENDER_RESOURCE_PATH_SYSTEM    2
 
 #define BLENDER_STARTUP_FILE    "startup.blend"
+#define BLENDER_PREFERENCES_FILE "preferences.blend"
 #define BLENDER_BOOKMARK_FILE   "bookmarks.txt"
 #define BLENDER_HISTORY_FILE    "recent-files.txt"
 

Modified: branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/source/blender/blenloader/intern/writefile.c	2012-06-06 18:16:53 UTC (rev 47531)
@@ -2862,7 +2862,7 @@
 
 /* if MemFile * there's filesave to memory */
 static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFile *current, 
-                             int write_user_block, int write_flags, const int *thumb)
+                             int write_flags, const int *thumb)
 {
 	BHead bhead;
 	ListBase mainlist;
@@ -2884,41 +2884,44 @@
 	write_thumb(wd, thumb);
 	write_global(wd, write_flags, mainvar);
 
-	/* no UI save in undo */
-	if (current==NULL) {
-		write_windowmanagers(wd, &mainvar->wm);
-		write_screens  (wd, &mainvar->screen);
+	if (!(write_flags & G_FILE_NO_DATA))
+	{
+		/* no UI save in undo */
+		if (current==NULL) {
+			write_windowmanagers(wd, &mainvar->wm);
+			write_screens  (wd, &mainvar->screen);
+		}
+		write_movieclips (wd, &mainvar->movieclip);
+		write_masks    (wd, &mainvar->mask);
+		write_scenes   (wd, &mainvar->scene);
+		write_curves   (wd, &mainvar->curve);
+		write_mballs   (wd, &mainvar->mball);
+		write_images   (wd, &mainvar->image);
+		write_cameras  (wd, &mainvar->camera);
+		write_lamps    (wd, &mainvar->lamp);
+		write_lattices (wd, &mainvar->latt);
+		write_vfonts   (wd, &mainvar->vfont);
+		write_keys     (wd, &mainvar->key);
+		write_worlds   (wd, &mainvar->world);
+		write_texts    (wd, &mainvar->text);
+		write_speakers (wd, &mainvar->speaker);
+		write_sounds   (wd, &mainvar->sound);
+		write_groups   (wd, &mainvar->group);
+		write_armatures(wd, &mainvar->armature);
+		write_actions  (wd, &mainvar->action);
+		write_objects  (wd, &mainvar->object);
+		write_materials(wd, &mainvar->mat);
+		write_textures (wd, &mainvar->tex);
+		write_meshs    (wd, &mainvar->mesh);
+		write_particlesettings(wd, &mainvar->particle);
+		write_nodetrees(wd, &mainvar->nodetree);
+		write_brushes  (wd, &mainvar->brush);
+		write_scripts  (wd, &mainvar->script);
+		write_gpencils (wd, &mainvar->gpencil);
+		write_libraries(wd,  mainvar->next);
 	}
-	write_movieclips (wd, &mainvar->movieclip);
-	write_masks    (wd, &mainvar->mask);
-	write_scenes   (wd, &mainvar->scene);
-	write_curves   (wd, &mainvar->curve);
-	write_mballs   (wd, &mainvar->mball);
-	write_images   (wd, &mainvar->image);
-	write_cameras  (wd, &mainvar->camera);
-	write_lamps    (wd, &mainvar->lamp);
-	write_lattices (wd, &mainvar->latt);
-	write_vfonts   (wd, &mainvar->vfont);
-	write_keys     (wd, &mainvar->key);
-	write_worlds   (wd, &mainvar->world);
-	write_texts    (wd, &mainvar->text);
-	write_speakers (wd, &mainvar->speaker);
-	write_sounds   (wd, &mainvar->sound);
-	write_groups   (wd, &mainvar->group);
-	write_armatures(wd, &mainvar->armature);
-	write_actions  (wd, &mainvar->action);
-	write_objects  (wd, &mainvar->object);
-	write_materials(wd, &mainvar->mat);
-	write_textures (wd, &mainvar->tex);
-	write_meshs    (wd, &mainvar->mesh);
-	write_particlesettings(wd, &mainvar->particle);
-	write_nodetrees(wd, &mainvar->nodetree);
-	write_brushes  (wd, &mainvar->brush);
-	write_scripts  (wd, &mainvar->script);
-	write_gpencils (wd, &mainvar->gpencil);
-	write_libraries(wd,  mainvar->next);
 
-	if (write_user_block) {
+	if (write_flags & G_FILE_PREFERENCES) {
 		write_userdef(wd);
 	}
 							
@@ -2973,9 +2976,8 @@
 /* return: success (1) */
 int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const int *thumb)
 {
-	char userfilename[FILE_MAX];
 	char tempname[FILE_MAX+1];
-	int file, err, write_user_block;
+	int file, err;
 
 	/* open temporary file, so we preserve the original in case we crash */
 	BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
@@ -3011,14 +3013,11 @@
 		}
 	}
 
-	BLI_make_file_string(G.main->name, userfilename, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
-	write_user_block= (BLI_path_cmp(filepath, userfilename) == 0);
-
 	if (write_flags & G_FILE_RELATIVE_REMAP)
 		BLI_bpath_relative_convert(mainvar, filepath, NULL); /* note, making relative to something OTHER then G.main->name */
 
 	/* actual file writing */
-	err= write_file_handle(mainvar, file, NULL, NULL, write_user_block, write_flags, thumb);
+	err= write_file_handle(mainvar, file, NULL, NULL, write_flags, thumb);
 	close(file);
 
 	if (err) {
@@ -3078,7 +3077,7 @@
 {
 	int err;
 
-	err= write_file_handle(mainvar, 0, compare, current, 0, write_flags, NULL);
+	err= write_file_handle(mainvar, 0, compare, current, write_flags, NULL);
 	
 	if (err==0) return 1;
 	return 0;

Modified: branches/soc-2012-bratwurst/source/blender/windowmanager/WM_api.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/windowmanager/WM_api.h	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/source/blender/windowmanager/WM_api.h	2012-06-06 18:16:53 UTC (rev 47531)
@@ -92,6 +92,8 @@
 
 
 			/* files */
+int			WM_read_preferences	(struct bContext *C);
+int			WM_write_preferences(struct bContext *C, struct wmOperator *op);
 int			WM_read_homefile_exec(struct bContext *C, struct wmOperator *op);
 int			WM_read_homefile	(struct bContext *C, struct ReportList *reports, short from_memory);
 int			WM_write_homefile	(struct bContext *C, struct wmOperator *op);

Modified: branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_files.c	2012-06-06 18:11:12 UTC (rev 47530)
+++ branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_files.c	2012-06-06 18:16:53 UTC (rev 47531)
@@ -478,7 +478,43 @@
 
 }
 
+int WM_read_preferences(bContext *C)
+{
+	ListBase wmbase;
+	char tstr[FILE_MAX];
+	int success = 0;
+	char *cfgdir;
+	
+	G.relbase_valid = 0;
 
+	cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
+	if (cfgdir) {
+		BLI_make_file_string(G.main->name, tstr, cfgdir, BLENDER_PREFERENCES_FILE);
+	}
+
+	/* prevent loading no UI */
+	G.fileflags |= (G_FILE_NO_UI|G_FILE_NO_DATA|G_FILE_PREFERENCES);
+
+	/* put aside screens to match with persistent windows later */
+	wm_window_match_init(C, &wmbase); 
+
+	if (BLI_exists(tstr)) {
+		success = (BKE_read_file(C, tstr, NULL) != BKE_READ_FILE_FAIL);
+		
+		if (U.themes.first == NULL) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list