Moved 'redo last operator' stuff to WM level, with a 

  WM_operator_repeat()

Code in screen_ops was not checking all operator stuff
correctly, so repeat menu (F3 now) crashed in cases.
This commit is contained in:
Ton Roosendaal
2009-02-01 12:00:00 +00:00
parent b3c3af2156
commit 00e2d763ff
4 changed files with 45 additions and 34 deletions

View File

@@ -1321,15 +1321,8 @@ static int repeat_last_exec(bContext *C, wmOperator *op)
{
wmOperator *lastop= CTX_wm_manager(C)->operators.last;
if(lastop) {
if(lastop->type->poll==NULL || lastop->type->poll(C)) {
if(lastop->type->exec) {
printf("repeat %s\n", lastop->type->idname);
lastop->type->exec(C, lastop);
return OPERATOR_FINISHED;
}
}
}
if(lastop)
WM_operator_repeat(C, lastop);
return OPERATOR_CANCELLED;
}
@@ -1380,10 +1373,7 @@ static int repeat_history_exec(bContext *C, wmOperator *op)
BLI_remlink(&wm->operators, op);
BLI_addtail(&wm->operators, op);
if(op->type->poll==NULL || op->type->poll(C)) {
printf("repeat %s\n", op->type->idname);
op->type->exec(C, op);
}
WM_operator_repeat(C, op);
}
return OPERATOR_FINISHED;

View File

@@ -133,6 +133,7 @@ void WM_operatortype_append_ptr (void (*opfunc)(wmOperatorType*, void *), void
int WM_operatortype_remove(const char *idname);
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);
int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *properties, struct ReportList *reports);

View File

@@ -196,21 +196,20 @@ void wm_event_do_notifiers(bContext *C)
/* ********************* operators ******************* */
static void WM_operator_print(wmOperator *op)
{
char *buf = WM_operator_pystring(op);
printf("%s\n", buf);
MEM_freeN(buf);
}
/* for running operators with frozen context (modal handlers, menus) */
int WM_operator_call(bContext *C, wmOperator *op)
/* if repeat is true, it doesn't register again, nor does it free */
static int wm_operator_exec(bContext *C, wmOperator *op, int repeat)
{
int retval= OPERATOR_CANCELLED;
if(op==NULL || op->type==NULL)
return retval;
if(op->type->poll && op->type->poll(C)==0)
return retval;
if(op->type->exec)
retval= op->type->exec(C, op);
if(!(retval & OPERATOR_RUNNING_MODAL))
if(op->reports->list.first)
uiPupMenuReports(C, op->reports);
@@ -219,17 +218,31 @@ int WM_operator_call(bContext *C, wmOperator *op)
if(op->type->flag & OPTYPE_UNDO)
ED_undo_push_op(C, op);
if(op->type->flag & OPTYPE_REGISTER)
wm_operator_register(CTX_wm_manager(C), op);
else
WM_operator_free(op);
if(repeat==0) {
if(op->type->flag & OPTYPE_REGISTER)
wm_operator_register(CTX_wm_manager(C), op);
else
WM_operator_free(op);
}
}
else
else if(repeat==0)
WM_operator_free(op);
return retval;
}
/* for running operators with frozen context (modal handlers, menus) */
int WM_operator_call(bContext *C, wmOperator *op)
{
return wm_operator_exec(C, op, 0);
}
/* do this operator again, put here so it can share above code */
int WM_operator_repeat(bContext *C, wmOperator *op)
{
return wm_operator_exec(C, op, 1);
}
static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, PointerRNA *properties, ReportList *reports)
{
@@ -262,6 +275,13 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P
return op;
}
static void wm_operator_print(wmOperator *op)
{
char *buf = WM_operator_pystring(op);
printf("%s\n", buf);
MEM_freeN(buf);
}
static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties)
{
wmWindowManager *wm= CTX_wm_manager(C);
@@ -284,9 +304,9 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
if(op->reports->list.first) /* only show the report if the report list was not given in the function */
uiPupMenuReports(C, op->reports);
if (retval & OPERATOR_FINISHED) /* todo - this may conflict with the other WM_operator_print, if theres ever 2 prints for 1 action will may need to add modal check here */
if (retval & OPERATOR_FINISHED) /* todo - this may conflict with the other wm_operator_print, if theres ever 2 prints for 1 action will may need to add modal check here */
if(G.f & G_DEBUG)
WM_operator_print(op);
wm_operator_print(op);
}
if(retval & OPERATOR_FINISHED) {
@@ -581,7 +601,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
if (retval & OPERATOR_FINISHED) {
if(G.f & G_DEBUG)
WM_operator_print(op); /* todo - this print may double up, might want to check more flags then the FINISHED */
wm_operator_print(op); /* todo - this print may double up, might want to check more flags then the FINISHED */
}
if(retval & OPERATOR_FINISHED) {

View File

@@ -76,13 +76,13 @@ enum {
/* wm_event_system.c */
void wm_event_add(wmWindow *win, wmEvent *event_to_add);
void wm_event_add (wmWindow *win, wmEvent *event_to_add);
void wm_event_free_all (wmWindow *win);
/* goes over entire hierarchy: events -> window -> screen -> area -> region */
void wm_event_do_handlers (bContext *C);
void wm_event_add_ghostevent(wmWindow *win, int type, void *customdata);
void wm_event_add_ghostevent (wmWindow *win, int type, void *customdata);
void wm_event_do_notifiers (bContext *C);