From 613148ce5bf887ecf700db0c25aafa45ee9b7a63 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 9 Mar 2020 12:06:49 +0100 Subject: [PATCH] Cleanup: WorkSpace: Move to IDTypeInfo and remove unused BKE API. --- source/blender/blenkernel/BKE_idtype.h | 2 +- source/blender/blenkernel/BKE_workspace.h | 1 - source/blender/blenkernel/intern/idtype.c | 2 +- .../blender/blenkernel/intern/lib_id_delete.c | 2 +- source/blender/blenkernel/intern/workspace.c | 62 +++++++++++-------- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index 54074c91fe6..1c10ebbc5d5 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -158,7 +158,7 @@ extern IDTypeInfo IDType_ID_WM; // extern IDTypeInfo IDType_ID_PAL; // extern IDTypeInfo IDType_ID_PC; // extern IDTypeInfo IDType_ID_CF; -// extern IDTypeInfo IDType_ID_WS; +extern IDTypeInfo IDType_ID_WS; extern IDTypeInfo IDType_ID_LP; /* ********** Helpers/Utils API. ********** */ diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h index 508a6179411..8582996108a 100644 --- a/source/blender/blenkernel/BKE_workspace.h +++ b/source/blender/blenkernel/BKE_workspace.h @@ -35,7 +35,6 @@ struct bToolRef; /* Create, delete, init */ struct WorkSpace *BKE_workspace_add(struct Main *bmain, const char *name); -void BKE_workspace_free(struct WorkSpace *workspace); void BKE_workspace_remove(struct Main *bmain, struct WorkSpace *workspace); struct WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(const struct Main *bmain); diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c index a7274fbc23d..0e72b20e035 100644 --- a/source/blender/blenkernel/intern/idtype.c +++ b/source/blender/blenkernel/intern/idtype.c @@ -85,7 +85,7 @@ static void id_type_init(void) // INIT_TYPE(ID_PAL); // INIT_TYPE(ID_PC); // INIT_TYPE(ID_CF); - // INIT_TYPE(ID_WS); + INIT_TYPE(ID_WS); INIT_TYPE(ID_LP); #undef INIT_TYPE diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c index 6a017d5a8d7..f9df36a71cc 100644 --- a/source/blender/blenkernel/intern/lib_id_delete.c +++ b/source/blender/blenkernel/intern/lib_id_delete.c @@ -241,7 +241,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) BKE_cachefile_free((CacheFile *)id); break; case ID_WS: - BKE_workspace_free((WorkSpace *)id); + BLI_assert(0); break; } } diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 6e923822f7d..8fff2e60594 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -26,8 +26,11 @@ #include "BLI_string_utils.h" #include "BLI_listbase.h" +#include "BLT_translation.h" + #include "BKE_global.h" #include "BKE_idprop.h" +#include "BKE_idtype.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_scene.h" @@ -45,6 +48,39 @@ #include "MEM_guardedalloc.h" /* -------------------------------------------------------------------- */ + +static void workspace_free_data(ID *id) +{ + WorkSpace *workspace = (WorkSpace *)id; + + BKE_workspace_relations_free(&workspace->hook_layout_relations); + + BLI_freelistN(&workspace->owner_ids); + BLI_freelistN(&workspace->layouts); + + while (!BLI_listbase_is_empty(&workspace->tools)) { + BKE_workspace_tool_remove(workspace, workspace->tools.first); + } + + MEM_SAFE_FREE(workspace->status_text); +} + +IDTypeInfo IDType_ID_WS = { + .id_code = ID_WS, + .id_filter = FILTER_ID_WS, + .main_listbase_index = INDEX_ID_WS, + .struct_size = sizeof(WorkSpace), + .name = "WorkSpace", + .name_plural = "workspaces", + .translation_context = BLT_I18NCONTEXT_ID_WORKSPACE, + .flags = IDTYPE_FLAGS_NO_COPY | IDTYPE_FLAGS_NO_MAKELOCAL, + + .init_data = NULL, + .copy_data = NULL, + .free_data = workspace_free_data, + .make_local = NULL, +}; + /** \name Internal Utils * \{ */ @@ -150,33 +186,9 @@ WorkSpace *BKE_workspace_add(Main *bmain, const char *name) return new_workspace; } -/** - * The function that actually frees the workspace data (not workspace itself). - * It shouldn't be called directly, instead #BKE_workspace_remove should be, - * which calls this through #BKE_id_free then. - * - * Should something like a bke_internal.h be added, this should go there! - */ -void BKE_workspace_free(WorkSpace *workspace) -{ - BKE_workspace_relations_free(&workspace->hook_layout_relations); - - BLI_freelistN(&workspace->owner_ids); - BLI_freelistN(&workspace->layouts); - - while (!BLI_listbase_is_empty(&workspace->tools)) { - BKE_workspace_tool_remove(workspace, workspace->tools.first); - } - - if (workspace->status_text) { - MEM_freeN(workspace->status_text); - workspace->status_text = NULL; - } -} - /** * Remove \a workspace by freeing itself and its data. This is a higher-level wrapper that - * calls #BKE_workspace_free (through #BKE_id_free) to free the workspace data, and frees + * calls #workspace_free_data (through #BKE_id_free) to free the workspace data, and frees * other data-blocks owned by \a workspace and its layouts (currently that is screens only). * * Always use this to remove (and free) workspaces. Don't free non-ID workspace members here.