Refactor: Move workspace foreach_id to new IDTypeInfo structure.

This commit is contained in:
Bastien Montagne 2020-05-18 19:01:20 +02:00
parent 8f10f9d5dc
commit 06c57d3e7a
2 changed files with 20 additions and 13 deletions

View File

@ -856,19 +856,7 @@ static void library_foreach_ID_link(Main *bmain,
}
case ID_WS: {
WorkSpace *workspace = (WorkSpace *)id;
ListBase *layouts = BKE_workspace_layouts_get(workspace);
LISTBASE_FOREACH (WorkSpaceLayout *, layout, layouts) {
bScreen *screen = BKE_workspace_layout_screen_get(layout);
/* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer.
* However we can't access layout->screen here
* since we are outside the workspace project. */
CALLBACK_INVOKE(screen, IDWALK_CB_USER);
/* allow callback to set a different screen */
BKE_workspace_layout_screen_set(layout, screen);
}
BLI_assert(0);
break;
}

View File

@ -32,6 +32,7 @@
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
@ -65,6 +66,23 @@ static void workspace_free_data(ID *id)
MEM_SAFE_FREE(workspace->status_text);
}
static void workspace_foreach_id(ID *id, LibraryForeachIDData *data)
{
WorkSpace *workspace = (WorkSpace *)id;
ListBase *layouts = BKE_workspace_layouts_get(workspace);
LISTBASE_FOREACH (WorkSpaceLayout *, layout, layouts) {
bScreen *screen = BKE_workspace_layout_screen_get(layout);
/* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer.
* However we can't access layout->screen here
* since we are outside the workspace project. */
BKE_LIB_FOREACHID_PROCESS(data, screen, IDWALK_CB_USER);
/* allow callback to set a different screen */
BKE_workspace_layout_screen_set(layout, screen);
}
}
IDTypeInfo IDType_ID_WS = {
.id_code = ID_WS,
.id_filter = FILTER_ID_WS,
@ -79,6 +97,7 @@ IDTypeInfo IDType_ID_WS = {
.copy_data = NULL,
.free_data = workspace_free_data,
.make_local = NULL,
.foreach_id = workspace_foreach_id,
};
/** \name Internal Utils