[Bf-blender-cvs] [32396b31645] blender2.8: WM: support for filtering modal keymap items

Campbell Barton noreply at git.blender.org
Mon Jul 9 08:42:27 CEST 2018


Commit: 32396b316455c5b207b1103f03ddc4c8e81cfd00
Author: Campbell Barton
Date:   Mon Jul 9 08:39:09 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB32396b316455c5b207b1103f03ddc4c8e81cfd00

WM: support for filtering modal keymap items

Modal keymap display often shows items which aren't used,
add a poll funciton to hide these from the status bar.

===================================================================

M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index bd2811d3306..80ad3840a8f 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -331,6 +331,8 @@ typedef struct wmKeyMap {
 	/* runtime */
 	/** Verify if enabled in the current context, use #WM_keymap_poll instead of direct calls. */
 	bool (*poll)(struct bContext *);
+	bool (*poll_modal_item)(const struct wmOperator *op, int value);
+
 	/** For modal, #EnumPropertyItem for now. */
 	const void *modal_items;
 } wmKeyMap;
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 4f5578e452d..7e2198eed7a 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -4524,14 +4524,14 @@ bool WM_window_modal_keymap_status_draw(
         uiLayout *layout)
 {
 	wmKeyMap *keymap = NULL;
-	wmOperatorType *ot = NULL;
+	wmOperator *op = NULL;
 	for (wmEventHandler *handler = win->modalhandlers.first; handler; handler = handler->next) {
 		if (handler->op) {
 			/* 'handler->keymap' could be checked too, seems not to be used. */
 			wmKeyMap *keymap_test = handler->op->type->modalkeymap;
 			if (keymap_test && keymap_test->modal_items) {
 				keymap = keymap_test;
-				ot = handler->op->type;
+				op = handler->op;
 				break;
 			}
 		}
@@ -4546,6 +4546,11 @@ bool WM_window_modal_keymap_status_draw(
 		if (!items[i].identifier[0]) {
 			continue;
 		}
+		if ((keymap->poll_modal_item != NULL) &&
+		    (keymap->poll_modal_item(op, items[i].value) == false))
+		{
+			continue;
+		}
 
 		bool show_text = true;
 
@@ -4577,7 +4582,8 @@ bool WM_window_modal_keymap_status_draw(
 			char buf[UI_MAX_DRAW_STR];
 			int available_len = sizeof(buf);
 			char *p = buf;
-			WM_modalkeymap_operator_items_to_string_buf(ot, items[i].value, true, UI_MAX_SHORTCUT_STR, &available_len, &p);
+			WM_modalkeymap_operator_items_to_string_buf(
+			        op->type, items[i].value, true, UI_MAX_SHORTCUT_STR, &available_len, &p);
 			p -= 1;
 			if (p > buf) {
 				BLI_snprintf(p, available_len, ": %s", items[i].name);



More information about the Bf-blender-cvs mailing list