diff options
author | Julian Eisel <julian@blender.org> | 2022-04-26 23:23:52 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-04-26 23:23:52 +0300 |
commit | 5fe1624b0eba8267325f166de8e75c4d2dd6989b (patch) | |
tree | d7ea9f084ba06a11bd0bd97490b00825fefaaf94 /source/blender/blenkernel/intern/context.c | |
parent | 8016d8a4bd21b2c113f0e2c9252d658cd48a5bd8 (diff) |
UI: Support setting context for buttons without layout
It was possible to set context pointers for buttons via the layout, but
not for buttons in places where the layout system wasn't used (where
buttons are placed manually). This is needed for buttons in the
Outliner, see D14653.
Diffstat (limited to 'source/blender/blenkernel/intern/context.c')
-rw-r--r-- | source/blender/blenkernel/intern/context.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 63efbb99368..1f1a49ca030 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -190,6 +190,22 @@ void CTX_store_set(bContext *C, bContextStore *store) C->wm.store = store; } +const PointerRNA *CTX_store_ptr_lookup(const bContextStore *store, + const char *name, + const StructRNA *type) +{ + bContextStoreEntry *entry = BLI_rfindstring( + &store->entries, name, offsetof(bContextStoreEntry, name)); + if (!entry) { + return NULL; + } + + if (type && !RNA_struct_is_a(entry->ptr.type, type)) { + return NULL; + } + return &entry->ptr; +} + bContextStore *CTX_store_copy(bContextStore *store) { bContextStore *ctx = MEM_dupallocN(store); @@ -324,11 +340,10 @@ static eContextResult ctx_data_get(bContext *C, const char *member, bContextData if (done != 1 && recursion < 1 && C->wm.store) { C->data.recursion = 1; - bContextStoreEntry *entry = BLI_rfindstring( - &C->wm.store->entries, member, offsetof(bContextStoreEntry, name)); + const PointerRNA *ptr = CTX_store_ptr_lookup(C->wm.store, member, NULL); - if (entry) { - result->ptr = entry->ptr; + if (ptr) { + result->ptr = *ptr; done = 1; } } |