1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_UndoableCommand
21 #define TrenchBroom_UndoableCommand
22 
23 #include "SharedPointer.h"
24 #include "View/Command.h"
25 
26 namespace TrenchBroom {
27     namespace View {
28         class MapDocumentCommandFacade;
29 
30         class UndoableCommand : public Command {
31         public:
32             typedef std::shared_ptr<UndoableCommand> Ptr;
33         public:
34             UndoableCommand(CommandType type, const String& name);
35             virtual ~UndoableCommand();
36 
37             virtual bool performUndo(MapDocumentCommandFacade* document);
38 
39             bool isRepeatDelimiter() const;
40             bool isRepeatable(MapDocumentCommandFacade* document) const;
41             UndoableCommand::Ptr repeat(MapDocumentCommandFacade* document) const;
42 
43             virtual bool collateWith(UndoableCommand::Ptr command);
44         private:
45             virtual bool doPerformUndo(MapDocumentCommandFacade* document) = 0;
46 
47             virtual bool doIsRepeatDelimiter() const;
48             virtual bool doIsRepeatable(MapDocumentCommandFacade* document) const = 0;
49             virtual UndoableCommand::Ptr doRepeat(MapDocumentCommandFacade* document) const;
50 
51             virtual bool doCollateWith(UndoableCommand::Ptr command) = 0;
52         public: // this method is just a service for DocumentCommand and should never be called from anywhere else
53             virtual size_t documentModificationCount() const;
54         };
55     }
56 }
57 
58 #endif /* defined(TrenchBroom_UndoableCommand) */
59