[Bf-blender-cvs] [52e09ed] master: Cleanup: move operators & related code of files & append/link to relevant dedicated source files.

Bastien Montagne noreply at git.blender.org
Tue Apr 19 22:53:58 CEST 2016


Commit: 52e09ed4f93b21aee8643de2f8b53e9fa7c99543
Author: Bastien Montagne
Date:   Tue Apr 19 17:08:31 2016 +0200
Branches: master
https://developer.blender.org/rB52e09ed4f93b21aee8643de2f8b53e9fa7c99543

Cleanup: move operators & related code of files & append/link to relevant dedicated source files.

This commit adds a new `wm_files_link.c` which contains everything related to append/link code,
moved from `wm_operators.c` (rather small currently, but will expand quite a bit with future reload & asset works).

It also moves all load/save .bland files (and related userpref/startup stuff) from `wm_operators.c`
to `wm_files.c` (some helper funcs were already there).

This also makes `wm_operators.c` significantly lighter.

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

M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/intern/wm_files.c
A	source/blender/windowmanager/intern/wm_files_link.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/wm_files.h

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

diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index af8a7cc..01188cb 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -58,6 +58,7 @@ set(SRC
 	intern/wm_draw.c
 	intern/wm_event_system.c
 	intern/wm_files.c
+	intern/wm_files_link.c
 	intern/wm_gesture.c
 	intern/wm_init_exit.c
 	intern/wm_jobs.c
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index ce722c7..498a3f5 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -26,7 +26,7 @@
 /** \file blender/windowmanager/intern/wm_files.c
  *  \ingroup wm
  *
- * User level access for blend file read/write, file-history and userprefs.
+ * User level access for blend file read/write, file-history and userprefs (including relevant operators).
  */
 
 
@@ -62,6 +62,7 @@
 
 #include "BLT_translation.h"
 
+#include "DNA_mesh_types.h" /* only for USE_BMESH_SAVE_AS_COMPAT */
 #include "DNA_object_types.h"
 #include "DNA_space_types.h"
 #include "DNA_userdef_types.h"
@@ -88,6 +89,7 @@
 #include "BLO_writefile.h"
 
 #include "RNA_access.h"
+#include "RNA_define.h"
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
@@ -103,6 +105,7 @@
 #include "GHOST_Path-api.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 #include "UI_view2d.h"
 
 #include "GPU_draw.h"
@@ -749,44 +752,6 @@ int wm_homefile_read(bContext *C, ReportList *reports, bool from_memory, const c
 	return true;
 }
 
-int wm_history_file_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
-{
-	ED_file_read_bookmarks();
-	wm_history_file_read();
-	return OPERATOR_FINISHED;
-}
-
-int wm_homefile_read_exec(bContext *C, wmOperator *op)
-{
-	const bool from_memory = (STREQ(op->type->idname, "WM_OT_read_factory_settings"));
-	char filepath_buf[FILE_MAX];
-	const char *filepath = NULL;
-
-	if (!from_memory) {
-		PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");
-
-		/* This can be used when loading of a start-up file should only change
-		 * the scene content but keep the blender UI as it is. */
-		wm_open_init_load_ui(op, true);
-		BKE_BIT_TEST_SET(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
-
-		if (RNA_property_is_set(op->ptr, prop)) {
-			RNA_property_string_get(op->ptr, prop, filepath_buf);
-			filepath = filepath_buf;
-			if (BLI_access(filepath, R_OK)) {
-				BKE_reportf(op->reports, RPT_ERROR, "Can't read alternative start-up file: '%s'", filepath);
-				return OPERATOR_CANCELLED;
-			}
-		}
-	}
-	else {
-		/* always load UI for factory settings (prefs will re-init) */
-		G.fileflags &= ~G_FILE_NO_UI;
-	}
-
-	return wm_homefile_read(C, op->reports, from_memory, filepath) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
-}
-
 /** \name WM History File API
  * \{ */
 
@@ -1005,7 +970,7 @@ bool write_crash_blend(void)
 /**
  * \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way.
  */
-int wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports)
+static int wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports)
 {
 	Library *li;
 	int len;
@@ -1117,69 +1082,6 @@ int wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *
 	return ret;
 }
 
-/**
- * \see #wm_file_write wraps #BLO_write_file in a similar way.
- */
-int wm_homefile_write_exec(bContext *C, wmOperator *op)
-{
-	wmWindowManager *wm = CTX_wm_manager(C);
-	wmWindow *win = CTX_wm_window(C);
-	char filepath[FILE_MAX];
-	int fileflags;
-
-	BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE);
-
-	/* check current window and close it if temp */
-	if (win && win->screen->temp)
-		wm_window_close(C, wm, win);
-	
-	/* update keymaps in user preferences */
-	WM_keyconfig_update(wm);
-	
-	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
-	printf("trying to save homefile at %s ", filepath);
-	
-	ED_editors_flush_edits(C, false);
-
-	/*  force save as regular blend file */
-	fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY);
-
-	if (BLO_write_file(CTX_data_main(C), filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) {
-		printf("fail\n");
-		return OPERATOR_CANCELLED;
-	}
-	
-	printf("ok\n");
-
-	G.save_over = 0;
-
-	BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_POST);
-
-	return OPERATOR_FINISHED;
-}
-
-/* Only save the prefs block. operator entry */
-int wm_userpref_write_exec(bContext *C, wmOperator *op)
-{
-	wmWindowManager *wm = CTX_wm_manager(C);
-	char filepath[FILE_MAX];
-	
-	/* update keymaps in user preferences */
-	WM_keyconfig_update(wm);
-	
-	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_USERPREF_FILE);
-	printf("trying to save userpref at %s ", filepath);
-	
-	if (BKE_write_file_userdef(filepath, op->reports) == 0) {
-		printf("fail\n");
-		return OPERATOR_CANCELLED;
-	}
-	
-	printf("ok\n");
-	
-	return OPERATOR_FINISHED;
-}
-
 /************************ autosave ****************************/
 
 void wm_autosave_location(char *filepath)
@@ -1341,3 +1243,728 @@ void WM_file_tag_modified(const bContext *C)
 		WM_event_add_notifier(C, NC_WM | ND_DATACHANGED, NULL);
 	}
 }
+
+/** \name Preferences/startup save & load.
+ *
+ * \{ */
+
+/**
+ * \see #wm_file_write wraps #BLO_write_file in a similar way.
+ */
+static int wm_homefile_write_exec(bContext *C, wmOperator *op)
+{
+	wmWindowManager *wm = CTX_wm_manager(C);
+	wmWindow *win = CTX_wm_window(C);
+	char filepath[FILE_MAX];
+	int fileflags;
+
+	BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE);
+
+	/* check current window and close it if temp */
+	if (win && win->screen->temp)
+		wm_window_close(C, wm, win);
+
+	/* update keymaps in user preferences */
+	WM_keyconfig_update(wm);
+
+	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_STARTUP_FILE);
+	printf("trying to save homefile at %s ", filepath);
+
+	ED_editors_flush_edits(C, false);
+
+	/*  force save as regular blend file */
+	fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY);
+
+	if (BLO_write_file(CTX_data_main(C), filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) {
+		printf("fail\n");
+		return OPERATOR_CANCELLED;
+	}
+
+	printf("ok\n");
+
+	G.save_over = 0;
+
+	BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_POST);
+
+	return OPERATOR_FINISHED;
+}
+
+void WM_OT_save_homefile(wmOperatorType *ot)
+{
+	ot->name = "Save Startup File";
+	ot->idname = "WM_OT_save_homefile";
+	ot->description = "Make the current file the default .blend file, includes preferences";
+
+	ot->invoke = WM_operator_confirm;
+	ot->exec = wm_homefile_write_exec;
+}
+
+static int wm_userpref_autoexec_add_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
+	bPathCompare *path_cmp = MEM_callocN(sizeof(bPathCompare), "bPathCompare");
+	BLI_addtail(&U.autoexec_paths, path_cmp);
+	return OPERATOR_FINISHED;
+}
+
+void WM_OT_userpref_autoexec_path_add(wmOperatorType *ot)
+{
+	ot->name = "Add Autoexec Path";
+	ot->idname = "WM_OT_userpref_autoexec_path_add";
+	ot->description = "Add path to exclude from autoexecution";
+
+	ot->exec = wm_userpref_autoexec_add_exec;
+
+	ot->flag = OPTYPE_INTERNAL;
+}
+
+static int wm_userpref_autoexec_remove_exec(bContext *UNUSED(C), wmOperator *op)
+{
+	const int index = RNA_int_get(op->ptr, "index");
+	bPathCompare *path_cmp = BLI_findlink(&U.autoexec_paths, index);
+	if (path_cmp) {
+		BLI_freelinkN(&U.autoexec_paths, path_cmp);
+	}
+	return OPERATOR_FINISHED;
+}
+
+void WM_OT_userpref_autoexec_path_remove(wmOperatorType *ot)
+{
+	ot->name = "Remove Autoexec Path";
+	ot->idname = "WM_OT_userpref_autoexec_path_remove";
+	ot->description = "Remove path to exclude from autoexecution";
+
+	ot->exec = wm_userpref_autoexec_remove_exec;
+
+	ot->flag = OPTYPE_INTERNAL;
+
+	RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, 1000);
+}
+
+/* Only save the prefs block. operator entry */
+static int wm_userpref_write_exec(bContext *C, wmOperator *op)
+{
+	wmWindowManager *wm = CTX_wm_manager(C);
+	char filepath[FILE_MAX];
+
+	/* update keymaps in user preferences */
+	WM_keyconfig_update(wm);
+
+	BLI_make_file_string("/", filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_USERPREF_FILE);
+	printf("trying to save userpref at %s ", filepath);
+
+	if (BKE_write_file_userdef(filepath, op->reports) == 0) {
+		printf("fail\n");
+		return OPERATOR_CANCELLED;
+	}
+
+	printf("ok\n");
+
+	return OPERATOR_FINISHED;
+}
+
+void WM_OT_save_userpref(wmOperatorType *ot)
+{
+	ot->name = "Save User Settings";
+	ot->idname = "WM_OT_save_userpref";
+	ot->description = "Save user preferences separately, overrides startup file preferences";
+
+	ot->invoke = WM_operator_confirm;
+	ot->exec = wm_userpref_write_exec;
+}
+
+static int wm_history_file_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
+{
+	ED_file_read_bookmarks();
+	wm_history_file_read();
+	return OPERATOR_FINISHED;
+}
+
+void WM_OT_read_history(wmOperatorType *ot)
+{
+	ot->name = "Reload History File";
+	ot->idname = "WM_OT_read_history";
+	ot->description = "Reloads history and bookmarks";
+
+	ot->invoke = WM_operator_confirm;
+	ot->exec = wm_history_file_read_exec;
+
+	/* this operator is only used for loading settings from a previous blender install */
+	ot->flag = OPTYPE_INTERNAL;
+}
+
+static int wm_homefile_read_exec(bContext *C, wmOperator *op)
+{
+	const bool from_memory = (STREQ(op->type->idname, "WM_OT_read_factory_settings"));
+	char filepath_buf[FILE_MAX];
+	const char *filepath = NULL;
+
+	if (!from_memory) {
+		PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");
+
+		/* This can be used when loading of a start-up file should only change
+		 * the scene content but keep the blender UI as it is. */
+		wm_open_init_load_ui(op, true);
+		BKE_BIT_TEST_SET(G.fileflags, !RNA_boolean_get(op->ptr, "load_ui"), G_FILE_NO_UI);
+
+		if (RNA_property_is_set(op->ptr, prop)) {
+			RNA_property_string_get(op->ptr, prop, filepath_buf);
+			filepath = filepath_buf;
+			if (BL

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list