[Bf-blender-cvs] [848df597732] workspaces: Allow choosing workspace from user config when adding workspace

Julian Eisel noreply at git.blender.org
Tue Mar 28 23:02:03 CEST 2017


Commit: 848df597732d3284de2521e7f31deff156e1a00a
Author: Julian Eisel
Date:   Tue Mar 28 21:55:43 2017 +0200
Branches: workspaces
https://developer.blender.org/rB848df597732d3284de2521e7f31deff156e1a00a

Allow choosing workspace from user config when adding workspace

When clicking the '+' icon to add a new workspace, a menu is spawned
now, showing the option 'Duplicate Current', but also a list of all
workspaces stored in a 'workflow.blend' as part of the user
configuration (next to startup.blend and userpref.blend)
Note that this workflow.blend has to be stored manually into the user
config folder right now. Of course it's not supposed to stay like this,
it should all be handled through simple operators for adding and removing
workspaces from the user configuration. We need to find out how that
would work UI wise though (tm).

When choosing a workspace from the menu, Blender does nothing but
appending the workspace from the workflow.blend file.

This design allows having a custom workspace setup stored as part of
the user configuration, it's however still possible to append workspaces
from regular .blend files.
This is useful e.g. if users want to open their workspaces without
overriding the workflow.blend when using the machine of someone else.

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

M	release/scripts/startup/bl_ui/space_info.py
M	source/blender/blenkernel/BKE_appdir.h
M	source/blender/blenkernel/BKE_blendfile.h
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/editors/space_file/file_utils.c
M	source/blender/editors/workspace/CMakeLists.txt
M	source/blender/editors/workspace/workspace_edit.c
M	source/blender/imbuf/intern/thumbs_blend.c
M	source/blender/windowmanager/intern/wm_files_link.c

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

diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index 29f26f99e07..81be503baaa 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -44,7 +44,7 @@ class INFO_HT_header(Header):
             layout.operator("screen.back_to_previous", icon='SCREEN_BACK', text="Back to Previous")
             layout.separator()
         else:
-            layout.template_ID(window, "workspace", new="workspace.workspace_new", unlink="workspace.workspace_delete")
+            layout.template_ID(window, "workspace", new="workspace.workspace_add", unlink="workspace.workspace_delete")
             layout.template_ID_preview(window, "screen", workspace, "screens", new="screen.new", unlink="screen.delete", rows=2, cols=6)
 
         if hasattr(workspace, 'object_mode'):
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index ac8f861fa56..3827036b9ff 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -66,6 +66,7 @@ enum {
 	BLENDER_USER_DATAFILES      = 32,
 	BLENDER_USER_SCRIPTS        = 33,
 	BLENDER_USER_AUTOSAVE       = 34,
+	BLENDER_USER_WORKFLOW       = 35,
 
 	/* system */
 	BLENDER_SYSTEM_DATAFILES    = 52,
@@ -82,6 +83,7 @@ enum {
 
 #define BLENDER_STARTUP_FILE    "startup.blend"
 #define BLENDER_USERPREF_FILE   "userpref.blend"
+#define BLENDER_WORKFLOW_FILE   "workflow.blend"
 #define BLENDER_QUIT_FILE       "quit.blend"
 #define BLENDER_BOOKMARK_FILE   "bookmarks.txt"
 #define BLENDER_HISTORY_FILE    "recent-files.txt"
diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 75978120051..4fe48af45c6 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -59,6 +59,9 @@ 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);
+void BKE_blendfile_workflow_data_free(struct WorkflowFileData *workflow_file);
+
 
 /* partial blend file writing */
 void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set);
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 714d551e5f1..81577de9d50 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -481,6 +481,29 @@ int BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
 	return retval;
 }
 
+WorkflowFileData *BKE_blendfile_workflow_read(const char *filepath, ReportList *reports)
+{
+	BlendFileData *bfd;
+	WorkflowFileData *workflow_file = NULL;
+
+	bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_USERDEF); /* TODO only read workspaces */
+	if (bfd) {
+		workflow_file = MEM_mallocN(sizeof(*workflow_file), __func__);
+		workflow_file->main = bfd->main;
+		workflow_file->workspaces = bfd->main->workspaces;
+
+		MEM_freeN(bfd);
+	}
+
+	return workflow_file;
+}
+
+void BKE_blendfile_workflow_data_free(WorkflowFileData *workflow_file)
+{
+	BKE_main_free(workflow_file->main);
+	MEM_freeN(workflow_file);
+}
+
 /** \} */
 
 
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 90ace4eb599..79782028963 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -72,6 +72,12 @@ typedef struct BlendFileData {
 	BlenFileType type;
 } BlendFileData;
 
+typedef struct WorkflowFileData {
+	struct Main *main; /* has to be freed when done reading file data */
+
+	ListBase workspaces;
+} WorkflowFileData;
+
 
 /* skip reading some data-block types (may want to skip screen data too). */
 typedef enum eBLOReadSkip {
diff --git a/source/blender/editors/space_file/file_utils.c b/source/blender/editors/space_file/file_utils.c
index c1caf5ae8ac..fc870399696 100644
--- a/source/blender/editors/space_file/file_utils.c
+++ b/source/blender/editors/space_file/file_utils.c
@@ -26,6 +26,7 @@
 
 #include "BLI_rect.h"
 #include "BLI_fileops.h"
+#include "BLI_listbase.h"
 
 #include "BLO_readfile.h"
 
diff --git a/source/blender/editors/workspace/CMakeLists.txt b/source/blender/editors/workspace/CMakeLists.txt
index 15f74f4b89a..9f5a97c115f 100644
--- a/source/blender/editors/workspace/CMakeLists.txt
+++ b/source/blender/editors/workspace/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
 	../../blenfont
 	../../blenkernel
 	../../blenlib
+	../../blenloader
 	../../blentranslation
 	../../bmesh
 	../../gpu
diff --git a/source/blender/editors/workspace/workspace_edit.c b/source/blender/editors/workspace/workspace_edit.c
index 94670518d38..0ed04435ae6 100644
--- a/source/blender/editors/workspace/workspace_edit.c
+++ b/source/blender/editors/workspace/workspace_edit.c
@@ -24,14 +24,23 @@
 
 #include <stdlib.h>
 
+#include "BLI_utildefines.h"
+#include "BLI_fileops.h"
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "BKE_appdir.h"
+#include "BKE_blendfile.h"
 #include "BKE_context.h"
+#include "BKE_idcode.h"
 #include "BKE_main.h"
 #include "BKE_library.h"
+#include "BKE_report.h"
 #include "BKE_screen.h"
 #include "BKE_workspace.h"
 
-#include "BLI_utildefines.h"
-#include "BLI_listbase.h"
+#include "BLO_readfile.h"
 
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
@@ -40,6 +49,11 @@
 #include "ED_object.h"
 #include "ED_screen.h"
 
+#include "RNA_access.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -258,12 +272,12 @@ static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
 	return OPERATOR_FINISHED;
 }
 
-static void WORKSPACE_OT_workspace_new(wmOperatorType *ot)
+static void WORKSPACE_OT_workspace_duplicate(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name = "New Workspace";
 	ot->description = "Add a new workspace";
-	ot->idname = "WORKSPACE_OT_workspace_new";
+	ot->idname = "WORKSPACE_OT_workspace_duplicate";
 
 	/* api callbacks */
 	ot->exec = workspace_new_exec;
@@ -292,10 +306,96 @@ static void WORKSPACE_OT_workspace_delete(wmOperatorType *ot)
 	ot->exec = workspace_delete_exec;
 }
 
+ATTR_NONNULL(1)
+static WorkflowFileData *workspace_workflow_file_read(const Main *bmain, ReportList *reports)
+{
+	char filepath_workflow[FILE_MAX];
+	const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
+
+	if (cfgdir) {
+		BLI_make_file_string(bmain->name, filepath_workflow, cfgdir, BLENDER_WORKFLOW_FILE);
+	}
+	else {
+		filepath_workflow[0] = '\0';
+	}
+
+	if (BLI_exists(filepath_workflow)) {
+		/* may still return NULL */
+		return BKE_blendfile_workflow_read(filepath_workflow, reports);
+	}
+	else if (reports) {
+		BKE_reportf(reports, RPT_WARNING, "Couldn't find workflow file in %s", filepath_workflow);
+	}
+
+	return NULL;
+}
+
+ATTR_NONNULL(1, 2)
+static void workspace_workflow_file_append_buttons(
+        uiLayout *layout, const Main *bmain, ReportList *reports)
+{
+	WorkflowFileData *workflow_file = workspace_workflow_file_read(bmain, reports);
+
+	if (workflow_file) {
+		wmOperatorType *ot_append = WM_operatortype_find("WM_OT_append", true);
+		PointerRNA opptr;
+		char lib_path[FILE_MAX_LIBEXTRA];
+
+		BKE_workspace_iter_begin(workspace, workflow_file->workspaces.first)
+		{
+			ID *id = BKE_workspace_id_get(workspace);
+
+			BLI_snprintf(
+			            lib_path, sizeof(lib_path), "%s%c%s", workflow_file->main->name,
+			            SEP, BKE_idcode_to_name(GS(id->name)));
+
+			opptr = uiItemFullO_ptr(
+			            layout, ot_append, BKE_workspace_name_get(workspace), ICON_NONE, NULL,
+			            WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+			RNA_string_set(&opptr, "directory", lib_path);
+			RNA_string_set(&opptr, "filename", id->name + 2);
+		}
+		BKE_workspace_iter_end;
+
+		BKE_blendfile_workflow_data_free(workflow_file);
+	}
+}
+
+static int workspace_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+	const Main *bmain = CTX_data_main(C);
+	uiPopupMenu *pup;
+	uiLayout *layout;
+
+	pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
+	layout = UI_popup_menu_layout(pup);
+
+	uiItemO(layout, "Duplicate Current", ICON_NONE, "WORKSPACE_OT_workspace_duplicate");
+	uiItemS(layout);
+	workspace_workflow_file_append_buttons(layout, bmain, op->reports);
+
+	UI_popup_menu_end(C, pup);
+
+	return OPERATOR_INTERFACE;
+}
+
+static void WORKSPACE_OT_workspace_add_menu(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Add Workspace";
+	ot->description = "Add a new workspace by duplicating the current one or appending one "
+	                  "from the workflow configuration";
+	ot->idname = "WORKSPACE_OT_workspace_add";
+
+	/* api callbacks */
+	ot->invoke = workspace_add_invoke;
+}
+
 void ED_operatortypes_workspace(void)
 {
-	WM_operatortype_append(WORKSPACE_OT_workspace_new);
+	WM_operatortype_append(WORKSPACE_OT_workspace_duplicate);
 	WM_operatortype_append(WORKSPACE_OT_workspace_delete);
+	WM_operatortype_append(WORKSPACE_OT_workspace_add_menu);
 }
 
 /** \} Workspace Operators */
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
index b5c6deb6b01..dcc7006e3c0 100644
--- a/source/blender/imbuf/intern/thumbs_blend.c
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -32,6 +32,7 @@
 #include "BLI_endian_switch.h"
 #include "BLI_fileops.h"
 #include "BLI_linklist.h"
+#include "BLI_listbase.h"
 
 #include "BLO_blend_defs.h"
 #include "BLO_readfile.h"
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index 834d94f2025..ab60b991d70 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -435,6 +435,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
 		wm_link_append_data_library_add(lapp_data, libname);
 		item = wm_link_append_data_item_add(lapp_data, name, BKE_idcode_from_name(group), NULL);
 		BLI_BITMAP_ENABLE(item->libraries, 0);
+		has_item =

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list