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