1 /****************************************************************************** 2 * 3 * Project: OpenCPN 4 * Purpose: Framework for Undo features 5 * Author: Jesper Weissglas 6 * 7 *************************************************************************** 8 * Copyright (C) 2012 by David S. Register * 9 * * 10 * This program is free software; you can redistribute it and/or modify * 11 * it under the terms of the GNU General Public License as published by * 12 * the Free Software Foundation; either version 2 of the License, or * 13 * (at your option) any later version. * 14 * * 15 * This program is distributed in the hope that it will be useful, * 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 * GNU General Public License for more details. * 19 * * 20 * You should have received a copy of the GNU General Public License * 21 * along with this program; if not, write to the * 22 * Free Software Foundation, Inc., * 23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 24 *************************************************************************** 25 * 26 * 27 */ 28 29 #ifndef UNDO_H 30 #define UNDO_H 31 32 #include <vector> 33 #include <deque> 34 35 enum UndoType { 36 Undo_CreateWaypoint, 37 Undo_DeleteWaypoint, 38 Undo_AppendWaypoint, 39 Undo_MoveWaypoint 40 }; 41 42 enum UndoBeforePointerType { 43 Undo_IsOrphanded, 44 Undo_NeedsCopy, 45 Undo_HasParent 46 }; 47 48 typedef void* UndoItemPointer; 49 50 class UndoAction { 51 public: 52 ~UndoAction(); 53 wxString Description(); 54 55 UndoType type; 56 std::vector<UndoItemPointer> before; 57 std::vector<UndoBeforePointerType> beforeType; 58 std::vector<UndoItemPointer> after; 59 std::vector<UndoItemPointer> selectable; 60 }; 61 62 class Undo { 63 public: 64 Undo( ChartCanvas *parent); 65 ~Undo(); 66 bool AnythingToUndo(); 67 bool AnythingToRedo(); 68 void InvalidateRedo(); 69 void InvalidateUndo(); 70 void Invalidate(); InUndoableAction()71 bool InUndoableAction() { return isInsideUndoableAction; } 72 UndoAction* GetNextUndoableAction(); 73 UndoAction* GetNextRedoableAction(); 74 bool UndoLastAction(); 75 bool RedoNextAction(); 76 bool BeforeUndoableAction( UndoType type, UndoItemPointer before, UndoBeforePointerType beforeType, 77 UndoItemPointer selectable ); 78 bool AfterUndoableAction( UndoItemPointer after ); 79 bool CancelUndoableAction( bool noDataDelete = false ); GetParent()80 ChartCanvas *GetParent(){ return m_parent; } 81 82 private: 83 ChartCanvas *m_parent; 84 bool isInsideUndoableAction; 85 UndoAction* candidate; 86 unsigned int stackpointer; 87 unsigned int depthSetting; 88 std::deque<UndoAction*> undoStack; 89 }; 90 91 #endif 92