Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-10-30 18:32:19 +0300
committerJacques Lucke <jacques@blender.org>2020-10-30 18:32:55 +0300
commit62e532785dfd5bd25fb6b1269ec41ea81a32c4c9 (patch)
tree98a4f715605108ac1024bf2452cdfaacf2875cd7 /source
parenta877248ac203930e0d6473edf143c44df2f84cf4 (diff)
Refactor: move WorkSpace .blend I/O to IDTypeInfo callbacks
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/workspace.c102
-rw-r--r--source/blender/blenloader/BLO_read_write.h3
-rw-r--r--source/blender/blenloader/intern/readfile.c85
-rw-r--r--source/blender/blenloader/intern/writefile.c19
4 files changed, 108 insertions, 101 deletions
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 43e03fb5165..52420810171 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -48,6 +48,8 @@
#include "MEM_guardedalloc.h"
+#include "BLO_read_write.h"
+
/* -------------------------------------------------------------------- */
static void workspace_free_data(ID *id)
@@ -75,6 +77,98 @@ static void workspace_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
+static void workspace_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+ WorkSpace *workspace = (WorkSpace *)id;
+
+ BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id);
+ BKE_id_blend_write(writer, &workspace->id);
+ BLO_write_struct_list(writer, WorkSpaceLayout, &workspace->layouts);
+ BLO_write_struct_list(writer, WorkSpaceDataRelation, &workspace->hook_layout_relations);
+ BLO_write_struct_list(writer, wmOwnerID, &workspace->owner_ids);
+ BLO_write_struct_list(writer, bToolRef, &workspace->tools);
+ LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
+ if (tref->properties) {
+ IDP_BlendWrite(writer, tref->properties);
+ }
+ }
+}
+
+static void workspace_blend_read_data(BlendDataReader *reader, ID *id)
+{
+ WorkSpace *workspace = (WorkSpace *)id;
+
+ BLO_read_list(reader, &workspace->layouts);
+ BLO_read_list(reader, &workspace->hook_layout_relations);
+ BLO_read_list(reader, &workspace->owner_ids);
+ BLO_read_list(reader, &workspace->tools);
+
+ LISTBASE_FOREACH (WorkSpaceDataRelation *, relation, &workspace->hook_layout_relations) {
+ /* parent pointer does not belong to workspace data and is therefore restored in lib_link step
+ * of window manager.*/
+ BLO_read_data_address(reader, &relation->value);
+ }
+
+ LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
+ tref->runtime = NULL;
+ BLO_read_data_address(reader, &tref->properties);
+ IDP_BlendDataRead(reader, &tref->properties);
+ }
+
+ workspace->status_text = NULL;
+
+ id_us_ensure_real(&workspace->id);
+}
+
+static void workspace_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+ WorkSpace *workspace = (WorkSpace *)id;
+ Main *bmain = BLO_read_lib_get_main(reader);
+
+ /* Restore proper 'parent' pointers to relevant data, and clean up unused/invalid entries. */
+ LISTBASE_FOREACH_MUTABLE (WorkSpaceDataRelation *, relation, &workspace->hook_layout_relations) {
+ relation->parent = NULL;
+ LISTBASE_FOREACH (wmWindowManager *, wm, &bmain->wm) {
+ LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
+ if (win->winid == relation->parentid) {
+ relation->parent = win->workspace_hook;
+ }
+ }
+ }
+ if (relation->parent == NULL) {
+ BLI_freelinkN(&workspace->hook_layout_relations, relation);
+ }
+ }
+
+ LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout, &workspace->layouts) {
+ BLO_read_id_address(reader, id->lib, &layout->screen);
+
+ if (layout->screen) {
+ if (ID_IS_LINKED(id)) {
+ layout->screen->winid = 0;
+ if (layout->screen->temp) {
+ /* delete temp layouts when appending */
+ BKE_workspace_layout_remove(bmain, workspace, layout);
+ }
+ }
+ }
+ else {
+ /* If we're reading a layout without screen stored, it's useless and we shouldn't keep it
+ * around. */
+ BKE_workspace_layout_remove(bmain, workspace, layout);
+ }
+ }
+}
+
+static void workspace_blend_read_expand(BlendExpander *expander, ID *id)
+{
+ WorkSpace *workspace = (WorkSpace *)id;
+
+ LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
+ BLO_expand(expander, BKE_workspace_layout_screen_get(layout));
+ }
+}
+
IDTypeInfo IDType_ID_WS = {
.id_code = ID_WS,
.id_filter = FILTER_ID_WS,
@@ -92,10 +186,10 @@ IDTypeInfo IDType_ID_WS = {
.foreach_id = workspace_foreach_id,
.foreach_cache = NULL,
- .blend_write = NULL,
- .blend_read_data = NULL,
- .blend_read_lib = NULL,
- .blend_read_expand = NULL,
+ .blend_write = workspace_blend_write,
+ .blend_read_data = workspace_blend_read_data,
+ .blend_read_lib = workspace_blend_read_lib,
+ .blend_read_expand = workspace_blend_read_expand,
};
/* -------------------------------------------------------------------- */
diff --git a/source/blender/blenloader/BLO_read_write.h b/source/blender/blenloader/BLO_read_write.h
index 56b51bf3096..3600ae504a1 100644
--- a/source/blender/blenloader/BLO_read_write.h
+++ b/source/blender/blenloader/BLO_read_write.h
@@ -52,6 +52,8 @@ typedef struct BlendExpander BlendExpander;
typedef struct BlendLibReader BlendLibReader;
typedef struct BlendWriter BlendWriter;
+struct Main;
+
/* Blend Write API
* ===============
*
@@ -223,6 +225,7 @@ ID *BLO_read_get_new_id_address(BlendLibReader *reader, struct Library *lib, str
/* Misc. */
bool BLO_read_lib_is_undo(BlendLibReader *reader);
+struct Main *BLO_read_lib_get_main(BlendLibReader *reader);
/* Blend Expand API
* ===================
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6f305a5613f..29ed66c5080 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2569,69 +2569,6 @@ static void lib_link_constraint_channels(BlendLibReader *reader, ID *id, ListBas
/** \name Read ID: WorkSpace
* \{ */
-static void lib_link_workspaces(BlendLibReader *reader, WorkSpace *workspace)
-{
- ID *id = (ID *)workspace;
-
- /* Restore proper 'parent' pointers to relevant data, and clean up unused/invalid entries. */
- LISTBASE_FOREACH_MUTABLE (WorkSpaceDataRelation *, relation, &workspace->hook_layout_relations) {
- relation->parent = NULL;
- LISTBASE_FOREACH (wmWindowManager *, wm, &reader->main->wm) {
- LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
- if (win->winid == relation->parentid) {
- relation->parent = win->workspace_hook;
- }
- }
- }
- if (relation->parent == NULL) {
- BLI_freelinkN(&workspace->hook_layout_relations, relation);
- }
- }
-
- LISTBASE_FOREACH_MUTABLE (WorkSpaceLayout *, layout, &workspace->layouts) {
- BLO_read_id_address(reader, id->lib, &layout->screen);
-
- if (layout->screen) {
- if (ID_IS_LINKED(id)) {
- layout->screen->winid = 0;
- if (layout->screen->temp) {
- /* delete temp layouts when appending */
- BKE_workspace_layout_remove(reader->main, workspace, layout);
- }
- }
- }
- else {
- /* If we're reading a layout without screen stored, it's useless and we shouldn't keep it
- * around. */
- BKE_workspace_layout_remove(reader->main, workspace, layout);
- }
- }
-}
-
-static void direct_link_workspace(BlendDataReader *reader, WorkSpace *workspace)
-{
- BLO_read_list(reader, &workspace->layouts);
- BLO_read_list(reader, &workspace->hook_layout_relations);
- BLO_read_list(reader, &workspace->owner_ids);
- BLO_read_list(reader, &workspace->tools);
-
- LISTBASE_FOREACH (WorkSpaceDataRelation *, relation, &workspace->hook_layout_relations) {
- /* parent pointer does not belong to workspace data and is therefore restored in lib_link step
- * of window manager.*/
- BLO_read_data_address(reader, &relation->value);
- }
-
- LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
- tref->runtime = NULL;
- BLO_read_data_address(reader, &tref->properties);
- IDP_BlendDataRead(reader, &tref->properties);
- }
-
- workspace->status_text = NULL;
-
- id_us_ensure_real(&workspace->id);
-}
-
static void lib_link_workspace_instance_hook(BlendLibReader *reader,
WorkSpaceInstanceHook *hook,
ID *id)
@@ -5510,8 +5447,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
direct_link_library(fd, (Library *)id, main);
break;
case ID_WS:
- direct_link_workspace(&reader, (WorkSpace *)id);
- break;
case ID_PA:
case ID_GR:
case ID_ME:
@@ -6132,10 +6067,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_WM:
lib_link_windowmanager(&reader, (wmWindowManager *)id);
break;
- case ID_WS:
- /* Could we skip WS in undo case? */
- lib_link_workspaces(&reader, (WorkSpace *)id);
- break;
case ID_SCE:
lib_link_scene(&reader, (Scene *)id);
break;
@@ -6149,6 +6080,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_LI:
lib_link_library(&reader, (Library *)id); /* Only init users. */
break;
+ case ID_WS:
case ID_SCR:
case ID_PA:
case ID_GR:
@@ -7033,13 +6965,6 @@ static void expand_scene(BlendExpander *expander, Scene *sce)
}
}
-static void expand_workspace(BlendExpander *expander, WorkSpace *workspace)
-{
- LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
- BLO_expand(expander, BKE_workspace_layout_screen_get(layout));
- }
-}
-
/**
* Set the callback func used over all ID data found by \a BLO_expand_main func.
*
@@ -7092,9 +7017,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_IP:
expand_ipo(&expander, (Ipo *)id); /* XXX deprecated - old animation system */
break;
- case ID_WS:
- expand_workspace(&expander, (WorkSpace *)id);
- break;
default:
break;
}
@@ -8230,6 +8152,11 @@ bool BLO_read_lib_is_undo(BlendLibReader *reader)
return reader->fd->memfile != NULL;
}
+Main *BLO_read_lib_get_main(BlendLibReader *reader)
+{
+ return reader->main;
+}
+
void BLO_expand_id(BlendExpander *expander, ID *id)
{
expand_doit(expander->fd, expander->main, id);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index bcfc5778f1d..835e2f92c7c 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1662,21 +1662,6 @@ static void write_windowmanager(BlendWriter *writer, wmWindowManager *wm, const
}
}
-static void write_workspace(BlendWriter *writer, WorkSpace *workspace, const void *id_address)
-{
- BLO_write_id_struct(writer, WorkSpace, id_address, &workspace->id);
- BKE_id_blend_write(writer, &workspace->id);
- BLO_write_struct_list(writer, WorkSpaceLayout, &workspace->layouts);
- BLO_write_struct_list(writer, WorkSpaceDataRelation, &workspace->hook_layout_relations);
- BLO_write_struct_list(writer, wmOwnerID, &workspace->owner_ids);
- BLO_write_struct_list(writer, bToolRef, &workspace->tools);
- LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) {
- if (tref->properties) {
- IDP_BlendWrite(writer, tref->properties);
- }
- }
-}
-
/* Keep it last of write_foodata functions. */
static void write_libraries(WriteData *wd, Main *main)
{
@@ -1938,15 +1923,13 @@ static bool write_file_handle(Main *mainvar,
case ID_WM:
write_windowmanager(&writer, (wmWindowManager *)id_buffer, id);
break;
- case ID_WS:
- write_workspace(&writer, (WorkSpace *)id_buffer, id);
- break;
case ID_SCE:
write_scene(&writer, (Scene *)id_buffer, id);
break;
case ID_OB:
write_object(&writer, (Object *)id_buffer, id);
break;
+ case ID_WS:
case ID_SCR:
case ID_PA:
case ID_GR: