added CTX_wm_operator_poll_msg_get/set so failing poll functions can set messages when poll fails, at the moment only python uses this but theres nothing python specific.

only added 1 message to a poll function, so messages still need to be set in many more places to be useful.
This commit is contained in:
Campbell Barton 2010-09-27 12:21:23 +00:00
parent 11ce49830a
commit d6c8b41144
6 changed files with 25 additions and 3 deletions

View File

@ -163,6 +163,8 @@ void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */
void CTX_wm_area_set(bContext *C, struct ScrArea *sa);
void CTX_wm_region_set(bContext *C, struct ARegion *region);
void CTX_wm_menu_set(bContext *C, struct ARegion *menu);
const char *CTX_wm_operator_poll_msg_get(struct bContext *C);
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg);
/* Data Context

View File

@ -64,6 +64,7 @@ struct bContext {
struct ARegion *region;
struct ARegion *menu;
struct bContextStore *store;
const char *operator_poll_msg; /* reason for poll failing */
} wm;
/* data context */
@ -399,6 +400,16 @@ void CTX_wm_menu_set(bContext *C, ARegion *menu)
C->wm.menu= menu;
}
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
{
C->wm.operator_poll_msg= msg;
}
const char *CTX_wm_operator_poll_msg_get(bContext *C)
{
return C->wm.operator_poll_msg;
}
/* data context utility functions */
struct bContextDataResult {

View File

@ -131,7 +131,11 @@ int ED_operator_view3d_active(bContext *C)
int ED_operator_region_view3d_active(bContext *C)
{
return CTX_wm_region_view3d(C) != NULL;
if(CTX_wm_region_view3d(C))
return TRUE;
CTX_wm_operator_poll_msg_set(C, "expected a view3d region");
return FALSE;
}
int ED_operator_timeline_active(bContext *C)

View File

@ -1811,7 +1811,6 @@ static int view3d_zoom_border_invoke(bContext *C, wmOperator *op, wmEvent *event
void VIEW3D_OT_zoom_border(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Border Zoom";
ot->description = "Zoom in the view to the nearest object contained in the border";

View File

@ -127,7 +127,9 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
Py_XINCREF(context_dict); /* so we done loose it */
if(WM_operator_poll((bContext*)C, ot) == FALSE) {
PyErr_Format( PyExc_SystemError, "Operator bpy.ops.%.200s.poll() failed, context is incorrect", opname);
const char *msg= CTX_wm_operator_poll_msg_get(C);
PyErr_Format( PyExc_SystemError, "Operator bpy.ops.%.200s.poll() %s", opname, msg ? msg : "failed, context is incorrect");
CTX_wm_operator_poll_msg_set(C, NULL); /* better set to NULL else it could be used again */
error_val= -1;
}
else {

View File

@ -466,6 +466,8 @@ static int wm_operator_exec(bContext *C, wmOperator *op, int repeat)
wmWindowManager *wm= CTX_wm_manager(C);
int retval= OPERATOR_CANCELLED;
CTX_wm_operator_poll_msg_set(C, NULL);
if(op==NULL || op->type==NULL)
return retval;
@ -698,6 +700,8 @@ static int wm_operator_call_internal(bContext *C, wmOperatorType *ot, int contex
int retval;
CTX_wm_operator_poll_msg_set(C, NULL);
/* dummie test */
if(ot && C) {
switch(context) {