From e882367d80a0bcdd09b5412d908b0fdb6b6bfe34 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 17 Mar 2015 13:58:32 -0400 Subject: Implemented undo/redo framework in map editor --- tools/mapedit/src/undo.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/mapedit/src/undo.h (limited to 'tools/mapedit/src/undo.h') diff --git a/tools/mapedit/src/undo.h b/tools/mapedit/src/undo.h new file mode 100644 index 0000000..794f993 --- /dev/null +++ b/tools/mapedit/src/undo.h @@ -0,0 +1,63 @@ +#ifndef UNDO_H +#define UNDO_H + +#include + +#ifndef WX_PRECOMP +#include +#endif + +#include +#include +#include + +class MapeditFrame; + +class Undoable { + public: + Undoable(std::string title, std::function forward, std::function backward); + virtual std::string getTitle() const; + virtual void apply(); + virtual void undo(); + virtual void endChanges() {} + + protected: + Undoable() {} + + std::string title; + std::function forward; + std::function backward; +}; + +class UndoableTextBox : public wxTextCtrl { + public: + UndoableTextBox(); + UndoableTextBox(wxWindow* parent, wxWindowID id, wxString startText, std::string undoType, MapeditFrame* realParent, wxPoint pos = wxDefaultPosition, wxSize size = wxDefaultSize, long style = 0); + + private: + class Undo : public Undoable { + public: + Undo(std::string title, wxString origText, UndoableTextBox& parent); + void apply(); + void undo(); + void endChanges(); + + wxString origText; + wxString newText; + UndoableTextBox& parent; + }; + + void Init(); + void OnFocus(wxFocusEvent& event); + void OnKillFocus(wxFocusEvent& event); + void OnTextChange(wxCommandEvent& event); + + MapeditFrame* realParent; + std::string undoText; + wxString curText; + std::shared_ptr undo; + + wxDECLARE_EVENT_TABLE(); +}; + +#endif -- cgit 1.4.1