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>2010-11-04 15:59:03 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-11-04 15:59:03 +0300
commit64ff9d6de40740866c290f1e1e88e6e22a1ca5e7 (patch)
tree00b710119c7a21088fda1d9f833afff5b965fc37 /source/blender/windowmanager
parent0e8172368356943e0bae95ec4a8d4ecdc9dba793 (diff)
fix to allow [#24009] to be fixed.
WM_operator_poll() could fail in cases WM_operator_name_call() would succeed because calling the operator would setup the context before calling poll. this would result in python raising an invalid error or menu items being greyed out. now python can also check with an operator context: bpy.ops.object.editmode_toggle.poll('INVOKE_SCREEN')
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h1
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c32
2 files changed, 23 insertions, 10 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 2a36e91ac66..7d4690ac7e1 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -218,6 +218,7 @@ struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *
int WM_operator_poll (struct bContext *C, struct wmOperatorType *ot);
+int WM_operator_poll_context(struct bContext *C, struct wmOperatorType *ot, int context);
int WM_operator_call (struct bContext *C, struct wmOperator *op);
int WM_operator_repeat (struct bContext *C, struct wmOperator *op);
int WM_operator_name_call (struct bContext *C, const char *opstring, int context, struct PointerRNA *properties);
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index ed1caa5fafe..910a528d419 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -72,6 +72,8 @@
#include "wm_event_types.h"
#include "wm_draw.h"
+static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports, short context, short poll_only);
+
/* ************ event management ************** */
void wm_event_add(wmWindow *win, wmEvent *event_to_add)
@@ -379,6 +381,12 @@ int WM_operator_poll(bContext *C, wmOperatorType *ot)
return 1;
}
+/* sets up the new context and calls 'wm_operator_invoke()' with poll_only */
+int WM_operator_poll_context(bContext *C, wmOperatorType *ot, int context)
+{
+ return wm_operator_call_internal(C, ot, NULL, NULL, context, TRUE);
+}
+
static void wm_operator_print(wmOperator *op)
{
char *buf = WM_operator_pystring(NULL, op->type, op->ptr, 1);
@@ -603,11 +611,15 @@ static void wm_region_mouse_co(bContext *C, wmEvent *event)
}
}
-int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties, ReportList *reports)
+int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties, ReportList *reports, short poll_only)
{
wmWindowManager *wm= CTX_wm_manager(C);
int retval= OPERATOR_PASS_THROUGH;
+ /* this is done because complicated setup is done to call this function that is better not duplicated */
+ if(poll_only)
+ return WM_operator_poll(C, ot);
+
if(WM_operator_poll(C, ot)) {
wmOperator *op= wm_operator_create(wm, ot, properties, reports); /* if reports==NULL, theyll be initialized */
@@ -693,7 +705,7 @@ int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerR
* this is for python to access since its done the operator lookup
*
* invokes operator in context */
-static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int context, PointerRNA *properties, ReportList *reports)
+static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports, short context, short poll_only)
{
wmWindow *window= CTX_wm_window(C);
wmEvent *event;
@@ -758,7 +770,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex
CTX_wm_region_set(C, ar1);
}
- retval= wm_operator_invoke(C, ot, event, properties, reports);
+ retval= wm_operator_invoke(C, ot, event, properties, reports, poll_only);
/* set region back */
CTX_wm_region_set(C, ar);
@@ -772,7 +784,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex
ARegion *ar= CTX_wm_region(C);
CTX_wm_region_set(C, NULL);
- retval= wm_operator_invoke(C, ot, event, properties, reports);
+ retval= wm_operator_invoke(C, ot, event, properties, reports, poll_only);
CTX_wm_region_set(C, ar);
return retval;
@@ -786,7 +798,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex
CTX_wm_region_set(C, NULL);
CTX_wm_area_set(C, NULL);
- retval= wm_operator_invoke(C, ot, event, properties, reports);
+ retval= wm_operator_invoke(C, ot, event, properties, reports, poll_only);
CTX_wm_region_set(C, ar);
CTX_wm_area_set(C, area);
@@ -794,7 +806,7 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex
}
case WM_OP_EXEC_DEFAULT:
case WM_OP_INVOKE_DEFAULT:
- return wm_operator_invoke(C, ot, event, properties, reports);
+ return wm_operator_invoke(C, ot, event, properties, reports, poll_only);
}
}
@@ -807,7 +819,7 @@ int WM_operator_name_call(bContext *C, const char *opstring, int context, Pointe
{
wmOperatorType *ot= WM_operatortype_find(opstring, 0);
if(ot)
- return wm_operator_call_internal(C, ot, context, properties, NULL);
+ return wm_operator_call_internal(C, ot, properties, NULL, context, FALSE);
return 0;
}
@@ -839,7 +851,7 @@ int WM_operator_call_py(bContext *C, wmOperatorType *ot, int context, PointerRNA
printf("error \"%s\" operator has no exec function, python cannot call it\n", op->type->name);
#endif
- retval= wm_operator_call_internal(C, ot, context, properties, reports);
+ retval= wm_operator_call_internal(C, ot, properties, reports, context, FALSE);
/* keep the reports around if needed later */
if ( (retval & OPERATOR_RUNNING_MODAL) ||
@@ -1168,7 +1180,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
wmOperatorType *ot= WM_operatortype_find(event->keymap_idname, 0);
if(ot)
- retval= wm_operator_invoke(C, ot, event, properties, NULL);
+ retval= wm_operator_invoke(C, ot, event, properties, NULL, FALSE);
}
/* Finished and pass through flag as handled */
@@ -1421,7 +1433,7 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers)
if(drop->poll(C, drag, event)) {
drop->copy(drag, drop);
- wm_operator_invoke(C, drop->ot, event, drop->ptr, NULL);
+ wm_operator_invoke(C, drop->ot, event, drop->ptr, NULL, FALSE);
action |= WM_HANDLER_BREAK;
}
}