mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-01 06:05:35 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2e7bec135 | ||
|
|
0ea98073d7 | ||
|
|
151f69305b | ||
|
|
71e1e395df | ||
|
|
74e5ca1b57 |
@@ -173,6 +173,8 @@ target_sources(
|
||||
lib/macro/macro-signals.hpp
|
||||
lib/macro/macro-tab.cpp
|
||||
lib/macro/macro-tree.cpp
|
||||
lib/macro/macro-undo-redo.cpp
|
||||
lib/macro/macro-undo-redo.hpp
|
||||
lib/macro/macro-tree.hpp
|
||||
lib/macro/macro-websocket-trigger.cpp
|
||||
lib/macro/macro.cpp
|
||||
|
||||
@@ -198,6 +198,19 @@ AdvSceneSwitcher.macroTab.groupNameExists="The name \"%1\" is already used by a
|
||||
AdvSceneSwitcher.macroTab.removeSingleMacroPopup.text="Are you sure you want to remove \"%1\"?"
|
||||
AdvSceneSwitcher.macroTab.removeMultipleMacrosPopup.text="Are you sure you want to remove %1 macros/groups?"
|
||||
AdvSceneSwitcher.macroTab.removeGroupPopup.text="Are you sure you want to remove \"%1\" group and all its elements?"
|
||||
AdvSceneSwitcher.undo.renameMacro="Rename Macro '%1'"
|
||||
AdvSceneSwitcher.undo.modifyMacro="Modify Macro '%1'"
|
||||
AdvSceneSwitcher.undo.addMacro="Add Macro '%1'"
|
||||
AdvSceneSwitcher.undo.removeMacro="Remove Macro '%1'"
|
||||
AdvSceneSwitcher.undo.addSegment="Add %1 in '%2'"
|
||||
AdvSceneSwitcher.undo.removeSegment="Remove %1 in '%2'"
|
||||
AdvSceneSwitcher.undo.changeSegmentType="Change %1 Type in '%2'"
|
||||
AdvSceneSwitcher.undo.groupMacros="Group Macros '%1'"
|
||||
AdvSceneSwitcher.undo.ungroupMacros="Ungroup Macros '%1'"
|
||||
AdvSceneSwitcher.undo.removeMacroGroup="Remove Macro Group '%1'"
|
||||
AdvSceneSwitcher.undo.segment.action="Action"
|
||||
AdvSceneSwitcher.undo.segment.elseAction="Else Action"
|
||||
AdvSceneSwitcher.undo.segment.condition="Condition"
|
||||
AdvSceneSwitcher.macroTab.contextMenuAdd="Add"
|
||||
AdvSceneSwitcher.macroTab.copy="Duplicate Macro"
|
||||
AdvSceneSwitcher.macroTab.group="Group Selected Macros"
|
||||
|
||||
@@ -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,32 @@ 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();
|
||||
|
||||
// Determine whether this is an action or else-action before resetting.
|
||||
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 +146,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 &)));
|
||||
|
||||
@@ -83,6 +83,7 @@ bool MacroActionLoop::PostLoad()
|
||||
MacroAction::PostLoad();
|
||||
_loopMacro->PostLoad();
|
||||
_loopMacro->SetActionTriggerMode(Macro::ActionTriggerMode::ALWAYS);
|
||||
_loopMacro->SetNestedParentMacro(GetMacro());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +281,7 @@ bool MacroActionMacro::PostLoad()
|
||||
MacroAction::PostLoad();
|
||||
_runOptions.macro.PostLoad();
|
||||
_nestedMacro->PostLoad();
|
||||
_nestedMacro->SetNestedParentMacro(GetMacro());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "macro-condition-edit.hpp"
|
||||
#include "macro-undo-redo.hpp"
|
||||
|
||||
#include "advanced-scene-switcher.hpp"
|
||||
#include "condition-logic.hpp"
|
||||
@@ -250,6 +251,19 @@ void MacroConditionEdit::ConditionSelectionChanged(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();
|
||||
const int oldLogic = (int)(*_entryData)->GetLogicType();
|
||||
OBSDataAutoRelease oldData = obs_data_create();
|
||||
(*_entryData)->Save(oldData);
|
||||
|
||||
auto temp = DurationModifier();
|
||||
_dur->SetValue(temp);
|
||||
HeaderInfoChanged("");
|
||||
@@ -267,6 +281,17 @@ void MacroConditionEdit::ConditionSelectionChanged(const QString &text)
|
||||
(*_entryData)->PostLoad();
|
||||
RunAndClearPostLoadSteps();
|
||||
}
|
||||
|
||||
OBSDataAutoRelease newData = obs_data_create();
|
||||
(*_entryData)->Save(newData);
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
} else {
|
||||
RegisterSegmentTypeChangeUndoRedo(
|
||||
macro, MacroEdit::SegmentType::CONDITION, idx, oldId,
|
||||
oldData, oldLogic, id, newData,
|
||||
(int)(*_entryData)->GetLogicType());
|
||||
}
|
||||
auto widget =
|
||||
MacroConditionFactory::CreateWidget(id, this, *_entryData);
|
||||
QWidget::connect(widget, SIGNAL(HeaderInfoChanged(const QString &)),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "macro-edit.hpp"
|
||||
|
||||
#include "condition-logic.hpp"
|
||||
#include "macro-undo-redo.hpp"
|
||||
#include "cursor-shape-changer.hpp"
|
||||
#include "macro-action-edit.hpp"
|
||||
#include "macro-action-macro.hpp"
|
||||
@@ -257,6 +258,92 @@ std::shared_ptr<Macro> MacroEdit::GetMacro() const
|
||||
return _currentMacro;
|
||||
}
|
||||
|
||||
void MacroEdit::InsertSegmentWidget(SegmentType type, int idx)
|
||||
{
|
||||
auto macro = _currentMacro;
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case SegmentType::ACTION: {
|
||||
if (idx < 0 || idx > (int)macro->Actions().size()) {
|
||||
break;
|
||||
}
|
||||
ui->actionsList->Insert(
|
||||
idx, new MacroActionEdit(this, ¯o->Actions()[idx]));
|
||||
SetActionData(*macro);
|
||||
ui->actionsList->SetHelpMsgVisible(false);
|
||||
break;
|
||||
}
|
||||
case SegmentType::ELSE_ACTION: {
|
||||
if (idx < 0 || idx > (int)macro->ElseActions().size()) {
|
||||
break;
|
||||
}
|
||||
ui->elseActionsList->Insert(
|
||||
idx,
|
||||
new MacroActionEdit(this, ¯o->ElseActions()[idx]));
|
||||
SetElseActionData(*macro);
|
||||
ui->elseActionsList->SetHelpMsgVisible(false);
|
||||
break;
|
||||
}
|
||||
case SegmentType::CONDITION: {
|
||||
if (idx < 0 || idx > (int)macro->Conditions().size()) {
|
||||
break;
|
||||
}
|
||||
ui->conditionsList->Insert(
|
||||
idx,
|
||||
new MacroConditionEdit(this, ¯o->Conditions()[idx],
|
||||
idx == 0));
|
||||
if (idx == 0 && macro->Conditions().size() > 1) {
|
||||
static_cast<MacroConditionEdit *>(
|
||||
ui->conditionsList->WidgetAt(1))
|
||||
->SetRootNode(false);
|
||||
}
|
||||
SetConditionData(*macro);
|
||||
ui->conditionsList->SetHelpMsgVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MacroEdit::RemoveSegmentWidget(SegmentType type, int idx)
|
||||
{
|
||||
auto macro = _currentMacro;
|
||||
if (!macro) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case SegmentType::ACTION:
|
||||
if (idx >= 0 &&
|
||||
idx < ui->actionsList->ContentLayout()->count()) {
|
||||
ui->actionsList->Remove(idx);
|
||||
SetActionData(*macro);
|
||||
}
|
||||
break;
|
||||
case SegmentType::ELSE_ACTION:
|
||||
if (idx >= 0 &&
|
||||
idx < ui->elseActionsList->ContentLayout()->count()) {
|
||||
ui->elseActionsList->Remove(idx);
|
||||
SetElseActionData(*macro);
|
||||
}
|
||||
break;
|
||||
case SegmentType::CONDITION:
|
||||
if (idx >= 0 &&
|
||||
idx < ui->conditionsList->ContentLayout()->count()) {
|
||||
ui->conditionsList->Remove(idx);
|
||||
if (idx == 0 && !macro->Conditions().empty()) {
|
||||
static_cast<MacroConditionEdit *>(
|
||||
ui->conditionsList->WidgetAt(0))
|
||||
->SetRootNode(true);
|
||||
}
|
||||
SetConditionData(*macro);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MacroEdit::ClearSegmentWidgetCacheFor(Macro *macro) const
|
||||
{
|
||||
ui->conditionsList->ClearWidgetsFromCacheFor(macro);
|
||||
@@ -295,7 +382,7 @@ isValidMacroSegmentIdx(const std::deque<std::shared_ptr<MacroSegment>> &list,
|
||||
return (idx > 0 || (unsigned)idx < list.size());
|
||||
}
|
||||
|
||||
void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
||||
void MacroEdit::SetupMacroSegmentSelection(SegmentType type, int idx)
|
||||
{
|
||||
auto macro = _currentMacro;
|
||||
if (!macro) {
|
||||
@@ -308,7 +395,7 @@ void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
||||
std::deque<std::shared_ptr<MacroSegment>> segments;
|
||||
|
||||
switch (type) {
|
||||
case MacroEdit::MacroSection::CONDITIONS:
|
||||
case MacroEdit::SegmentType::CONDITION:
|
||||
setList = ui->conditionsList;
|
||||
setIdx = ¤tConditionIdx;
|
||||
segments = {macro->Conditions().begin(),
|
||||
@@ -319,7 +406,7 @@ void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
||||
resetIdx1 = ¤tActionIdx;
|
||||
resetIdx2 = ¤tElseActionIdx;
|
||||
break;
|
||||
case MacroEdit::MacroSection::ACTIONS:
|
||||
case MacroEdit::SegmentType::ACTION:
|
||||
setList = ui->actionsList;
|
||||
setIdx = ¤tActionIdx;
|
||||
segments = {macro->Actions().begin(), macro->Actions().end()};
|
||||
@@ -329,7 +416,7 @@ void MacroEdit::SetupMacroSegmentSelection(MacroSection type, int idx)
|
||||
resetIdx1 = ¤tConditionIdx;
|
||||
resetIdx2 = ¤tElseActionIdx;
|
||||
break;
|
||||
case MacroEdit::MacroSection::ELSE_ACTIONS:
|
||||
case MacroEdit::SegmentType::ELSE_ACTION:
|
||||
setList = ui->elseActionsList;
|
||||
setIdx = ¤tElseActionIdx;
|
||||
segments = {macro->ElseActions().begin(),
|
||||
@@ -965,7 +1052,7 @@ void MacroEdit::UpMacroSegmentHotkey()
|
||||
int conditionSize = macro->Conditions().size();
|
||||
|
||||
if (currentActionIdx == -1 && currentConditionIdx == -1) {
|
||||
if (lastInteracted == MacroSection::CONDITIONS) {
|
||||
if (lastInteracted == SegmentType::CONDITION) {
|
||||
if (conditionSize == 0) {
|
||||
MacroActionSelectionChanged(0);
|
||||
} else {
|
||||
@@ -1021,7 +1108,7 @@ void MacroEdit::DownMacroSegmentHotkey()
|
||||
int conditionSize = macro->Conditions().size();
|
||||
|
||||
if (currentActionIdx == -1 && currentConditionIdx == -1) {
|
||||
if (lastInteracted == MacroSection::CONDITIONS) {
|
||||
if (lastInteracted == SegmentType::CONDITION) {
|
||||
if (conditionSize == 0) {
|
||||
MacroActionSelectionChanged(0);
|
||||
} else {
|
||||
@@ -1084,6 +1171,13 @@ void MacroEdit::AddMacroAction(Macro *macro, int idx, const std::string &id,
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||
OBSDataAutoRelease parentBeforeData;
|
||||
if (parentMacro) {
|
||||
parentBeforeData = obs_data_create();
|
||||
parentMacro->Save(parentBeforeData);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
macro->Actions().emplace(macro->Actions().begin() + idx,
|
||||
@@ -1098,6 +1192,11 @@ void MacroEdit::AddMacroAction(Macro *macro, int idx, const std::string &id,
|
||||
idx, new MacroActionEdit(this, ¯o->Actions()[idx]));
|
||||
SetActionData(*macro);
|
||||
}
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
} else {
|
||||
RegisterSegmentAddUndoRedo(macro, SegmentType::ACTION, idx);
|
||||
}
|
||||
HighlightAction(idx);
|
||||
ui->actionsList->SetHelpMsgVisible(false);
|
||||
emit(MacroSegmentOrderChanged());
|
||||
@@ -1163,6 +1262,24 @@ void MacroEdit::RemoveMacroAction(int idx)
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||
OBSDataAutoRelease parentBeforeData;
|
||||
if (parentMacro) {
|
||||
parentBeforeData = obs_data_create();
|
||||
parentMacro->Save(parentBeforeData);
|
||||
} else {
|
||||
OBSDataAutoRelease segData = obs_data_create();
|
||||
std::string segId;
|
||||
{
|
||||
auto lock = LockContext();
|
||||
macro->Actions().at(idx)->Save(segData);
|
||||
segId = macro->Actions().at(idx)->GetId();
|
||||
}
|
||||
RegisterSegmentRemoveUndoRedo(macro.get(), SegmentType::ACTION,
|
||||
idx, segId, segData,
|
||||
(int)Logic::Type::ROOT_NONE);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
ui->actionsList->Remove(idx);
|
||||
@@ -1172,8 +1289,11 @@ void MacroEdit::RemoveMacroAction(int idx)
|
||||
macro->UpdateActionIndices();
|
||||
SetActionData(*macro);
|
||||
}
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
}
|
||||
MacroActionSelectionChanged(-1);
|
||||
lastInteracted = MacroSection::ACTIONS;
|
||||
lastInteracted = SegmentType::ACTION;
|
||||
emit(MacroSegmentOrderChanged());
|
||||
}
|
||||
|
||||
@@ -1353,7 +1473,7 @@ void MacroEdit::MoveMacroActionDown(int idx)
|
||||
|
||||
void MacroEdit::MacroElseActionSelectionChanged(int idx)
|
||||
{
|
||||
SetupMacroSegmentSelection(MacroSection::ELSE_ACTIONS, idx);
|
||||
SetupMacroSegmentSelection(SegmentType::ELSE_ACTION, idx);
|
||||
}
|
||||
|
||||
void MacroEdit::MacroElseActionReorder(int to, int from)
|
||||
@@ -1390,6 +1510,13 @@ void MacroEdit::AddMacroElseAction(Macro *macro, int idx, const std::string &id,
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||
OBSDataAutoRelease parentBeforeData;
|
||||
if (parentMacro) {
|
||||
parentBeforeData = obs_data_create();
|
||||
parentMacro->Save(parentBeforeData);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
macro->ElseActions().emplace(macro->ElseActions().begin() + idx,
|
||||
@@ -1406,6 +1533,12 @@ void MacroEdit::AddMacroElseAction(Macro *macro, int idx, const std::string &id,
|
||||
new MacroActionEdit(this, ¯o->ElseActions()[idx]));
|
||||
SetElseActionData(*macro);
|
||||
}
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
} else {
|
||||
RegisterSegmentAddUndoRedo(macro, SegmentType::ELSE_ACTION,
|
||||
idx);
|
||||
}
|
||||
HighlightElseAction(idx);
|
||||
ui->elseActionsList->SetHelpMsgVisible(false);
|
||||
emit(MacroSegmentOrderChanged());
|
||||
@@ -1455,6 +1588,25 @@ void MacroEdit::RemoveMacroElseAction(int idx)
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||
OBSDataAutoRelease parentBeforeData;
|
||||
if (parentMacro) {
|
||||
parentBeforeData = obs_data_create();
|
||||
parentMacro->Save(parentBeforeData);
|
||||
} else {
|
||||
OBSDataAutoRelease segData = obs_data_create();
|
||||
std::string segId;
|
||||
{
|
||||
auto lock = LockContext();
|
||||
macro->ElseActions().at(idx)->Save(segData);
|
||||
segId = macro->ElseActions().at(idx)->GetId();
|
||||
}
|
||||
RegisterSegmentRemoveUndoRedo(macro.get(),
|
||||
SegmentType::ELSE_ACTION, idx,
|
||||
segId, segData,
|
||||
(int)Logic::Type::ROOT_NONE);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
ui->elseActionsList->Remove(idx);
|
||||
@@ -1464,8 +1616,11 @@ void MacroEdit::RemoveMacroElseAction(int idx)
|
||||
macro->UpdateElseActionIndices();
|
||||
SetElseActionData(*macro);
|
||||
}
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
}
|
||||
MacroElseActionSelectionChanged(-1);
|
||||
lastInteracted = MacroSection::ELSE_ACTIONS;
|
||||
lastInteracted = SegmentType::ELSE_ACTION;
|
||||
emit(MacroSegmentOrderChanged());
|
||||
}
|
||||
|
||||
@@ -1526,7 +1681,7 @@ void MacroEdit::MoveMacroElseActionDown(int idx)
|
||||
|
||||
void MacroEdit::MacroActionSelectionChanged(int idx)
|
||||
{
|
||||
SetupMacroSegmentSelection(MacroSection::ACTIONS, idx);
|
||||
SetupMacroSegmentSelection(SegmentType::ACTION, idx);
|
||||
}
|
||||
|
||||
void MacroEdit::MacroActionReorder(int to, int from)
|
||||
@@ -1599,6 +1754,13 @@ void MacroEdit::AddMacroCondition(Macro *macro, int idx, const std::string &id,
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||
OBSDataAutoRelease parentBeforeData;
|
||||
if (parentMacro) {
|
||||
parentBeforeData = obs_data_create();
|
||||
parentMacro->Save(parentBeforeData);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
auto cond = macro->Conditions().emplace(
|
||||
@@ -1617,6 +1779,11 @@ void MacroEdit::AddMacroCondition(Macro *macro, int idx, const std::string &id,
|
||||
idx == 0));
|
||||
SetConditionData(*macro);
|
||||
}
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
} else {
|
||||
RegisterSegmentAddUndoRedo(macro, SegmentType::CONDITION, idx);
|
||||
}
|
||||
HighlightCondition(idx);
|
||||
ui->conditionsList->SetHelpMsgVisible(false);
|
||||
emit(MacroSegmentOrderChanged());
|
||||
@@ -1652,6 +1819,26 @@ void MacroEdit::RemoveMacroCondition(int idx)
|
||||
return;
|
||||
}
|
||||
|
||||
Macro *const parentMacro = macro->GetNestedParentMacro();
|
||||
OBSDataAutoRelease parentBeforeData;
|
||||
if (parentMacro) {
|
||||
parentBeforeData = obs_data_create();
|
||||
parentMacro->Save(parentBeforeData);
|
||||
} else {
|
||||
OBSDataAutoRelease segData = obs_data_create();
|
||||
std::string segId;
|
||||
int logic;
|
||||
{
|
||||
auto lock = LockContext();
|
||||
macro->Conditions().at(idx)->Save(segData);
|
||||
segId = macro->Conditions().at(idx)->GetId();
|
||||
logic = (int)macro->Conditions().at(idx)->GetLogicType();
|
||||
}
|
||||
RegisterSegmentRemoveUndoRedo(macro.get(),
|
||||
SegmentType::CONDITION, idx,
|
||||
segId, segData, logic);
|
||||
}
|
||||
|
||||
{
|
||||
auto lock = LockContext();
|
||||
ui->conditionsList->Remove(idx);
|
||||
@@ -1666,8 +1853,11 @@ void MacroEdit::RemoveMacroCondition(int idx)
|
||||
}
|
||||
SetConditionData(*macro);
|
||||
}
|
||||
if (parentMacro) {
|
||||
RegisterMacroModifyUndoRedo(parentMacro, parentBeforeData);
|
||||
}
|
||||
MacroConditionSelectionChanged(-1);
|
||||
lastInteracted = MacroSection::CONDITIONS;
|
||||
lastInteracted = SegmentType::CONDITION;
|
||||
emit(MacroSegmentOrderChanged());
|
||||
}
|
||||
|
||||
@@ -1792,7 +1982,7 @@ void MacroEdit::MoveMacroConditionDown(int idx)
|
||||
|
||||
void MacroEdit::MacroConditionSelectionChanged(int idx)
|
||||
{
|
||||
SetupMacroSegmentSelection(MacroSection::CONDITIONS, idx);
|
||||
SetupMacroSegmentSelection(SegmentType::CONDITION, idx);
|
||||
}
|
||||
|
||||
void MacroEdit::MacroConditionReorder(int to, int from)
|
||||
|
||||
@@ -12,11 +12,15 @@ class MacroEdit : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class SegmentType { CONDITION, ACTION, ELSE_ACTION };
|
||||
|
||||
MacroEdit(QWidget *parent, QStringList helpMsg = {});
|
||||
void SetMacro(const std::shared_ptr<Macro> &);
|
||||
std::shared_ptr<Macro> GetMacro() const;
|
||||
void ClearSegmentWidgetCacheFor(Macro *) const;
|
||||
void SetControlsDisabled(bool disable) const;
|
||||
void InsertSegmentWidget(SegmentType type, int idx);
|
||||
void RemoveSegmentWidget(SegmentType type, int idx);
|
||||
void HighlightAction(int idx, QColor color = QColor(Qt::green)) const;
|
||||
void HighlightElseAction(int idx,
|
||||
QColor color = QColor(Qt::green)) const;
|
||||
@@ -112,14 +116,12 @@ protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
private:
|
||||
enum class MacroSection { CONDITIONS, ACTIONS, ELSE_ACTIONS };
|
||||
|
||||
void PopulateMacroActions(Macro &m, uint32_t afterIdx = 0);
|
||||
void PopulateMacroElseActions(Macro &m, uint32_t afterIdx = 0);
|
||||
void PopulateMacroConditions(Macro &m, uint32_t afterIdx = 0);
|
||||
void ScrollAndFocusNewSegment(MacroSegmentList *list, int newIdx,
|
||||
int *currentIdx);
|
||||
void SetupMacroSegmentSelection(MacroSection type, int idx);
|
||||
void SetupMacroSegmentSelection(SegmentType type, int idx);
|
||||
void
|
||||
SetupContextMenu(const QPoint &pos,
|
||||
const std::function<void(MacroEdit *, int)> &remove,
|
||||
@@ -131,7 +133,7 @@ private:
|
||||
void RunSegmentHighlightChecks();
|
||||
bool ElseSectionIsVisible() const;
|
||||
|
||||
MacroSection lastInteracted = MacroSection::CONDITIONS;
|
||||
SegmentType lastInteracted = SegmentType::CONDITION;
|
||||
int currentConditionIdx = -1;
|
||||
int currentActionIdx = -1;
|
||||
int currentElseActionIdx = -1;
|
||||
|
||||
@@ -201,6 +201,8 @@ bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro)
|
||||
_contentLayout->addWidget(widget);
|
||||
widget->show();
|
||||
}
|
||||
// Widgets are now owned by the layout again, so the cache entry is stale.
|
||||
_widgetCache.erase(it);
|
||||
|
||||
adjustSize();
|
||||
updateGeometry();
|
||||
@@ -463,7 +465,17 @@ void MacroSegmentList::SetupVisibleMacroSegmentWidgets()
|
||||
|
||||
const auto viewportRect = viewport()->rect();
|
||||
|
||||
for (auto segment : widget()->findChildren<MacroSegmentEdit *>()) {
|
||||
for (int i = 0; i < _contentLayout->count(); ++i) {
|
||||
auto item = _contentLayout->itemAt(i);
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto segment = dynamic_cast<MacroSegmentEdit *>(item->widget());
|
||||
if (!segment) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto pos = segment->mapTo(viewport(), QPoint(0, 0));
|
||||
const QRect rect(pos, segment->size());
|
||||
if (!viewportRect.intersects(rect)) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "macro-settings.hpp"
|
||||
#include "macro-signals.hpp"
|
||||
#include "macro-tree.hpp"
|
||||
#include "macro-undo-redo.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "math-helpers.hpp"
|
||||
#include "name-dialog.hpp"
|
||||
@@ -122,6 +123,7 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
||||
ui->macros->Add(newMacro);
|
||||
MacroSignalManager::Instance()->Add(
|
||||
QString::fromStdString(name));
|
||||
RegisterMacroAddUndoRedo(name);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,6 +133,7 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
||||
ui->macros->AddToGroup(newMacro, selectedMacro);
|
||||
MacroSignalManager::Instance()->Add(
|
||||
QString::fromStdString(name));
|
||||
RegisterMacroAddUndoRedo(name);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,12 +142,14 @@ void AdvSceneSwitcher::on_macroAdd_clicked()
|
||||
ui->macros->Add(newMacro, selectedMacro);
|
||||
MacroSignalManager::Instance()->Add(
|
||||
QString::fromStdString(name));
|
||||
RegisterMacroAddUndoRedo(name);
|
||||
return;
|
||||
}
|
||||
|
||||
Macro::PrepareMoveToGroup(selectedMacroGroup, newMacro);
|
||||
ui->macros->Add(newMacro, selectedMacro);
|
||||
MacroSignalManager::Instance()->Add(QString::fromStdString(name));
|
||||
RegisterMacroAddUndoRedo(name);
|
||||
}
|
||||
|
||||
static void addGroupSubitems(std::vector<std::shared_ptr<Macro>> ¯os,
|
||||
@@ -185,6 +190,12 @@ void AdvSceneSwitcher::RemoveMacro(std::shared_ptr<Macro> ¯o)
|
||||
}
|
||||
}
|
||||
|
||||
if (macro->IsGroup()) {
|
||||
RegisterGroupDeleteUndoRedo(macro.get());
|
||||
} else {
|
||||
RegisterMacroRemoveUndoRedo(macro.get());
|
||||
}
|
||||
|
||||
if (macro->IsGroup()) {
|
||||
std::vector<std::shared_ptr<Macro>> macros = {macro};
|
||||
addGroupSubitems(macros, macro);
|
||||
@@ -241,13 +252,16 @@ void AdvSceneSwitcher::RemoveSelectedMacros()
|
||||
void AdvSceneSwitcher::RenameMacro(std::shared_ptr<Macro> ¯o,
|
||||
const QString &name)
|
||||
{
|
||||
auto oldName = QString::fromStdString(macro->Name());
|
||||
const std::string oldName = macro->Name();
|
||||
const std::string newName = name.toStdString();
|
||||
{
|
||||
auto lock = LockContext();
|
||||
macro->SetName(name.toStdString());
|
||||
macro->SetName(newName);
|
||||
}
|
||||
|
||||
MacroSignalManager::Instance()->Rename(oldName, name);
|
||||
RegisterMacroRenameUndoRedo(oldName, newName);
|
||||
MacroSignalManager::Instance()->Rename(QString::fromStdString(oldName),
|
||||
name);
|
||||
}
|
||||
|
||||
void AdvSceneSwitcher::on_macroRemove_clicked()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "macro-tree.hpp"
|
||||
#include "macro-undo-redo.hpp"
|
||||
|
||||
#include "macro-helpers.hpp"
|
||||
#include "macro-search.hpp"
|
||||
@@ -824,6 +825,8 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices)
|
||||
|
||||
Reset(_macros);
|
||||
assert(IsInValidState());
|
||||
|
||||
RegisterGroupCreateUndoRedo(name.toStdString());
|
||||
}
|
||||
|
||||
void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
||||
@@ -837,6 +840,7 @@ void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
||||
std::shared_ptr<Macro> item = _macros[ModelIndexToMacroIndex(
|
||||
indices[i].row(), _macros)];
|
||||
if (item->IsGroup()) {
|
||||
RegisterGroupRemoveUndoRedo(item->Name());
|
||||
Macro::RemoveGroup(item);
|
||||
}
|
||||
}
|
||||
|
||||
1166
lib/macro/macro-undo-redo.cpp
Normal file
1166
lib/macro/macro-undo-redo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
31
lib/macro/macro-undo-redo.hpp
Normal file
31
lib/macro/macro-undo-redo.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "macro-edit.hpp"
|
||||
|
||||
#include <obs-data.h>
|
||||
#include <string>
|
||||
|
||||
namespace advss {
|
||||
|
||||
class Macro;
|
||||
|
||||
void RegisterMacroAddUndoRedo(const std::string ¯oName);
|
||||
bool RegisterMacroRemoveUndoRedo(Macro *macro);
|
||||
void RegisterSegmentAddUndoRedo(Macro *macro, MacroEdit::SegmentType type,
|
||||
int index);
|
||||
void RegisterSegmentTypeChangeUndoRedo(Macro *macro,
|
||||
MacroEdit::SegmentType type, int index,
|
||||
const std::string &oldId,
|
||||
obs_data_t *oldData, int oldLogic,
|
||||
const std::string &newId,
|
||||
obs_data_t *newData, int newLogic);
|
||||
void RegisterSegmentRemoveUndoRedo(Macro *macro, MacroEdit::SegmentType type,
|
||||
int index, const std::string &segmentId,
|
||||
obs_data_t *segmentData, int logic);
|
||||
void RegisterMacroRenameUndoRedo(const std::string &oldName,
|
||||
const std::string &newName);
|
||||
void RegisterGroupCreateUndoRedo(const std::string &groupName);
|
||||
void RegisterGroupRemoveUndoRedo(const std::string &groupName);
|
||||
void RegisterGroupDeleteUndoRedo(Macro *macro);
|
||||
void RegisterMacroModifyUndoRedo(Macro *parentMacro, obs_data_t *beforeData);
|
||||
|
||||
} // namespace advss
|
||||
@@ -130,6 +130,13 @@ public:
|
||||
void SetParent(std::shared_ptr<Macro> m) { _parent = m; }
|
||||
std::shared_ptr<Macro> Parent() const;
|
||||
|
||||
// For nested macros embedded in actions (e.g. loop, nested-macro action)
|
||||
void SetNestedParentMacro(Macro *parent)
|
||||
{
|
||||
_nestedParentMacro = parent;
|
||||
}
|
||||
Macro *GetNestedParentMacro() const { return _nestedParentMacro; }
|
||||
|
||||
// Saving and loading
|
||||
bool Save(obs_data_t *obj, bool saveForCopy = false) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
@@ -187,6 +194,7 @@ private:
|
||||
std::deque<std::shared_ptr<MacroAction>> _elseActions;
|
||||
|
||||
std::weak_ptr<Macro> _parent;
|
||||
Macro *_nestedParentMacro = nullptr;
|
||||
uint32_t _groupSize = 0;
|
||||
bool _isGroup = false;
|
||||
bool _isCollapsed = false;
|
||||
|
||||
@@ -110,7 +110,9 @@ void MacroEdit::HighlightControls() const {}
|
||||
void MacroEdit::PopulateMacroActions(Macro &, uint32_t) {}
|
||||
void MacroEdit::PopulateMacroElseActions(Macro &, uint32_t) {}
|
||||
void MacroEdit::PopulateMacroConditions(Macro &, uint32_t) {}
|
||||
void MacroEdit::SetupMacroSegmentSelection(MacroSection, int) {}
|
||||
void MacroEdit::InsertSegmentWidget(SegmentType, int) {}
|
||||
void MacroEdit::RemoveSegmentWidget(SegmentType, int) {}
|
||||
void MacroEdit::SetupMacroSegmentSelection(SegmentType, int) {}
|
||||
void MacroEdit::SetupContextMenu(const QPoint &,
|
||||
const std::function<void(MacroEdit *, int)> &,
|
||||
const std::function<void(MacroEdit *)> &,
|
||||
|
||||
Reference in New Issue
Block a user