From 613148ce5bf887ecf700db0c25aafa45ee9b7a63 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 9 Mar 2020 12:06:49 +0100 Subject: Cleanup: WorkSpace: Move to IDTypeInfo and remove unused BKE API. --- source/blender/blenkernel/intern/workspace.c | 62 +++++++++++++++++----------- 1 file changed, 37 insertions(+), 25 deletions(-) (limited to 'source/blender/blenkernel/intern/workspace.c') 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. -- cgit v1.2.3