Debian Codegraph @

plugins/dm.gui/ReadableEditorDialog.h

raw
1 #pragma once
2
3 #include "icommandsystem.h"
4
5 #include "wxutil/dialog/DialogBase.h"
6 #include "ReadableGuiView.h"
7 #include <map>
8 #include <memory>
9 #include "XDataLoader.h"
10 #include "string/string.h"
11 #include "wxutil/XmlResourceBasedWidget.h"
12
13 class Entity;
14
15 class wxTextCtrl;
16 class wxSpinCtrl;
17 class wxRadioButton;
18 class wxStaticText;
19
20 namespace ui
21 {
22
23 namespace
24 {
25 const std::string RKEY_READABLES_STORAGE_FOLDER = "user/ui/gui/storageFolder";
26 const std::string RKEY_READABLES_CUSTOM_FOLDER = "user/ui/gui/customFolder";
27 }
28
29 ///////////////////////////// ReadableEditorDialog:
30 // The main dialog of the Readable Editor, which implements most editing features.
31 class ReadableEditorDialog :
32 public wxutil::DialogBase,
33 private wxutil::XmlResourceBasedWidget
34 {
35 private:
36 gui::ReadableGuiView* _guiView;
37
38 // The entity we're working with
39 Entity* _entity;
40
41 // The XData-definition of the entity
42 XData::XDataPtr _xData;
43
44 // The filename of the XData definition
45 std::string _xdFilename;
46
47 // The XData filename derived from the map-name.
48 std::string _mapBasedFilename;
49
50 // The xData loader
51 XData::XDataLoaderPtr _xdLoader;
52
53 // The index of the current page.
54 std::size_t _currentPageIndex;
55
56 // Has the XData name been specified?
57 bool _xdNameSpecified;
58
59 // Tells the program whether checkGuiLayout() is already running.
60 bool _runningGuiLayoutCheck;
61
62 // Tells the program whether checkXDataUniqueness is already running.
63 bool _runningXDataUniquenessCheck;
64
65 // Tells the exporter whether to use the _mapBasedFilename (true) or not.
66 bool _useDefaultFilename;
67
68 // Prevents saving races.
69 bool _saveInProgress;
70
71 wxTextCtrl* _nameEntry;
72 wxTextCtrl* _xDataNameEntry;
73
74 wxSpinCtrl* _numPages;
75
76 wxRadioButton* _oneSidedButton;
77 wxRadioButton* _twoSidedButton;
78 wxTextCtrl* _pageTurnEntry;
79 wxStaticText* _curPageDisplay;
80 wxTextCtrl* _guiEntry;
81
82 wxStaticText* _pageLeftLabel;
83 wxStaticText* _pageRightLabel;
84
85 wxTextCtrl* _textViewTitle;
86 wxTextCtrl* _textViewRightTitle;
87 wxTextCtrl* _textViewBody;
88 wxTextCtrl* _textViewRightBody;
89
90 std::unique_ptr<wxMenu> _insertMenu;
91 std::unique_ptr<wxMenu> _deleteMenu;
92 std::unique_ptr<wxMenu> _appendMenu;
93 std::unique_ptr<wxMenu> _prependMenu;
94 std::unique_ptr<wxMenu> _toolsMenu;
95
96 public:
97 // Pass the working entity to the constructor
98 ReadableEditorDialog(Entity* entity);
99
100 static void RunDialog(const cmd::ArgumentList& args);
101
102 // override DialogBase
103 int ShowModal();
104
105 // Switch between the editing modes
106 void useOneSidedEditing();
107 void useTwoSidedEditing();
108
109 // Updates the GUI preview (text updates). Public so that XDataSelector and GuiSelector can access it.
110 // Uses the current data in the readable editor for updating or imports XData/guis by the passed strings.
111 // This Method can create error-messages. For that reason a parent window can be specified. If Null the Readable
112 // Editor Dialog is parent.
113 void updateGuiView(wxWindow* parent = NULL,
114 const std::string& guiPath = "",
115 const std::string& xDataName = "",
116 const std::string& xDataPath = "");
117
118 // Sets some GUI state variables needed for rendering and sets the time for script execution
119 void initGuiState(const gui::IGuiPtr& gui);
120
121 // shows the XData import Summary
122 void showXdImportSummary();
123
124 private:
125 // Save all settings on the entity and exports xdata.
126 bool save();
127
128 // Constructs the storage path for the current XData definition. Used by save-method and for the window-title.
129 std::string constructStoragePath();
130
131 // Refreshes the window title based on the storagepath.
132 void refreshWindowTitle();
133
134 // Retrieves information from the entity and imports xdata. If the user cancels, the window is destroyed in _postshow
135 bool initControlsFromEntity();
136
137 // _show_ TwoSided editing-interface.
138 void toggleTwoSidedEditingInterface(bool show);
139
140 // shows the gui import Summary
141 void showGuiImportSummary();
142
143 // toggles the layout of the xdata object and updates the interface.
144 void toggleLayout();
145
146 // Stores the contents of the current page inside the xData-object.
147 void storeCurrentPage();
148
149 // Stores the contents of all controls in the xData-object.
150 void storeXData();
151
152 // Updates the page related inputs and the preview renderer. Also adds default guis.
153 // Warning: Contents are overwritten. storeCurrentPage() should be called beforehand.
154 void showPage(std::size_t pageIndex);
155
156 // Populates the controls with the information in the xdata object. Adds a default snd_page_turn, if not defined.
157 void populateControlsFromXData();
158
159 // Checks whether the chosen XData name already exists. If it does a popup will ask the user whether it should be imported.
160 void checkXDataUniqueness();
161
162 // Checks whether the specified gui definition matches the pagelayout. Returns FALSE on success.
163 void checkGuiLayout();
164
165 void handleNumberOfPagesChanged();
166
167 // Deleting and inserting of pages.
168 void insertPage();
169 void deletePage();
170
171 // Inserts a page on the right or left side of the current page.
172 void insertSide(bool rightSide);
173
174 // Deletes the left or right side of the current page.
175 void deleteSide(bool rightSide);
176
177 // Ui Creation:
178 void setupGeneralPropertiesInterface();
179 void setupPageRelatedInterface();
180 void setupButtonPanel();
181 void createMenus();
182
183 // Callback methods for Signals:
184 void onCancel(wxCommandEvent& ev);
185 void onSave(wxCommandEvent& ev);
186 void onSaveClose(wxCommandEvent& ev);
187
188 void onBrowseXd(wxCommandEvent& ev);
189 void onBrowseGui(wxCommandEvent& ev);
190 void onFirstPage(wxCommandEvent& ev);
191 void onPrevPage(wxCommandEvent& ev);
192 void onNextPage(wxCommandEvent& ev);
193 void onLastPage(wxCommandEvent& ev);
194
195 void onInsert(wxCommandEvent& ev);
196 void onDelete(wxCommandEvent& ev);
197
198 void onNumPagesChanged(wxSpinEvent& ev);
199 void onToolsClicked(wxCommandEvent& ev);
200 void onMenuItemClick(wxCommandEvent& ev);
201 void onOneSided(wxCommandEvent& ev);
202 void onTwoSided(wxCommandEvent& ev);
203
204 // Callback methods for Events:
205 void onFocusOut(wxFocusEvent& ev);
206 void onChar(wxKeyEvent& ev);
207 void onTextChanged(wxCommandEvent& ev);
208
209 // Helper Methods:
210
211 void showDuplicateDefinitions();
212
213 // Sets the text of a TextView identified by its widget enumerator and scrolls it to the end.
214 void setTextViewAndScroll(wxTextCtrl* view, const std::string& text);
215 };
216
217 } // namespace ui