[Bf-blender-cvs] [28254985182] workspaces: Allow storing workspaces as part of user config (UI preliminary)

Julian Eisel noreply at git.blender.org
Thu Apr 6 12:19:42 CEST 2017


Commit: 2825498518272554d79ca425ea5f98317d43d602
Author: Julian Eisel
Date:   Thu Apr 6 12:09:31 2017 +0200
Branches: workspaces
https://developer.blender.org/rB2825498518272554d79ca425ea5f98317d43d602

Allow storing workspaces as part of user config (UI preliminary)

Adds a button in the User Preference Interface tab to save all
workspaces of the current file into [user config
path]/config/worflow.blend.
When clicking the button to add a new workspace, the menu will list
these then (and of course the option to duplicate current workspace).

Note that the operator currently overrides all workspaces in the config
file. There should be ways to add and remove workspaces from it instead,
but we need to figure out a good UI design for how to do that still.

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_blendfile.h
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/wm_files.h

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 19577f25c98..81ed53b8267 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -57,7 +57,9 @@ class USERPREF_HT_header(Header):
 
         layout.operator_context = 'INVOKE_DEFAULT'
 
-        if userpref.active_section == 'INPUT':
+        if userpref.active_section == 'INTERFACE':
+            layout.operator("wm.save_workflow_file")
+        elif userpref.active_section == 'INPUT':
             layout.operator("wm.keyconfig_import")
             layout.operator("wm.keyconfig_export")
         elif userpref.active_section == 'ADDONS':
diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 55af41fcec9..64fa165089f 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -61,6 +61,7 @@ struct UserDef *BKE_blendfile_userdef_read_from_memory(
 int BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
 
 struct WorkflowFileData *BKE_blendfile_workflow_read(const char *filepath, struct ReportList *reports);
+bool BKE_blendfile_workflow_write(struct Main *bmain, const char *filepath, struct ReportList *reports);
 void BKE_blendfile_workflow_data_free(struct WorkflowFileData *workflow_file);
 
 
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index ac55cbe0ac8..b430b43ee66 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -532,6 +532,29 @@ WorkflowFileData *BKE_blendfile_workflow_read(const char *filepath, ReportList *
 	return workflow_file;
 }
 
+bool BKE_blendfile_workflow_write(Main *bmain, const char *filepath, ReportList *reports)
+{
+	int fileflags = G.fileflags & ~(G_FILE_NO_UI | G_FILE_AUTOPLAY | G_FILE_HISTORY);
+	bool retval = false;
+
+	BKE_blendfile_write_partial_begin(bmain);
+
+	BKE_workspace_iter_begin(workspace, bmain->workspaces.first)
+	{
+		ID *workspace_id = BKE_workspace_id_get(workspace);
+		BKE_blendfile_write_partial_tag_ID(workspace_id, true);
+	}
+	BKE_workspace_iter_end;
+
+	if (BKE_blendfile_write_partial(bmain, filepath, fileflags, reports)) {
+		retval = true;
+	}
+
+	BKE_blendfile_write_partial_end(bmain);
+
+	return retval;
+}
+
 void BKE_blendfile_workflow_data_free(WorkflowFileData *workflow_file)
 {
 	BKE_main_free(workflow_file->main);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 4bec08bbc00..b68df5e6bbb 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -469,7 +469,8 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local)
 			return true;
 		case ID_WS:
 		case ID_SCR:
-			/* A bit special: can be appended but not linked. Thus, supporting make-local doesn't make much sense. */
+			/* A bit special: can be appended but not linked. Return false
+			 * since supporting make-local doesn't make much sense. */
 			return false;
 		case ID_LI:
 		case ID_KE:
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d72148bb09e..996064933f1 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2768,6 +2768,7 @@ static void lib_link_workspaces(FileData *fd, Main *bmain)
 
 static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main *main)
 {
+	ID *workspace_id = BKE_workspace_id_get(workspace);
 	ListBase *hook_layout_relations = BKE_workspace_hook_layout_relations_get(workspace);
 
 	link_list(fd, BKE_workspace_layouts_get(workspace));
@@ -2784,6 +2785,12 @@ static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main
 		BKE_workspace_relation_data_set(relation, parent, data);
 	}
 
+	if (ID_IS_LINKED_DATABLOCK(workspace_id)) {
+		/* Appending workspace so render layer is likely from a different scene. Unset
+		 * now, when activating workspace later we set a valid one from current scene. */
+		BKE_workspace_render_layer_set(workspace, NULL);
+	}
+
 	/* Same issue/fix as in direct_link_scene_update_screen_data: Can't read workspace data
 	 * when reading windows, so have to update windows after/when reading workspaces. */
 	for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) {
@@ -9981,9 +9988,6 @@ static void expand_workspace(FileData *fd, Main *mainvar, WorkSpace *workspace)
 		expand_doit(fd, mainvar, BKE_workspace_layout_screen_get(layout));
 	}
 	BKE_workspace_layout_iter_end;
-
-	/* unset render-layer, when changing workspace we'll assign one from the active scene then. */
-	BKE_workspace_render_layer_set(workspace, NULL);
 }
 
 /**
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 80a698c8008..61987246e1b 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1512,6 +1512,41 @@ void WM_OT_save_userpref(wmOperatorType *ot)
 	ot->exec = wm_userpref_write_exec;
 }
 
+static int wm_workflow_file_write_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain = CTX_data_main(C);
+	char filepath[FILE_MAX];
+	const char *cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL);
+
+	if (cfgdir) {
+		BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_WORKFLOW_FILE, NULL);
+		printf("trying to save workflow file at %s ", filepath);
+
+		if (BKE_blendfile_workflow_write(bmain, filepath, op->reports) != 0) {
+			printf("ok\n");
+			return OPERATOR_FINISHED;
+		}
+		else {
+			printf("fail\n");
+		}
+	}
+	else {
+		BKE_report(op->reports, RPT_ERROR, "Unable to create workflow file path");
+	}
+
+	return OPERATOR_CANCELLED;
+}
+
+void WM_OT_save_workflow_file(wmOperatorType *ot)
+{
+	ot->name = "Save Workspaces";
+	ot->idname = "WM_OT_save_workflow_file";
+	ot->description = "Save workspaces of the current file as part of the user configuration";
+
+	ot->invoke = WM_operator_confirm;
+	ot->exec = wm_workflow_file_write_exec;
+}
+
 static int wm_history_file_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
 	ED_file_read_bookmarks();
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 861b87ba857..41c32644657 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -4233,6 +4233,7 @@ void wm_operatortype_init(void)
 	WM_operatortype_append(WM_OT_read_factory_settings);
 	WM_operatortype_append(WM_OT_save_homefile);
 	WM_operatortype_append(WM_OT_save_userpref);
+	WM_operatortype_append(WM_OT_save_workflow_file);
 	WM_operatortype_append(WM_OT_userpref_autoexec_path_add);
 	WM_operatortype_append(WM_OT_userpref_autoexec_path_remove);
 	WM_operatortype_append(WM_OT_window_fullscreen_toggle);
diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h
index 9a1518e15b0..b2213acbeaa 100644
--- a/source/blender/windowmanager/wm_files.h
+++ b/source/blender/windowmanager/wm_files.h
@@ -45,6 +45,7 @@ void        WM_OT_save_homefile(struct wmOperatorType *ot);
 void        WM_OT_userpref_autoexec_path_add(struct wmOperatorType *ot);
 void        WM_OT_userpref_autoexec_path_remove(struct wmOperatorType *ot);
 void        WM_OT_save_userpref(struct wmOperatorType *ot);
+void        WM_OT_save_workflow_file(struct wmOperatorType *ot);
 void        WM_OT_read_history(struct wmOperatorType *ot);
 void        WM_OT_read_homefile(struct wmOperatorType *ot);
 void        WM_OT_read_factory_settings(struct wmOperatorType *ot);




More information about the Bf-blender-cvs mailing list