Popup menu layout inherits context store from button.

When adding extra context data in a layout using uiLayoutSetContextPointer, this info was not inherited by popup menus generated in this layout. While operators from regular buttons work fine, the data is missing in operators from menus and such. This patch copies the bContextStore from buttons to the new uiLayout used for popups.
This commit is contained in:
Lukas Toenne 2012-04-03 15:18:59 +00:00
parent f137ba074a
commit 123f7d3eb3
5 changed files with 42 additions and 2 deletions

@ -117,6 +117,7 @@ bContext *CTX_copy(const bContext *C);
/* Stored Context */
bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *ptr);
bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context);
void CTX_store_set(bContext *C, bContextStore *store);
bContextStore *CTX_store_copy(bContextStore *store);
void CTX_store_free(bContextStore *store);

@ -141,6 +141,35 @@ bContextStore *CTX_store_add(ListBase *contexts, const char *name, PointerRNA *p
return ctx;
}
bContextStore *CTX_store_add_all(ListBase *contexts, bContextStore *context)
{
bContextStoreEntry *entry, *tentry;
bContextStore *ctx, *lastctx;
/* ensure we have a context to put the entries in, if it was already used
* we have to copy the context to ensure */
ctx= contexts->last;
if (!ctx || ctx->used) {
if (ctx) {
lastctx= ctx;
ctx= MEM_dupallocN(lastctx);
BLI_duplicatelist(&ctx->entries, &lastctx->entries);
}
else
ctx= MEM_callocN(sizeof(bContextStore), "bContextStore");
BLI_addtail(contexts, ctx);
}
for (tentry= context->entries.first; tentry; tentry= tentry->next) {
entry= MEM_dupallocN(tentry);
BLI_addtail(&ctx->entries, entry);
}
return ctx;
}
void CTX_store_set(bContext *C, bContextStore *store)
{
C->wm.store= store;

@ -48,6 +48,7 @@ struct wmWindowManager;
struct wmOperator;
struct AutoComplete;
struct bContext;
struct bContextStore;
struct Panel;
struct PanelType;
struct PointerRNA;
@ -692,6 +693,7 @@ uiBlock *uiLayoutGetBlock(uiLayout *layout);
void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv);
void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr);
void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context);
const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
void uiLayoutOperatorButs(const struct bContext *C, struct uiLayout *layout, struct wmOperator *op, int (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align, const short flag);
struct MenuType *uiButGetMenuType(uiBut *but);

@ -2722,6 +2722,12 @@ void uiLayoutSetContextPointer(uiLayout *layout, const char *name, PointerRNA *p
layout->context = CTX_store_add(&block->contexts, name, ptr);
}
void uiLayoutContextCopy(uiLayout *layout, bContextStore *context)
{
uiBlock *block= layout->root->block;
layout->context= CTX_store_add_all(&block->contexts, context);
}
/* introspect funcs */
#include "BLI_dynstr.h"

@ -2404,16 +2404,18 @@ uiPopupBlockHandle *ui_popup_menu_create(bContext *C, ARegion *butregion, uiBut
/* some enums reversing is strange, currently we have no good way to
* reverse some enum's but not others, so reverse all so the first menu
* items are always close to the mouse cursor */
#if 0
else {
#if 0
/* if this is an rna button then we can assume its an enum
* flipping enums is generally not good since the order can be
* important [#28786] */
if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM) {
pup->block->flag |= UI_BLOCK_NO_FLIP;
}
}
#endif
if (but->context)
uiLayoutContextCopy(pup->layout, but->context);
}
if (str) {
/* menu is created from a string */