Add undo / redo support for macros
Some checks failed
debian-build / build (push) Has been cancelled
Check locale / ubuntu64 (push) Has been cancelled
Push to master / Check Formatting 🔍 (push) Has been cancelled
Push to master / Build Project 🧱 (push) Has been cancelled
Push to master / Create Release 🛫 (push) Has been cancelled

This commit is contained in:
WarmUpTill
2026-08-12 11:48:53 +02:00
committed by WarmUpTill
parent afd9154c84
commit 7ea944e1a3
17 changed files with 1768 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
#include "macro-action-edit.hpp"
#include "macro-undo-redo.hpp"
#include "advanced-scene-switcher.hpp"
#include "macro-helpers.hpp"
#include "macro-settings.hpp"
@@ -111,9 +112,31 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
return;
}
Macro *const parentMacro =
(*_entryData)->GetMacro()->GetNestedParentMacro();
OBSDataAutoRelease parentBeforeData;
if (parentMacro) {
parentBeforeData = obs_data_create();
parentMacro->Save(parentBeforeData);
}
const std::string oldId = (*_entryData)->GetId();
OBSDataAutoRelease oldData = obs_data_create();
(*_entryData)->Save(oldData);
HeaderInfoChanged("");
auto idx = _entryData->get()->GetIndex();
auto macro = _entryData->get()->GetMacro();
const auto *rawPtr = (*_entryData).get();
const auto &elseActions = macro->ElseActions();
const bool isElse = std::any_of(elseActions.begin(), elseActions.end(),
[rawPtr](const auto &a) {
return a.get() == rawPtr;
});
const auto segmentType = isElse ? MacroEdit::SegmentType::ELSE_ACTION
: MacroEdit::SegmentType::ACTION;
{
auto lock = LockContext();
_entryData->reset();
@@ -122,6 +145,16 @@ void MacroActionEdit::ActionSelectionChanged(const QString &text)
(*_entryData)->PostLoad();
RunAndClearPostLoadSteps();
}
OBSDataAutoRelease newData = obs_data_create();
(*_entryData)->Save(newData);
if (parentMacro) {
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
} else {
RegisterSegmentTypeChangeUndoRedo(macro, segmentType, idx,
oldId, oldData, 0, id,
newData, 0);
}
auto widget = MacroActionFactory::CreateWidget(id, this, *_entryData);
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
this, SLOT(HeaderInfoChanged(const QString &)));