Loading...
Searching...
No Matches
CommandStackSerialization.hpp
1#pragma once
2#include <score/application/ApplicationComponents.hpp>
3#include <score/command/CommandData.hpp>
4#include <score/plugins/StringFactoryKeySerialization.hpp>
6
7#include <core/command/CommandStack.hpp>
8namespace score
9{
10template <typename RedoFun>
11void loadCommandStack(
12 const score::ApplicationComponents& components, DataStreamWriter& writer,
13 score::CommandStack& stack, RedoFun redo_fun)
14{
15 std::vector<score::CommandData> undoStack, redoStack;
16 writer.writeTo(undoStack);
17 writer.writeTo(redoStack);
18
19 writer.checkDelimiter();
20
21 stack.undoable().clear();
22 stack.redoable().clear();
23
24 stack.updateStack([&]() {
25 stack.setSavedIndex(-1);
26
27 bool ok = true;
28 for(const auto& elt : undoStack)
29 {
30 auto cmd = components.instantiateUndoCommand(elt);
31
32 if(redo_fun(cmd))
33 {
34 stack.undoable().push(cmd);
35 }
36 else
37 {
38 ok = false;
39 break;
40 }
41 }
42
43 if(ok)
44 {
45 for(const auto& elt : redoStack)
46 {
47 auto cmd = components.instantiateUndoCommand(elt);
48
49 stack.redoable().push(cmd);
50 }
51 }
52 });
53}
54}
Definition DataStreamVisitor.hpp:202
void checkDelimiter()
checkDelimiter
Definition DataStreamVisitor.cpp:47
Definition ApplicationComponents.hpp:68
Definition CommandStack.hpp:26
void updateStack(Callable &&c)
updateStack Updates the undo / redo stack
Definition CommandStack.hpp:176
Base toolkit upon which the software is built.
Definition Application.cpp:90