2.5
authorTon Roosendaal <ton@blender.org>
Sun, 1 Feb 2009 12:00:00 +0000 (12:00 +0000)
committerTon Roosendaal <ton@blender.org>
Sun, 1 Feb 2009 12:00:00 +0000 (12:00 +0000)
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.

source/blender/editors/screen/screen_ops.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/wm_event_system.h

index 810e52af0e76a537ccf60c795cdef9c74e894e2d..66eda54f3da91db063e762ddc82fe134972ed98c 100644 (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;
index cf39f347060b9e825ea6db58afb7a23b1b7c4e3a..8840b7f73ab2214c96cc3f2319e8f73406ae5607 100644 (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);
 
index 6d18df40215db275ad99cc12b296cdc2fd7f4ff7..d8c1e8a58889bdcf43806cc10e4eba8b68a19b9e 100644 (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) {
index 5205c8c17e1aaa0f4af3e98591126b01b06dc61e..d6899d4747124e734d329c5ff7fe3259fbf632f5 100644 (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);