1 | // Aseprite |
---|---|
2 | // Copyright (C) 2019 Igara Studio S.A. |
3 | // Copyright (C) 2001-2018 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifndef APP_CMD_TRANSACTION_H_INCLUDED |
9 | #define APP_CMD_TRANSACTION_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "app/cmd_sequence.h" |
13 | #include "app/doc_range.h" |
14 | #include "app/sprite_position.h" |
15 | |
16 | #include <memory> |
17 | #include <sstream> |
18 | |
19 | namespace app { |
20 | |
21 | // Cmds created on each Transaction. |
22 | // The whole DocUndo contains a list of these CmdTransaction. |
23 | class CmdTransaction : public CmdSequence { |
24 | public: |
25 | CmdTransaction(const std::string& label, |
26 | bool changeSavedState, int* savedCounter); |
27 | |
28 | // Moves the CmdTransaction internals to a new copy in case that |
29 | // we want to rollback this CmdTransaction and start again with |
30 | // the new CmdTransaction. |
31 | CmdTransaction* moveToEmptyCopy(); |
32 | |
33 | void setNewDocRange(const DocRange& range); |
34 | void updateSpritePositionAfter(); |
35 | |
36 | SpritePosition spritePositionBeforeExecute() const { return m_spritePositionBefore; } |
37 | SpritePosition spritePositionAfterExecute() const { return m_spritePositionAfter; } |
38 | |
39 | std::istream* documentRangeBeforeExecute() const; |
40 | std::istream* documentRangeAfterExecute() const; |
41 | |
42 | protected: |
43 | void onExecute() override; |
44 | void onUndo() override; |
45 | void onRedo() override; |
46 | std::string onLabel() const override; |
47 | size_t onMemSize() const override; |
48 | |
49 | private: |
50 | SpritePosition calcSpritePosition() const; |
51 | bool isDocRangeEnabled() const; |
52 | DocRange calcDocRange() const; |
53 | |
54 | struct Ranges { |
55 | std::stringstream m_before; |
56 | std::stringstream m_after; |
57 | }; |
58 | |
59 | SpritePosition m_spritePositionBefore; |
60 | SpritePosition m_spritePositionAfter; |
61 | std::unique_ptr<Ranges> m_ranges; |
62 | std::string m_label; |
63 | bool m_changeSavedState; |
64 | int* m_savedCounter; |
65 | }; |
66 | |
67 | } // namespace app |
68 | |
69 | #endif |
70 |