WM: store modal operator last-properties
authorCampbell Barton <ideasman42@gmail.com>
Mon, 16 Oct 2017 05:35:22 +0000 (16:35 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 16 Oct 2017 05:38:02 +0000 (16:38 +1100)
Avoids modal operators needing to explicitly store them.

source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index a6777d403980ac875f5ce507e8a3077e2888332b..6ebe1671afc3e0edad9ed40cfe398310bdd506ec 100644 (file)
@@ -744,12 +744,16 @@ static bool wm_operator_register_check(wmWindowManager *wm, wmOperatorType *ot)
        return wm && (wm->op_undo_depth == 0) && (ot->flag & (OPTYPE_REGISTER | OPTYPE_UNDO));
 }
 
-static void wm_operator_finished(bContext *C, wmOperator *op, const bool repeat)
+static void wm_operator_finished(bContext *C, wmOperator *op, const bool repeat, const bool store)
 {
        wmWindowManager *wm = CTX_wm_manager(C);
 
        op->customdata = NULL;
 
+       if (store) {
+               WM_operator_last_properties_store(op);
+       }
+
        /* we don't want to do undo pushes for operators that are being
         * called from operators that already do an undo push. usually
         * this will happen for python operators that call C operators */
@@ -812,12 +816,7 @@ static int wm_operator_exec(bContext *C, wmOperator *op, const bool repeat, cons
                wm_operator_reports(C, op, retval, false);
        
        if (retval & OPERATOR_FINISHED) {
-               if (store) {
-                       if (wm->op_undo_depth == 0) { /* not called by py script */
-                               WM_operator_last_properties_store(op);
-                       }
-               }
-               wm_operator_finished(C, op, repeat);
+               wm_operator_finished(C, op, repeat, store && wm->op_undo_depth == 0);
        }
        else if (repeat == 0) {
                /* warning: modal from exec is bad practice, but avoid crashing. */
@@ -1173,10 +1172,8 @@ static int wm_operator_invoke(
                        /* do nothing, wm_operator_exec() has been called somewhere */
                }
                else if (retval & OPERATOR_FINISHED) {
-                       if (!is_nested_call) { /* not called by py script */
-                               WM_operator_last_properties_store(op);
-                       }
-                       wm_operator_finished(C, op, 0);
+                       const bool store = !is_nested_call;
+                       wm_operator_finished(C, op, false, store);
                }
                else if (retval & OPERATOR_RUNNING_MODAL) {
                        /* take ownership of reports (in case python provided own) */
@@ -1752,7 +1749,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
 
                                /* important to run 'wm_operator_finished' before NULLing the context members */
                                if (retval & OPERATOR_FINISHED) {
-                                       wm_operator_finished(C, op, 0);
+                                       wm_operator_finished(C, op, false, true);
                                        handler->op = NULL;
                                }
                                else if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
index e4776ea7b29dc32963dcf94804b5217c974a9b72..307c8b24c1ed1a0bb556d0f0cce79469d58cccf3 100644 (file)
@@ -2491,9 +2491,6 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
                        }
                        case GESTURE_MODAL_CANCEL:
                        case GESTURE_MODAL_CONFIRM:
-                               /* Normally we wouldn't store last-properties on cancel,
-                                * this is an exception since the circle tool is modal. */
-                               WM_operator_last_properties_store(op);
                                wm_gesture_end(C, op);
                                return OPERATOR_FINISHED; /* use finish or we don't get an undo */
                }