@@ -400,7 +400,6 @@ class SimpleTransactionAction : public UndoableAction
400400 , originalProperties (origProps)
401401 , originalChildren (origChildren)
402402 {
403- // Capture current state as the "after" state
404403 if (dataTree.object != nullptr )
405404 {
406405 currentProperties = dataTree.object ->properties ;
@@ -419,23 +418,16 @@ class SimpleTransactionAction : public UndoableAction
419418 return false ;
420419
421420 if (state == UndoableActionState::Redo)
422- {
423- // Restore "after" state (current/new state)
424421 restoreState (currentProperties, currentChildren);
425- }
426- else // Undo
427- {
428- // Restore "before" state (original state)
422+ else
429423 restoreState (originalProperties, originalChildren);
430- }
431424
432425 return true ;
433426 }
434427
435428private:
436429 void restoreState (const NamedValueSet& props, const std::vector<DataTree>& children)
437430 {
438- // Clear parent references for children that will be removed
439431 for (const auto & currentChild : dataTree.object ->children )
440432 {
441433 bool willBeKept = false ;
@@ -449,23 +441,18 @@ class SimpleTransactionAction : public UndoableAction
449441 }
450442
451443 if (!willBeKept && currentChild.object != nullptr )
452- {
453444 currentChild.object ->parent .reset ();
454- }
455445 }
456446
457- // Restore properties and children
458447 dataTree.object ->properties = props;
459448 dataTree.object ->children = children;
460449
461- // Set parent references for restored children
462450 for (const auto & child : dataTree.object ->children )
463451 {
464452 if (child.object != nullptr )
465453 child.object ->parent = dataTree.object ;
466454 }
467455
468- // Send notifications
469456 for (int i = 0 ; i < props.size (); ++i)
470457 dataTree.object ->sendPropertyChangeMessage (props.getName (i));
471458
@@ -709,8 +696,7 @@ void DataTree::setProperty (const Identifier& name, const var& newValue, UndoMan
709696 }
710697 else
711698 {
712- object->properties .set (name, newValue);
713- object->sendPropertyChangeMessage (name);
699+ PropertySetAction (*this , name, newValue, object->properties [name]).perform (UndoableActionState::Redo);
714700 }
715701}
716702
@@ -727,8 +713,7 @@ void DataTree::removeProperty (const Identifier& name, UndoManager* undoManager)
727713 }
728714 else
729715 {
730- object->properties .remove (name);
731- object->sendPropertyChangeMessage (name);
716+ PropertyRemoveAction (*this , name, object->properties [name]).perform (UndoableActionState::Redo);
732717 }
733718}
734719
@@ -745,11 +730,7 @@ void DataTree::removeAllProperties (UndoManager* undoManager)
745730 }
746731 else
747732 {
748- auto oldProperties = object->properties ;
749- object->properties .clear ();
750-
751- for (int i = 0 ; i < oldProperties.size (); ++i)
752- object->sendPropertyChangeMessage (oldProperties.getName (i));
733+ RemoveAllPropertiesAction (*this , object->properties ).perform (UndoableActionState::Redo);
753734 }
754735}
755736
@@ -773,17 +754,7 @@ void DataTree::addChild (const DataTree& child, int index, UndoManager* undoMana
773754 }
774755 else
775756 {
776- // Remove from previous parent if any
777- if (auto oldParentObj = child.object ->parent .lock ())
778- {
779- DataTree oldParent (oldParentObj);
780- oldParent.removeChild (child);
781- }
782-
783- object->children .insert (object->children .begin () + index, child);
784- child.object ->parent = object;
785-
786- object->sendChildAddedMessage (child);
757+ AddChildAction (*this , child, index).perform (UndoableActionState::Redo);
787758 }
788759}
789760
@@ -811,10 +782,7 @@ void DataTree::removeChild (int index, UndoManager* undoManager)
811782 }
812783 else
813784 {
814- object->children .erase (object->children .begin () + index);
815- child.object ->parent .reset ();
816-
817- object->sendChildRemovedMessage (child, index);
785+ RemoveChildAction (*this , child, index).perform (UndoableActionState::Redo);
818786 }
819787}
820788
@@ -831,14 +799,7 @@ void DataTree::removeAllChildren (UndoManager* undoManager)
831799 }
832800 else
833801 {
834- auto oldChildren = object->children ;
835- object->children .clear ();
836-
837- for (size_t i = 0 ; i < oldChildren.size (); ++i)
838- {
839- oldChildren[i].object ->parent .reset ();
840- object->sendChildRemovedMessage (oldChildren[i], static_cast <int > (i));
841- }
802+ RemoveAllChildrenAction (*this , object->children ).perform (UndoableActionState::Redo);
842803 }
843804}
844805
@@ -859,11 +820,7 @@ void DataTree::moveChild (int currentIndex, int newIndex, UndoManager* undoManag
859820 }
860821 else
861822 {
862- auto child = object->children [static_cast <size_t > (currentIndex)];
863- object->children .erase (object->children .begin () + currentIndex);
864- object->children .insert (object->children .begin () + newIndex, child);
865-
866- object->sendChildMovedMessage (child, currentIndex, newIndex);
823+ MoveChildAction (*this , currentIndex, newIndex).perform (UndoableActionState::Redo);
867824 }
868825}
869826
0 commit comments