diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-10-30 12:24:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-10-30 12:50:22 +0300 |
commit | 3cc6b423b12b8c412892782928203c16b77be932 (patch) | |
tree | 62f86bbd8d2c5f58ebebaaeabf99da62fac8ee63 | |
parent | 8d2576fd295fc67e2b70c282117928173ec1af8a (diff) |
Object: use undo-group for object.switch_object
object.switch_object no longer adds multiple undo steps
from a user perspective.
-rw-r--r-- | source/blender/editors/object/object_modes.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c index 089bd5567a7..9eaa8f3d31b 100644 --- a/source/blender/editors/object/object_modes.c +++ b/source/blender/editors/object/object_modes.c @@ -445,37 +445,41 @@ static int object_switch_object_invoke(bContext *C, wmOperator *op, const wmEven return OPERATOR_CANCELLED; } - if (!ED_object_mode_set_ex(C, OB_MODE_OBJECT, true, op->reports)) { - return OPERATOR_CANCELLED; - } - - Object *ob_dst_orig = DEG_get_original_object(ob_dst); - Base *base = BKE_view_layer_base_find(view_layer, ob_dst_orig); - BKE_view_layer_base_deselect_all(view_layer); - BKE_view_layer_base_select_and_set_active(view_layer, base); - DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); - - /* FIXME: Do a single undo push. */ - ED_undo_push(C, "Change Active"); - - ob_dst_orig = DEG_get_original_object(ob_dst); - ED_object_mode_set_ex(C, last_mode, true, op->reports); - - /* Update the viewport rotation origin to the mouse cursor. */ - if (last_mode & OB_MODE_ALL_PAINT) { - float global_loc[3]; - if (ED_view3d_autodist_simple(ar, event->mval, global_loc, 0, NULL)) { - UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; - copy_v3_v3(ups->average_stroke_accum, global_loc); - ups->average_stroke_counter = 1; - ups->last_stroke_valid = true; + int retval = OPERATOR_CANCELLED; + + ED_undo_group_begin(C); + + if (ED_object_mode_set_ex(C, OB_MODE_OBJECT, true, op->reports)) { + Object *ob_dst_orig = DEG_get_original_object(ob_dst); + Base *base = BKE_view_layer_base_find(view_layer, ob_dst_orig); + BKE_view_layer_base_deselect_all(view_layer); + BKE_view_layer_base_select_and_set_active(view_layer, base); + DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); + + ED_undo_push(C, "Change Active"); + + ob_dst_orig = DEG_get_original_object(ob_dst); + ED_object_mode_set_ex(C, last_mode, true, op->reports); + + /* Update the viewport rotation origin to the mouse cursor. */ + if (last_mode & OB_MODE_ALL_PAINT) { + float global_loc[3]; + if (ED_view3d_autodist_simple(ar, event->mval, global_loc, 0, NULL)) { + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; + copy_v3_v3(ups->average_stroke_accum, global_loc); + ups->average_stroke_counter = 1; + ups->last_stroke_valid = true; + } } + + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); + WM_toolsystem_update_from_context_view3d(C); + retval = OPERATOR_FINISHED; } - WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); - WM_toolsystem_update_from_context_view3d(C); + ED_undo_group_end(C); - return OPERATOR_FINISHED; + return retval; } void OBJECT_OT_switch_object(wmOperatorType *ot) |