[Bf-blender-cvs] [3cc6b423b12] blender-v2.91-release: Object: use undo-group for object.switch_object

Campbell Barton noreply at git.blender.org
Fri Oct 30 10:53:25 CET 2020


Commit: 3cc6b423b12b8c412892782928203c16b77be932
Author: Campbell Barton
Date:   Fri Oct 30 20:24:15 2020 +1100
Branches: blender-v2.91-release
https://developer.blender.org/rB3cc6b423b12b8c412892782928203c16b77be932

Object: use undo-group for object.switch_object

object.switch_object no longer adds multiple undo steps
from a user perspective.

===================================================================

M	source/blender/editors/object/object_modes.c

===================================================================

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)



More information about the Bf-blender-cvs mailing list