[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18725] branches/blender2.5/blender/source /blender: 2.5:
Brecht Van Lommel
brecht at blender.org
Thu Jan 29 00:29:32 CET 2009
Revision: 18725
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18725
Author: blendix
Date: 2009-01-29 00:29:27 +0100 (Thu, 29 Jan 2009)
Log Message:
-----------
2.5:
* Automatic shortcut keys in menus now compare operator properties as well.
Implemented IDP_EqualsProperties for this.
* I imagine all these compares may be a bit slow, for this case it's not
so bad though because it only happens for one menu when it is opened.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h
branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c
branches/blender2.5/blender/source/blender/editors/interface/interface.c
branches/blender2.5/blender/source/blender/editors/space_image/image_header.c
branches/blender2.5/blender/source/blender/windowmanager/WM_api.h
branches/blender2.5/blender/source/blender/windowmanager/intern/wm_keymap.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h 2009-01-28 22:51:42 UTC (rev 18724)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_idprop.h 2009-01-28 23:29:27 UTC (rev 18725)
@@ -142,6 +142,8 @@
struct IDProperty *IDP_GetProperties(struct ID *id, int create_if_needed);
struct IDProperty *IDP_CopyProperty(struct IDProperty *prop);
+int IDP_EqualsProperties(struct IDProperty *prop1, struct IDProperty *prop2);
+
/*
Allocate a new ID.
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c 2009-01-28 22:51:42 UTC (rev 18724)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c 2009-01-28 23:29:27 UTC (rev 18725)
@@ -527,6 +527,60 @@
}
}
+int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2)
+{
+ if(prop1 == NULL && prop2 == NULL)
+ return 1;
+ else if(prop1 == NULL || prop2 == NULL)
+ return 0;
+ else if(prop1->type != prop2->type)
+ return 0;
+
+ if(prop1->type == IDP_INT)
+ return (IDP_Int(prop1) == IDP_Int(prop2));
+ else if(prop1->type == IDP_FLOAT)
+ return (IDP_Float(prop1) == IDP_Float(prop2));
+ else if(prop1->type == IDP_DOUBLE)
+ return (IDP_Double(prop1) == IDP_Double(prop2));
+ else if(prop1->type == IDP_STRING)
+ return BSTR_EQ(IDP_String(prop1), IDP_String(prop2));
+ else if(prop1->type == IDP_ARRAY) {
+ if(prop1->len == prop2->len && prop1->subtype == prop2->subtype)
+ return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[prop1->subtype]*prop1->len);
+ else
+ return 0;
+ }
+ else if(prop1->type == IDP_GROUP) {
+ IDProperty *link1, *link2;
+
+ if(BLI_countlist(&prop1->data.group) != BLI_countlist(&prop2->data.group))
+ return 0;
+
+ for(link1=prop1->data.group.first; link1; link1=link1->next) {
+ link2= IDP_GetPropertyFromGroup(prop2, link1->name);
+
+ if(!IDP_EqualsProperties(link1, link2))
+ return 0;
+ }
+
+ return 1;
+ }
+ else if(prop1->type == IDP_IDPARRAY) {
+ IDProperty *array1= IDP_IDPArray(prop1);
+ IDProperty *array2= IDP_IDPArray(prop2);
+ int i;
+
+ if(prop1->len != prop2->len)
+ return 0;
+
+ for(i=0; i<prop1->len; i++)
+ if(!IDP_EqualsProperties(&array1[i], &array2[i]))
+ return 0;
+ }
+
+ return 1;
+}
+
IDProperty *IDP_New(int type, IDPropertyTemplate val, const char *name)
{
IDProperty *prop=NULL;
Modified: branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c 2009-01-28 22:51:42 UTC (rev 18724)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c 2009-01-28 23:29:27 UTC (rev 18725)
@@ -482,13 +482,15 @@
static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
{
uiBut *but;
+ IDProperty *prop;
char buf[512], *butstr;
+ int bounds= 0;;
- /* XXX bounds? */
for(but=block->buttons.first; but; but=but->next) {
- /* only hotkey for menus without properties */
- if(but->opname && but->opptr==NULL) {
- if(WM_key_event_operator_string(C, but->opname, but->opcontext, buf, sizeof(buf))) {
+ if(but->opname) {
+ prop= (but->opptr)? but->opptr->data: NULL;
+
+ if(WM_key_event_operator_string(C, but->opname, but->opcontext, prop, buf, sizeof(buf))) {
butstr= MEM_mallocN(strlen(but->str)+strlen(buf)+2, "menu_block_set_keymaps");
strcpy(butstr, but->str);
strcat(butstr, "|");
@@ -499,9 +501,14 @@
MEM_freeN(butstr);
ui_check_but(but);
+ bounds= 1;
}
}
}
+
+ // XXX not nice ..
+ if(bounds)
+ uiTextBoundsBlock(block, 50);
}
void uiEndBlock(const bContext *C, uiBlock *block)
Modified: branches/blender2.5/blender/source/blender/editors/space_image/image_header.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_image/image_header.c 2009-01-28 22:51:42 UTC (rev 18724)
+++ branches/blender2.5/blender/source/blender/editors/space_image/image_header.c 2009-01-28 23:29:27 UTC (rev 18725)
@@ -112,6 +112,7 @@
/* position menu */
uiBlockSetDirection(block, UI_RIGHT);
uiTextBoundsBlock(block, 50);
+ uiEndBlock(C, block);
return block;
}
Modified: branches/blender2.5/blender/source/blender/windowmanager/WM_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/WM_api.h 2009-01-28 22:51:42 UTC (rev 18724)
+++ branches/blender2.5/blender/source/blender/windowmanager/WM_api.h 2009-01-28 23:29:27 UTC (rev 18725)
@@ -81,7 +81,7 @@
int spaceid, int regionid);
char *WM_key_event_string(short type);
-char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, char *str, int len);
+char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, char *str, int len);
/* handlers */
Modified: branches/blender2.5/blender/source/blender/windowmanager/intern/wm_keymap.c
===================================================================
--- branches/blender2.5/blender/source/blender/windowmanager/intern/wm_keymap.c 2009-01-28 22:51:42 UTC (rev 18724)
+++ branches/blender2.5/blender/source/blender/windowmanager/intern/wm_keymap.c 2009-01-28 23:29:27 UTC (rev 18725)
@@ -37,6 +37,7 @@
#include "BKE_blender.h"
#include "BKE_context.h"
+#include "BKE_idprop.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_utildefines.h"
@@ -507,13 +508,35 @@
return str;
}
-char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, char *str, int len)
+static char *wm_keymap_item_find(ListBase *handlers, const char *opname, int opcontext, IDProperty *properties, char *str, int len)
{
wmEventHandler *handler;
wmKeymapItem *kmi;
- ListBase *handlers= NULL;
- /* find right handler list based on specified context */
+ /* find keymap item in handlers */
+ for(handler=handlers->first; handler; handler=handler->next)
+ if(handler->keymap)
+ for(kmi=handler->keymap->first; kmi; kmi=kmi->next)
+ if(strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0])
+ if(kmi->ptr && IDP_EqualsProperties(properties, kmi->ptr->data))
+ return wm_keymap_item_to_string(kmi, str, len);
+
+ return NULL;
+}
+
+char *WM_key_event_operator_string(const bContext *C, const char *opname, int opcontext, IDProperty *properties, char *str, int len)
+{
+ char *found= NULL;
+
+ /* look into multiple handler lists to find the item */
+ if(CTX_wm_window(C))
+ if((found= wm_keymap_item_find(&CTX_wm_window(C)->handlers, opname, opcontext, properties, str, len)))
+ return found;
+
+ if(CTX_wm_area(C))
+ if((found= wm_keymap_item_find(&CTX_wm_area(C)->handlers, opname, opcontext, properties, str, len)))
+ return found;
+
if(ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
if(CTX_wm_area(C)) {
ARegion *ar= CTX_wm_area(C)->regionbase.first;
@@ -522,32 +545,16 @@
break;
if(ar)
- handlers= &ar->handlers;
+ if((found= wm_keymap_item_find(&ar->handlers, opname, opcontext, properties, str, len)))
+ return found;
}
}
- else if(ELEM(opcontext, WM_OP_EXEC_AREA, WM_OP_INVOKE_AREA)) {
- if(CTX_wm_area(C))
- handlers= &CTX_wm_area(C)->handlers;
- }
- else if(ELEM(opcontext, WM_OP_EXEC_SCREEN, WM_OP_INVOKE_SCREEN)) {
- if(CTX_wm_window(C))
- handlers= &CTX_wm_window(C)->handlers;
- }
else {
if(CTX_wm_region(C))
- handlers= &CTX_wm_region(C)->handlers;
+ if((found= wm_keymap_item_find(&CTX_wm_region(C)->handlers, opname, opcontext, properties, str, len)))
+ return found;
}
- if(!handlers)
- return NULL;
-
- /* find keymap item in handlers */
- for(handler=handlers->first; handler; handler=handler->next)
- if(handler->keymap)
- for(kmi=handler->keymap->first; kmi; kmi=kmi->next)
- if(strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0])
- return wm_keymap_item_to_string(kmi, str, len);
-
return NULL;
}
More information about the Bf-blender-cvs
mailing list