[Bf-blender-cvs] [1ad7359efdd] workspaces: Bundle default workspace user configuration file with Blender
Julian Eisel
noreply at git.blender.org
Thu Apr 6 23:44:06 CEST 2017
Commit: 1ad7359efdd43bf863ac4b4687d09af7af773693
Author: Julian Eisel
Date: Thu Apr 6 23:32:45 2017 +0200
Branches: workspaces
https://developer.blender.org/rB1ad7359efdd43bf863ac4b4687d09af7af773693
Bundle default workspace user configuration file with Blender
This contains nothing but the old screen-layouts converted into
workspaces (and "Default" layout/workspace is now called "General").
Note that this adds the workspaces.blend directly, no datatoc conversion
is used like for default startup.blend. Mainly for these two reasons:
* Appending only supports regular .blend files
* Regular .blend is much smaller than datatoc one (181kB vs. 1.4MB)
===================================================================
A release/datafiles/workspaces.blend
M source/blender/editors/screen/workspace_edit.c
M source/blender/windowmanager/intern/wm_files.c
M source/creator/CMakeLists.txt
===================================================================
diff --git a/release/datafiles/workspaces.blend b/release/datafiles/workspaces.blend
new file mode 100644
index 00000000000..27a3e474383
Binary files /dev/null and b/release/datafiles/workspaces.blend differ
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index 387bc89d728..8b6842d80d3 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -23,6 +23,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include "BLI_utildefines.h"
#include "BLI_fileops.h"
@@ -180,6 +181,7 @@ bool ED_workspace_change(
}
screen_new = screen_change_prepare(screen_old, screen_new, bmain, C, win);
+ BLI_assert(BKE_workspace_layout_screen_get(layout_new) == screen_new);
if (screen_new) {
WM_window_set_active_layout(win, workspace_new, layout_new);
@@ -306,28 +308,54 @@ static void WORKSPACE_OT_workspace_delete(wmOperatorType *ot)
ot->exec = workspace_delete_exec;
}
-ATTR_NONNULL(1)
-static WorkspaceConfigFileData *workspace_config_file_read(const Main *bmain, ReportList *reports)
+static void workspace_config_file_path_from_folder_id(const Main *bmain, int folder_id, char *r_path)
{
- char workspace_config_path[FILE_MAX];
- const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL);
+ const char *cfgdir = BKE_appdir_folder_id(folder_id, NULL);
if (cfgdir) {
- BLI_make_file_string(bmain->name, workspace_config_path, cfgdir, BLENDER_WORKSPACES_FILE);
+ BLI_make_file_string(bmain->name, r_path, cfgdir, BLENDER_WORKSPACES_FILE);
}
else {
- workspace_config_path[0] = '\0';
+ r_path[0] = '\0';
}
+}
+
+ATTR_NONNULL(1)
+static WorkspaceConfigFileData *workspace_config_file_read(const Main *bmain, ReportList *reports)
+{
+ char workspace_config_path[FILE_MAX];
+ bool has_path = false;
+ workspace_config_file_path_from_folder_id(bmain, BLENDER_USER_CONFIG, workspace_config_path);
if (BLI_exists(workspace_config_path)) {
- /* may still return NULL */
- return BKE_blendfile_workspace_config_read(workspace_config_path, reports);
+ has_path = true;
}
- else if (reports) {
- BKE_reportf(reports, RPT_WARNING, "Couldn't find workspace configuration file in %s", workspace_config_path);
+ else {
+ workspace_config_file_path_from_folder_id(bmain, BLENDER_DATAFILES, workspace_config_path);
+ if (BLI_exists(workspace_config_path)) {
+ has_path = true;
+ }
}
- return NULL;
+ return has_path ? BKE_blendfile_workspace_config_read(workspace_config_path, reports) : NULL;
+}
+
+static void workspace_append_button(
+ uiLayout *layout, wmOperatorType *ot_append, const WorkSpace *workspace, const Main *from_main)
+{
+ const ID *id = BKE_workspace_id_get((WorkSpace *)workspace); /* non-const cast, but we really don't modify it... */
+ PointerRNA opptr;
+ char lib_path[FILE_MAX_LIBEXTRA];
+
+ BLI_path_join(
+ lib_path, sizeof(lib_path), from_main->name, BKE_idcode_to_name(GS(id->name)), NULL);
+
+ BLI_assert(STREQ(ot_append->idname, "WM_OT_append"));
+ 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);
}
ATTR_NONNULL(1, 2)
@@ -338,21 +366,10 @@ static void workspace_config_file_append_buttons(
if (workspace_config) {
wmOperatorType *ot_append = WM_operatortype_find("WM_OT_append", true);
- PointerRNA opptr;
- char lib_path[FILE_MAX_LIBEXTRA];
BKE_workspace_iter_begin(workspace, workspace_config->workspaces.first)
{
- ID *id = BKE_workspace_id_get(workspace);
-
- BLI_path_join(
- lib_path, sizeof(lib_path), workspace_config->main->name, BKE_idcode_to_name(GS(id->name)), NULL);
-
- 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);
+ workspace_append_button(layout, ot_append, workspace, workspace_config->main);
}
BKE_workspace_iter_end;
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index f74f15ecd8e..34f226e8155 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -245,6 +245,7 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
bScreen *screen = NULL;
/* when loading without UI, no matching needed */
+ /* XXX think we don't handle this correctly yet, it's activating workspace from old file */
if (!(G.fileflags & G_FILE_NO_UI) && (screen = CTX_wm_screen(C))) {
/* match oldwm to new dbase, only old files */
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index eea45545949..7c8684d0331 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -423,6 +423,12 @@ if(WITH_OPENCOLORIO)
)
endif()
+# Add default workspaces.blend to build (under [version]/datafiles
+install(
+ FILES ${CMAKE_SOURCE_DIR}/release/datafiles/workspaces.blend
+ DESTINATION ${TARGETDIR_VER}/datafiles
+)
+
# helpful tip when using make
if("${CMAKE_GENERATOR}" MATCHES ".*Makefiles.*")
# message after building.
More information about the Bf-blender-cvs
mailing list