forked from Wirless/IdlersMapEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor_tabs.cpp
More file actions
248 lines (208 loc) · 5.95 KB
/
editor_tabs.cpp
File metadata and controls
248 lines (208 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "editor_tabs.h"
#include "editor.h"
#include "live_tab.h"
EditorTab::EditorTab() {
;
}
EditorTab::~EditorTab() {
;
}
BEGIN_EVENT_TABLE(MapTabbook, wxPanel)
EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, MapTabbook::OnNotebookPageClose)
EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, MapTabbook::OnNotebookPageChanged)
END_EVENT_TABLE()
MapTabbook::MapTabbook(wxWindow* parent, wxWindowID id) :
wxPanel(parent, id, wxDefaultPosition, wxDefaultSize) {
wxSizer* wxz = newd wxBoxSizer(wxHORIZONTAL);
notebook = newd wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxz->Add(notebook, 1, wxEXPAND);
SetSizerAndFit(wxz);
}
MapTabbook::~MapTabbook() {
;
}
void MapTabbook::CycleTab(bool forward) {
if (!notebook) {
return;
}
int32_t pageCount = notebook->GetPageCount();
int32_t currentSelection = notebook->GetSelection();
int32_t selection;
if (forward) {
selection = (currentSelection + 1) % pageCount;
} else {
selection = (currentSelection - 1 + pageCount) % pageCount;
}
notebook->SetSelection(selection);
}
void MapTabbook::OnNotebookPageClose(wxAuiNotebookEvent& evt) {
EditorTab* editorTab = GetTab(evt.GetInt());
MapTab* mapTab = dynamic_cast<MapTab*>(editorTab);
if (mapTab) {
// Check for detached views first
if (g_gui.HasDetachedViews(mapTab->GetEditor())) {
SetFocusedTab(evt.GetInt());
wxString message = "This map has one or more detached views open.\n";
message += "You must close all detached views before closing the map.";
int choice = wxMessageBox(
message,
"Detached Views Open",
wxOK | wxCANCEL | wxICON_EXCLAMATION
);
if (choice == wxOK) {
// User chose to close detached views
g_gui.CloseDetachedViews(mapTab->GetEditor());
// Process any remaining events and check again
wxYield();
// Verify that all detached views are actually closed
if (g_gui.HasDetachedViews(mapTab->GetEditor())) {
// Some views may still be open, prevent map from closing
wxMessageBox(
"Could not close all detached views. Please close them manually before closing the map.",
"Detached Views Still Open",
wxOK | wxICON_ERROR
);
evt.Veto();
return;
}
} else {
// User canceled operation
evt.Veto();
return;
}
}
if (mapTab->IsUniqueReference() && mapTab->GetMap()) {
bool needRefresh = true;
if (mapTab->GetEditor()->IsLive()) {
if (mapTab->GetMap()->hasChanged()) {
SetFocusedTab(evt.GetInt());
if (!g_gui.root->DoQuerySave(false)) {
needRefresh = false;
evt.Veto();
}
}
}
if (needRefresh) {
g_gui.RefreshPalettes(nullptr, false);
g_gui.UpdateMenus();
}
return;
}
}
LiveLogTab* lt = dynamic_cast<LiveLogTab*>(editorTab);
if (lt && lt->IsConnected()) {
evt.Veto();
}
}
void MapTabbook::OnNotebookPageChanged(wxAuiNotebookEvent& evt) {
g_gui.UpdateMinimap();
int32_t oldSelection = evt.GetOldSelection();
int32_t newSelection = evt.GetSelection();
MapTab* oldMapTab;
if (oldSelection != -1) {
oldMapTab = dynamic_cast<MapTab*>(GetTab(oldSelection));
} else {
oldMapTab = nullptr;
}
MapTab* newMapTab;
if (newSelection != -1) {
newMapTab = dynamic_cast<MapTab*>(GetTab(newSelection));
} else {
newMapTab = nullptr;
}
if (!newMapTab) {
g_gui.RefreshPalettes(nullptr);
} else if (!oldMapTab || !oldMapTab->HasSameReference(newMapTab)) {
g_gui.RefreshPalettes(newMapTab->GetMap());
g_gui.UpdateMenus();
}
if (oldMapTab) {
oldMapTab->VisibilityCheck();
}
if (newMapTab) {
newMapTab->VisibilityCheck();
}
}
void MapTabbook::OnAllowNotebookDND(wxAuiNotebookEvent& evt) {
evt.Allow();
}
// Wrappers
void MapTabbook::AddTab(EditorTab* tab, bool select) {
tab->GetWindow()->Reparent(notebook);
notebook->AddPage(tab->GetWindow(), tab->GetTitle(), select);
conv[tab->GetWindow()] = tab;
}
void MapTabbook::SetFocusedTab(int idx) {
notebook->SetSelection(idx);
}
EditorTab* MapTabbook::GetInternalTab(int idx) {
return conv[notebook->GetPage(idx)];
}
EditorTab* MapTabbook::GetCurrentTab() {
if (GetTabCount() == 0 || GetSelection() == -1) {
return nullptr;
}
return dynamic_cast<EditorTab*>(GetInternalTab(GetSelection()));
}
EditorTab* MapTabbook::GetTab(int idx) {
return GetInternalTab(idx);
}
wxWindow* MapTabbook::GetCurrentPage() {
if (GetTabCount() == 0) {
return nullptr;
}
return GetCurrentTab()->GetWindow();
}
void MapTabbook::OnSwitchEditorMode(EditorMode mode) {
for (int32_t i = 0; i < GetTabCount(); ++i) {
EditorTab* editorTab = GetTab(i);
if (editorTab) {
editorTab->OnSwitchEditorMode(mode);
}
}
}
void MapTabbook::SetTabLabel(int idx, wxString label) {
if (notebook) {
notebook->SetPageText(idx, label);
}
}
void MapTabbook::DeleteTab(int idx) {
if (notebook) {
notebook->DeletePage(idx);
}
}
int MapTabbook::GetTabCount() {
if (notebook) {
return notebook->GetPageCount();
}
return 0;
}
int MapTabbook::GetTabIndex(wxWindow* w) {
if (notebook) {
return notebook->GetPageIndex(w);
}
return 0;
}
int MapTabbook::GetSelection() {
if (notebook) {
return notebook->GetSelection();
}
return 0;
}