Loading...
Searching...
No Matches
SingleOngoingCommandDispatcher.hpp
1#pragma once
2#include <score/command/CommandStackFacade.hpp>
3#include <score/command/Dispatchers/ICommandDispatcher.hpp>
4#include <score/command/Dispatchers/SendStrategy.hpp>
5#include <score/selection/SelectionStack.hpp>
6
7#include <memory>
8
16template <typename TheCommand>
18{
19public:
21 : ICommandDispatcher{stack}
22 {
23 }
24
25 template <typename... Args>
26 void submit(Args&&... args)
27 {
28 if(!m_cmd)
29 {
30 stack().disableActions();
31 m_cmd = std::make_unique<TheCommand>(std::forward<Args>(args)...);
32 }
33 else
34 {
35 m_cmd->update(std::forward<Args>(args)...);
36 }
37
38 score::SelectionStack::Batch b{stack().selectionStack()};
39 m_cmd->redo(stack().context());
40 }
41
42 void commit()
43 {
44 if(m_cmd)
45 {
46 SendStrategy::Quiet::send(stack(), m_cmd.release());
47 stack().enableActions();
48 }
49 }
50
51 void rollback()
52 {
53 if(m_cmd)
54 {
55 {
56 score::SelectionStack::Batch b{stack().selectionStack()};
57 m_cmd->undo(stack().context());
58 }
59 stack().enableActions();
60 }
61 m_cmd.reset();
62 }
63
64protected:
65 std::unique_ptr<TheCommand> m_cmd;
66};
The ICommandDispatcher class.
Definition ICommandDispatcher.hpp:21
The SingleOngoingCommandDispatcher class.
Definition SingleOngoingCommandDispatcher.hpp:18
A small abstraction layer over the score::CommandStack.
Definition CommandStackFacade.hpp:21
Definition SelectionStack.hpp:72