Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-11-01 00:29:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-11-01 00:29:32 +0400
commit1bcadda46b96e3e557aad1b0d2d53a0b4743b413 (patch)
tree3f749a30df330ced48905860da40b1ed21254f6e /source/blender/windowmanager/intern/wm_keymap.c
parent26541afc8b9bfa0b11ecd2dcdab120cfcfff5d92 (diff)
fix [#30910] Problems: Add Shortcut(s) for "Ctrl Tab" menu
comparing keymaps was too sloppy or too strict, now sloppy keymap comparison works by setting all the operator properties to their default values if they are not already set, then compare this with the keymap item (ignoring values missing from either one). ... this way any non default keymap setting wont match with an operator menu item which doesnt set this operator at all (a problem sighted in this bug report). developer notes: - IDP_EqualsProperties_ex() function adds an argument to treat missing members of either group to act as if there is a match. - WM_operator_properties_default() function to reset RNA values to their defaults. - add IDP_spit(), debug only function to print out ID properties.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_keymap.c')
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index bcddc984ed3..2781ec2d3df 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -816,7 +816,7 @@ char *WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len)
static wmKeyMapItem *wm_keymap_item_find_handlers(
const bContext *C, ListBase *handlers, const char *opname, int UNUSED(opcontext),
- IDProperty *properties, int compare_props, int hotkey, wmKeyMap **keymap_r)
+ IDProperty *properties, int is_strict, int hotkey, wmKeyMap **keymap_r)
{
wmWindowManager *wm = CTX_wm_manager(C);
wmEventHandler *handler;
@@ -834,9 +834,22 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(
if (hotkey)
if (!ISHOTKEY(kmi->type))
continue;
-
- if (compare_props) {
- if (kmi->ptr && IDP_EqualsProperties(properties, kmi->ptr->data)) {
+
+ if (properties) {
+
+ /* example of debugging keymaps */
+#if 0
+ if (kmi->ptr) {
+ if (strcmp("MESH_OT_rip_move", opname) == 0) {
+ printf("OPERATOR\n");
+ IDP_spit(properties);
+ printf("KEYMAP\n");
+ IDP_spit(kmi->ptr->data);
+ }
+ }
+#endif
+
+ if (kmi->ptr && IDP_EqualsProperties_ex(properties, kmi->ptr->data, is_strict)) {
if (keymap_r) *keymap_r = keymap;
return kmi;
}
@@ -857,7 +870,7 @@ static wmKeyMapItem *wm_keymap_item_find_handlers(
static wmKeyMapItem *wm_keymap_item_find_props(
const bContext *C, const char *opname, int opcontext,
- IDProperty *properties, int compare_props, int hotkey, wmKeyMap **keymap_r)
+ IDProperty *properties, int is_strict, int hotkey, wmKeyMap **keymap_r)
{
wmWindow *win = CTX_wm_window(C);
ScrArea *sa = CTX_wm_area(C);
@@ -866,10 +879,10 @@ static wmKeyMapItem *wm_keymap_item_find_props(
/* look into multiple handler lists to find the item */
if (win)
- found = wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
+ found = wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r);
if (sa && found == NULL)
- found = wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
+ found = wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r);
if (found == NULL) {
if (ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
@@ -878,7 +891,7 @@ static wmKeyMapItem *wm_keymap_item_find_props(
ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
if (ar)
- found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
+ found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r);
}
}
else if (ELEM(opcontext, WM_OP_EXEC_REGION_CHANNELS, WM_OP_INVOKE_REGION_CHANNELS)) {
@@ -886,18 +899,18 @@ static wmKeyMapItem *wm_keymap_item_find_props(
ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);
if (ar)
- found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
+ found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r);
}
else if (ELEM(opcontext, WM_OP_EXEC_REGION_PREVIEW, WM_OP_INVOKE_REGION_PREVIEW)) {
if (!(ar && ar->regiontype == RGN_TYPE_PREVIEW))
ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
if (ar)
- found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
+ found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r);
}
else {
if (ar)
- found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
+ found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r);
}
}
@@ -906,12 +919,28 @@ static wmKeyMapItem *wm_keymap_item_find_props(
static wmKeyMapItem *wm_keymap_item_find(
const bContext *C, const char *opname, int opcontext,
- IDProperty *properties, const short hotkey, const short sloppy, wmKeyMap **keymap_r)
+ IDProperty *properties, const short hotkey, const short UNUSED(sloppy), wmKeyMap **keymap_r)
{
wmKeyMapItem *found = wm_keymap_item_find_props(C, opname, opcontext, properties, 1, hotkey, keymap_r);
- if (!found && sloppy)
- found = wm_keymap_item_find_props(C, opname, opcontext, NULL, 0, hotkey, keymap_r);
+ if (!found && properties) {
+ wmOperatorType *ot = WM_operatortype_find(opname, TRUE);
+ if (ot) {
+ /* make a copy of the properties and set any unset props
+ * to their default values, so the ID property compare function succeeds */
+ PointerRNA opptr;
+ IDProperty *properties_default = IDP_CopyProperty(properties);
+
+ RNA_pointer_create(NULL, ot->srna, properties_default, &opptr);
+
+ if (WM_operator_properties_default(&opptr, TRUE)) {
+ found = wm_keymap_item_find_props(C, opname, opcontext, properties_default, 0, hotkey, keymap_r);
+ }
+
+ IDP_FreeProperty(properties_default);
+ MEM_freeN(properties_default);
+ }
+ }
return found;
}