[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45375] trunk/blender/source/blender: Popup menu layout inherits context store from button.

Lukas Toenne lukas.toenne at googlemail.com
Tue Apr 3 17:19:05 CEST 2012


Revision: 45375
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45375
Author:   lukastoenne
Date:     2012-04-03 15:18:59 +0000 (Tue, 03 Apr 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_context.h
    trunk/blender/source/blender/blenkernel/intern/context.c
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_regions.c

Modified: trunk/blender/source/blender/blenkernel/BKE_context.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_context.h	2012-04-03 14:08:04 UTC (rev 45374)
+++ trunk/blender/source/blender/blenkernel/BKE_context.h	2012-04-03 15:18:59 UTC (rev 45375)
@@ -117,6 +117,7 @@
 /* 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);

Modified: trunk/blender/source/blender/blenkernel/intern/context.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/context.c	2012-04-03 14:08:04 UTC (rev 45374)
+++ trunk/blender/source/blender/blenkernel/intern/context.c	2012-04-03 15:18:59 UTC (rev 45375)
@@ -141,6 +141,35 @@
 	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;

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2012-04-03 14:08:04 UTC (rev 45374)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2012-04-03 15:18:59 UTC (rev 45375)
@@ -48,6 +48,7 @@
 struct wmOperator;
 struct AutoComplete;
 struct bContext;
+struct bContextStore;
 struct Panel;
 struct PanelType;
 struct PointerRNA;
@@ -692,6 +693,7 @@
 
 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);

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2012-04-03 14:08:04 UTC (rev 45374)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2012-04-03 15:18:59 UTC (rev 45375)
@@ -2722,7 +2722,13 @@
 	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"
 

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2012-04-03 14:08:04 UTC (rev 45374)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2012-04-03 15:18:59 UTC (rev 45375)
@@ -2404,16 +2404,18 @@
 	/* 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 */
+	else {
 #if 0
-	else {
 		/* 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);
 	}
-#endif
 
 	if (str) {
 		/* menu is created from a string */




More information about the Bf-blender-cvs mailing list