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