mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-20 17:17:25 -05:00
Synchronize re-ordering and grouping of macros
This commit is contained in:
parent
64ccd5ba53
commit
b4936274f2
|
|
@ -1,6 +1,7 @@
|
|||
#include "macro-tree.hpp"
|
||||
#include "macro.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "switcher-data-structs.hpp"
|
||||
|
||||
#include <obs.h>
|
||||
#include <string>
|
||||
|
|
@ -563,6 +564,7 @@ void MacroTreeModel::GroupSelectedItems(QModelIndexList &indices)
|
|||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
QString name = GetNewGroupName();
|
||||
std::vector<std::shared_ptr<Macro>> items;
|
||||
items.reserve(indices.size());
|
||||
|
|
@ -606,6 +608,7 @@ void MacroTreeModel::UngroupSelectedGroups(QModelIndexList &indices)
|
|||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
for (int i = indices.count() - 1; i >= 0; i--) {
|
||||
std::shared_ptr<Macro> item = _macros[ModelIndexToMacroIndex(
|
||||
indices[i].row(), _macros)];
|
||||
|
|
@ -966,6 +969,7 @@ void MacroTree::dropEvent(QDropEvent *event)
|
|||
}
|
||||
|
||||
// Move items in backend
|
||||
std::lock_guard<std::mutex> lock(switcher->m);
|
||||
int to = row;
|
||||
try {
|
||||
to = ModelIndexToMacroIndex(row, items);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ Macro::CreateGroup(const std::string &name,
|
|||
{
|
||||
auto group = std::make_shared<Macro>(name, false);
|
||||
for (auto &c : children) {
|
||||
c->SetParent(group.get());
|
||||
c->SetParent(group);
|
||||
}
|
||||
group->_isGroup = true;
|
||||
group->_groupSize = children.size();
|
||||
|
|
@ -82,7 +82,7 @@ void Macro::PrepareMoveToGroup(std::shared_ptr<Macro> group,
|
|||
oldGroup->_groupSize--;
|
||||
}
|
||||
|
||||
item->SetParent(group.get());
|
||||
item->SetParent(group);
|
||||
if (group) {
|
||||
group->_groupSize++;
|
||||
}
|
||||
|
|
@ -204,8 +204,9 @@ bool Macro::PerformActions(bool forceParallel, bool ignorePause)
|
|||
RunActions(ret, ignorePause);
|
||||
}
|
||||
_wasExecutedRecently = true;
|
||||
if (_parent) {
|
||||
_parent->_wasExecutedRecently = true;
|
||||
auto group = _parent.lock();
|
||||
if (group) {
|
||||
group->_wasExecutedRecently = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -313,6 +314,12 @@ void Macro::UpdateConditionIndices()
|
|||
}
|
||||
}
|
||||
|
||||
Macro *Macro::Parent()
|
||||
{
|
||||
auto p = _parent.lock();
|
||||
return p.get();
|
||||
}
|
||||
|
||||
bool Macro::Save(obs_data_t *obj) const
|
||||
{
|
||||
obs_data_set_string(obj, "name", _name.c_str());
|
||||
|
|
@ -720,7 +727,7 @@ void SwitcherData::loadMacros(obs_data_t *obj)
|
|||
continue;
|
||||
}
|
||||
if (groupCount) {
|
||||
m->SetParent(group.get());
|
||||
m->SetParent(group);
|
||||
groupCount--;
|
||||
}
|
||||
if (m->IsGroup()) {
|
||||
|
|
@ -764,8 +771,14 @@ bool SwitcherData::checkMacros()
|
|||
|
||||
bool SwitcherData::runMacros()
|
||||
{
|
||||
for (auto m : macros) {
|
||||
if (m->Matched()) {
|
||||
// Create copy of macor list as elements might be removed, inserted, or
|
||||
// reordered while macros are currently being executed.
|
||||
// For example, this can happen if a macro is performing a wait action,
|
||||
// as the main lock will be unlocked during this time.
|
||||
auto runPhaseMacros = macros;
|
||||
|
||||
for (auto m : runPhaseMacros) {
|
||||
if (m && m->Matched()) {
|
||||
vblog(LOG_INFO, "running macro: %s", m->Name().c_str());
|
||||
if (!m->PerformActions()) {
|
||||
blog(LOG_WARNING, "abort macro: %s",
|
||||
|
|
|
|||
|
|
@ -55,11 +55,11 @@ public:
|
|||
std::shared_ptr<Macro> item);
|
||||
bool IsGroup() { return _isGroup; }
|
||||
uint32_t GroupSize() { return _groupSize; }
|
||||
bool IsSubitem() { return !!_parent; }
|
||||
bool IsSubitem() { return !_parent.expired(); }
|
||||
void SetCollapsed(bool val) { _isCollapsed = val; }
|
||||
bool IsCollapsed() { return _isCollapsed; }
|
||||
void SetParent(Macro *m) { _parent = m; }
|
||||
Macro *Parent() { return _parent; }
|
||||
void SetParent(std::shared_ptr<Macro> m) { _parent = m; }
|
||||
Macro *Parent();
|
||||
|
||||
bool Save(obs_data_t *obj) const;
|
||||
bool Load(obs_data_t *obj);
|
||||
|
|
@ -93,7 +93,7 @@ private:
|
|||
std::deque<std::shared_ptr<MacroCondition>> _conditions;
|
||||
std::deque<std::shared_ptr<MacroAction>> _actions;
|
||||
|
||||
Macro *_parent = nullptr;
|
||||
std::weak_ptr<Macro> _parent;
|
||||
uint32_t _groupSize = 0;
|
||||
|
||||
bool _runInParallel = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user