diff options
Diffstat (limited to 'tools/mapedit/src/undo.h')
-rw-r--r-- | tools/mapedit/src/undo.h | 63 |
1 files changed, 63 insertions, 0 deletions
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 @@ | |||
1 | #ifndef UNDO_H | ||
2 | #define UNDO_H | ||
3 | |||
4 | #include <wx/wxprec.h> | ||
5 | |||
6 | #ifndef WX_PRECOMP | ||
7 | #include <wx/wx.h> | ||
8 | #endif | ||
9 | |||
10 | #include <functional> | ||
11 | #include <string> | ||
12 | #include <list> | ||
13 | |||
14 | class MapeditFrame; | ||
15 | |||
16 | class Undoable { | ||
17 | public: | ||
18 | Undoable(std::string title, std::function<void ()> forward, std::function<void ()> backward); | ||
19 | virtual std::string getTitle() const; | ||
20 | virtual void apply(); | ||
21 | virtual void undo(); | ||
22 | virtual void endChanges() {} | ||
23 | |||
24 | protected: | ||
25 | Undoable() {} | ||
26 | |||
27 | std::string title; | ||
28 | std::function<void ()> forward; | ||
29 | std::function<void ()> backward; | ||
30 | }; | ||
31 | |||
32 | class UndoableTextBox : public wxTextCtrl { | ||
33 | public: | ||
34 | UndoableTextBox(); | ||
35 | UndoableTextBox(wxWindow* parent, wxWindowID id, wxString startText, std::string undoType, MapeditFrame* realParent, wxPoint pos = wxDefaultPosition, wxSize size = wxDefaultSize, long style = 0); | ||
36 | |||
37 | private: | ||
38 | class Undo : public Undoable { | ||
39 | public: | ||
40 | Undo(std::string title, wxString origText, UndoableTextBox& parent); | ||
41 | void apply(); | ||
42 | void undo(); | ||
43 | void endChanges(); | ||
44 | |||
45 | wxString origText; | ||
46 | wxString newText; | ||
47 | UndoableTextBox& parent; | ||
48 | }; | ||
49 | |||
50 | void Init(); | ||
51 | void OnFocus(wxFocusEvent& event); | ||
52 | void OnKillFocus(wxFocusEvent& event); | ||
53 | void OnTextChange(wxCommandEvent& event); | ||
54 | |||
55 | MapeditFrame* realParent; | ||
56 | std::string undoText; | ||
57 | wxString curText; | ||
58 | std::shared_ptr<Undo> undo; | ||
59 | |||
60 | wxDECLARE_EVENT_TABLE(); | ||
61 | }; | ||
62 | |||
63 | #endif | ||