1 /* 2 * Copyright 2006-2012, Stephan Aßmus <superstippi@gmx.de> 3 * Copyright 2021, Andrew Lindesay <apl@lindesay.co.nz> 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef EDIT_MANAGER_H 7 #define EDIT_MANAGER_H 8 9 #include <vector> 10 #include <stack> 11 12 #include "UndoableEdit.h" 13 14 class BString; 15 class EditContext; 16 17 18 class EditManager { 19 public: 20 class Listener { 21 public: 22 virtual ~Listener(); 23 virtual void EditManagerChanged( 24 const EditManager* manager) = 0; 25 }; 26 27 public: 28 EditManager(); 29 virtual ~EditManager(); 30 31 status_t Perform(UndoableEdit* edit, 32 EditContext& context); 33 status_t Perform(const UndoableEditRef& edit, 34 EditContext& context); 35 36 status_t Undo(EditContext& context); 37 status_t Redo(EditContext& context); 38 39 bool GetUndoName(BString& name); 40 bool GetRedoName(BString& name); 41 42 void Clear(); 43 void Save(); 44 bool IsSaved(); 45 46 void AddListener(Listener* listener); 47 void RemoveListener(Listener* listener); 48 49 private: 50 status_t _AddEdit(const UndoableEditRef& edit); 51 52 void _NotifyListeners(); 53 54 private: 55 std::stack<UndoableEditRef> 56 fUndoHistory; 57 std::stack<UndoableEditRef> 58 fRedoHistory; 59 UndoableEditRef fEditAtSave; 60 std::vector<Listener*> 61 fListeners; 62 }; 63 64 #endif // EDIT_MANAGER_H 65