2 #include <score/command/Dispatchers/ICommandDispatcher.hpp>
3 #include <score/command/Dispatchers/SendStrategy.hpp>
7 namespace RollbackStrategy
14 for(
int i = cmds.size() - 1; i >= 0; --i)
44 stack().disableActions();
45 cmd->redo(stack().context());
46 m_cmds.push_back(cmd);
51 stack().disableActions();
52 m_cmds.push_back(cmd);
55 template <
typename TheCommand,
typename... Args>
56 void submit(Args&&... args)
60 stack().disableActions();
61 auto cmd =
new TheCommand(std::forward<Args>(args)...);
62 cmd->redo(stack().context());
63 m_cmds.push_back(cmd);
68 if(last->key() == TheCommand::static_key())
70 safe_cast<TheCommand*>(last)->update(std::forward<Args>(args)...);
71 safe_cast<TheCommand*>(last)->redo(stack().context());
75 auto cmd =
new TheCommand(std::forward<Args>(args)...);
76 cmd->redo(stack().context());
77 m_cmds.push_back(cmd);
83 template <
typename CommitCommand>
88 auto theCmd =
new CommitCommand;
89 for(
auto& cmd : m_cmds)
91 theCmd->addCommand(cmd);
94 SendStrategy::Quiet::send(stack(), theCmd);
97 stack().enableActions();
101 template <
typename RollbackStrategy>
104 RollbackStrategy::rollback(stack().context(), m_cmds);
109 stack().enableActions();
115 std::for_each(m_cmds.rbegin(), m_cmds.rend(), [](
auto cmd) { delete cmd; });
118 std::vector<score::Command*> m_cmds;
The ICommandDispatcher class.
Definition: ICommandDispatcher.hpp:21
The MultiOngoingCommandDispatcher class.
Definition: MultiOngoingCommandDispatcher.hpp:33
The Command class.
Definition: Command.hpp:34
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
Definition: MultiOngoingCommandDispatcher.hpp:10
Definition: DocumentContext.hpp:18