Add poll message when poll fails because of window missing from the context.
This means calling invoke operators from python in states that dont support will give a meaningful error message. also reduce context lookups when polling.
This commit is contained in:
@@ -821,8 +821,12 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (done == false) {
|
if (done == false) {
|
||||||
if (item) printf("PyContext '%s' not a valid type\n", member);
|
if (item) {
|
||||||
else printf("PyContext '%s' not found\n", member);
|
printf("PyContext '%s' not a valid type\n", member);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("PyContext '%s' not found\n", member);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (G.debug & G_DEBUG_PYTHON) {
|
if (G.debug & G_DEBUG_PYTHON) {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ static void wm_notifier_clear(wmNotifier *note);
|
|||||||
static void update_tablet_data(wmWindow *win, wmEvent *event);
|
static void update_tablet_data(wmWindow *win, wmEvent *event);
|
||||||
|
|
||||||
static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports,
|
static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports,
|
||||||
short context, short poll_only);
|
const short context, const bool poll_only);
|
||||||
|
|
||||||
/* ************ event management ************** */
|
/* ************ event management ************** */
|
||||||
|
|
||||||
@@ -963,9 +963,8 @@ int WM_operator_last_properties_store(wmOperator *UNUSED(op))
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event,
|
static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event,
|
||||||
PointerRNA *properties, ReportList *reports, short poll_only)
|
PointerRNA *properties, ReportList *reports, const bool poll_only)
|
||||||
{
|
{
|
||||||
wmWindowManager *wm = CTX_wm_manager(C);
|
|
||||||
int retval = OPERATOR_PASS_THROUGH;
|
int retval = OPERATOR_PASS_THROUGH;
|
||||||
|
|
||||||
/* this is done because complicated setup is done to call this function that is better not duplicated */
|
/* this is done because complicated setup is done to call this function that is better not duplicated */
|
||||||
@@ -973,6 +972,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event,
|
|||||||
return WM_operator_poll(C, ot);
|
return WM_operator_poll(C, ot);
|
||||||
|
|
||||||
if (WM_operator_poll(C, ot)) {
|
if (WM_operator_poll(C, ot)) {
|
||||||
|
wmWindowManager *wm = CTX_wm_manager(C);
|
||||||
wmOperator *op = wm_operator_create(wm, ot, properties, reports); /* if reports == NULL, they'll be initialized */
|
wmOperator *op = wm_operator_create(wm, ot, properties, reports); /* if reports == NULL, they'll be initialized */
|
||||||
const short is_nested_call = (wm->op_undo_depth != 0);
|
const short is_nested_call = (wm->op_undo_depth != 0);
|
||||||
|
|
||||||
@@ -1101,9 +1101,8 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event,
|
|||||||
*
|
*
|
||||||
* invokes operator in context */
|
* invokes operator in context */
|
||||||
static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports,
|
static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA *properties, ReportList *reports,
|
||||||
short context, short poll_only)
|
const short context, const bool poll_only)
|
||||||
{
|
{
|
||||||
wmWindow *window = CTX_wm_window(C);
|
|
||||||
wmEvent *event;
|
wmEvent *event;
|
||||||
|
|
||||||
int retval;
|
int retval;
|
||||||
@@ -1112,16 +1111,23 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, PointerRNA
|
|||||||
|
|
||||||
/* dummie test */
|
/* dummie test */
|
||||||
if (ot && C) {
|
if (ot && C) {
|
||||||
|
wmWindow *window = CTX_wm_window(C);
|
||||||
|
|
||||||
switch (context) {
|
switch (context) {
|
||||||
case WM_OP_INVOKE_DEFAULT:
|
case WM_OP_INVOKE_DEFAULT:
|
||||||
case WM_OP_INVOKE_REGION_WIN:
|
case WM_OP_INVOKE_REGION_WIN:
|
||||||
case WM_OP_INVOKE_AREA:
|
case WM_OP_INVOKE_AREA:
|
||||||
case WM_OP_INVOKE_SCREEN:
|
case WM_OP_INVOKE_SCREEN:
|
||||||
/* window is needed for invoke, cancel operator */
|
/* window is needed for invoke, cancel operator */
|
||||||
if (window == NULL)
|
if (window == NULL) {
|
||||||
|
if (poll_only) {
|
||||||
|
CTX_wm_operator_poll_msg_set(C, "missing 'window' in context");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
event = window->eventstate;
|
event = window->eventstate;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
event = NULL;
|
event = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user