Undo System: remove nested edit-mode undo calls
authorCampbell Barton <ideasman42@gmail.com>
Tue, 15 May 2018 08:02:01 +0000 (10:02 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 15 May 2018 08:10:48 +0000 (10:10 +0200)
Regression in recent undo system changes,
This caused T55048.

When each mode had its own undo stack it was important
to initialize it when entering edit-mode.

source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/curve/editcurve_add.c
source/blender/editors/include/ED_object.h
source/blender/editors/mesh/editmesh_add.c
source/blender/editors/mesh/mesh_navmesh.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/space_outliner/outliner_select.c
source/blender/editors/space_outliner/outliner_tools.c

index 20904ed0263dcdcf44ce5113f6c57feeb55200c0..301124c4dfaed13475c96f05b025625a90822884 100644 (file)
@@ -2720,8 +2720,9 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index,
                                        adt->flag |= ADT_UI_ACTIVE;
 
                                /* ensure we exit editmode on whatever object was active before to avoid getting stuck there - T48747 */
-                               if (ob != sce->obedit)
-                                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+                               if (ob != sce->obedit) {
+                                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
+                               }
 
                                notifierFlags |= (ND_ANIMCHAN | NA_SELECTED);
                        }
index b23f0f967ec79d1b4ce2063f1a594da31fc7213e..a91b58f1e6559722e434167aa0f4bbee1421c5ca 100644 (file)
@@ -516,10 +516,6 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
                }
        }
 
-       /* ED_object_add_type doesnt do an undo, is needed for redo operator on primitive */
-       if (newob && enter_editmode)
-               ED_undo_push(C, "Enter Editmode");
-
        ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
        dia = RNA_float_get(op->ptr, "radius");
        mul_mat3_m4_fl(mat, dia);
index 2087394b6f68d084d47d69cabc1bbcaa69447c54..614be5dd0c1e9730171c7a19ec2aa8540b9ae6e3 100644 (file)
@@ -115,10 +115,9 @@ void ED_object_parent(struct Object *ob, struct Object *parent, const int type,
 enum {
        EM_FREEDATA         = (1 << 0),
        EM_WAITCURSOR       = (1 << 1),
-       EM_DO_UNDO          = (1 << 2),
        EM_IGNORE_LAYER     = (1 << 3),
 };
-void ED_object_editmode_exit_ex(struct bContext *C, struct Scene *scene, struct Object *obedit, int flag);
+void ED_object_editmode_exit_ex(struct Scene *scene, struct Object *obedit, int flag);
 void ED_object_editmode_exit(struct bContext *C, int flag);
 void ED_object_editmode_enter(struct bContext *C, int flag);
 bool ED_object_editmode_load(struct Object *obedit);
index 22cb28f0b1b84caa6026814a30972a7778f5f3f6..9bea203e67b6f109d38584da94108b2fcbe03c90 100644 (file)
@@ -72,7 +72,7 @@ static Object *make_prim_init(
                obedit = ED_object_add_type(C, OB_MESH, idname, loc, rot, false, layer);
 
                /* create editmode */
-               ED_object_editmode_enter(C, EM_DO_UNDO | EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
+               ED_object_editmode_enter(C, EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
                *was_editmode = true;
        }
 
@@ -95,7 +95,7 @@ static void make_prim_finish(bContext *C, Object *obedit, bool was_editmode, int
 
        /* userdef */
        if (exit_editmode) {
-               ED_object_editmode_exit(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */
+               ED_object_editmode_exit(C, EM_FREEDATA);
        }
        WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit);
 }
index 0f1884f40173fc66a247ebcc8bea5d2da847fde3..0d6c7320a9547aff512eb2c12face7a5dce0654d 100644 (file)
@@ -358,7 +358,7 @@ static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh,
                copy_v3_v3(obedit->rot, rot);
        }
 
-       ED_object_editmode_enter(C, EM_DO_UNDO | EM_IGNORE_LAYER);
+       ED_object_editmode_enter(C, EM_IGNORE_LAYER);
        em = BKE_editmesh_from_object(obedit);
 
        if (!createob) {
index eeeb3c058d090eaa190455403db03fc9d8b37ac1..101b5d4920d2ced848dca1e061fba21c86e58d9a 100644 (file)
@@ -411,8 +411,9 @@ Object *ED_object_add_type(
        Object *ob;
 
        /* for as long scene has editmode... */
-       if (CTX_data_edit_object(C)) 
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);  /* freedata, and undo */
+       if (CTX_data_edit_object(C)) {
+               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
+       }
 
        /* deselects all, sets scene->basact */
        ob = BKE_object_add(bmain, scene, type, name);
index 844ed1681572652ab48f6323227e39007234604e..a01a671ec98f9cf85ce6ed41ec59c4152ddd6d5e 100644 (file)
@@ -444,14 +444,11 @@ bool ED_object_editmode_load(Object *obedit)
 }
 
 /**
- * \param C: Can be NULL, only if #EM_DO_UNDO isn't set.
  * \param flag:
- * - Only in exceptional cases should #EM_DO_UNDO NOT be in the flag.
  * - If #EM_FREEDATA isn't in the flag, use ED_object_editmode_load directly.
  */
-void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int flag)
+void ED_object_editmode_exit_ex(Scene *scene, Object *obedit, int flag)
 {
-       BLI_assert(C || !(flag & EM_DO_UNDO));
        const bool freedata = (flag & EM_FREEDATA) != 0;
 
        if (flag & EM_WAITCURSOR) waitcursor(1);
@@ -486,16 +483,8 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f
 
                /* also flush ob recalc, doesn't take much overhead, but used for particles */
                DAG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
-       
-               if (flag & EM_DO_UNDO)
-                       ED_undo_push(C, "Editmode");
 
-               if (C != NULL) {
-                       WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
-               }
-               else {
-                       WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
-               }
+               WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
 
                obedit->mode &= ~OB_MODE_EDIT;
        }
@@ -507,7 +496,7 @@ void ED_object_editmode_exit(bContext *C, int flag)
 {
        Scene *scene = CTX_data_scene(C);
        Object *obedit = CTX_data_edit_object(C);
-       ED_object_editmode_exit_ex(C, scene, obedit, flag);
+       ED_object_editmode_exit_ex(scene, obedit, flag);
 }
 
 void ED_object_editmode_enter(bContext *C, int flag)
@@ -638,7 +627,6 @@ void ED_object_editmode_enter(bContext *C, int flag)
                WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
        }
 
-       if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
        if (flag & EM_WAITCURSOR) waitcursor(0);
 }
 
@@ -655,11 +643,12 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op)
                }
        }
 
-       if (!is_mode_set)
+       if (!is_mode_set) {
                ED_object_editmode_enter(C, EM_WAITCURSOR);
-       else
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);  /* had EM_DO_UNDO but op flag calls undo too [#24685] */
-       
+       }
+       else {
+               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
+       }
        ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene);
 
        return OPERATOR_FINISHED;
@@ -713,7 +702,7 @@ static int posemode_exec(bContext *C, wmOperator *op)
 
        if (ob->type == OB_ARMATURE) {
                if (ob == CTX_data_edit_object(C)) {
-                       ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
+                       ED_object_editmode_exit(C, EM_FREEDATA);
                        is_mode_set = false;
                }
 
index 2cd8ee9223f33328cf3c08d46a788f4aae12c5cf..7630f913ec1bd2afaa746326ac29e996219aede8 100644 (file)
@@ -1381,9 +1381,10 @@ void ED_screen_set_scene(bContext *C, bScreen *screen, Scene *scene)
 
        if (screen == NULL)
                return;
-       
-       if (ed_screen_used(CTX_wm_manager(C), screen))
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
+
+       if (ed_screen_used(CTX_wm_manager(C), screen)) {
+               ED_object_editmode_exit(C, EM_FREEDATA);
+       }
 
        for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                if ((U.flag & USER_SCENEGLOBAL) || sc == screen) {
index 0b8724b4e28ac9a5229ca88e4879fa2b2cc5bd20..760673e5a5f39166fd14e794cabd5adf851daa0c 100644 (file)
@@ -241,7 +241,7 @@ static eOLDrawState tree_element_set_active_object(
        }
        
        if (ob != scene->obedit)
-               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+               ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
                
        return OL_DRAWSEL_NORMAL;
 }
@@ -715,7 +715,7 @@ static eOLDrawState tree_element_active_pose(
 
        if (set != OL_SETSEL_NONE) {
                if (scene->obedit) {
-                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
                }
                
                if (ob->mode & OB_MODE_POSE) {
index e8275d597a6073b292e90b23d27b9a8d5fe9ddb4..20e011d4c8f0ec191bb1338bdf95042c68f3b79c 100644 (file)
@@ -417,8 +417,9 @@ static void object_delete_cb(
                }
 
                // check also library later
-               if (scene->obedit == base->object)
-                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+               if (scene->obedit == base->object) {
+                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
+               }
                
                ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
                /* leave for ED_outliner_id_unref to handle */
@@ -873,7 +874,7 @@ static void object_delete_hierarchy_cb(
                /* Check also library later. */
                for (; obedit && (obedit != base->object); obedit = obedit->parent);
                if (obedit == base->object) {
-                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
+                       ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR);
                }
 
                outline_delete_hierarchy(C, reports, scene, base);