]>
Commit | Line | Data |
---|---|---|
d7463f75 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: configtoolview.cpp | |
3 | // Purpose: View class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2003-06-04 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
d9ab621e WS |
12 | // For compilers that support precompilation, includes "wx/wx.h". |
13 | #include "wx/wxprec.h" | |
d7463f75 JS |
14 | |
15 | #ifdef __BORLANDC__ | |
d9ab621e | 16 | #pragma hdrstop |
d7463f75 JS |
17 | #endif |
18 | ||
19 | #include "wx/wfstream.h" | |
8d3261f9 | 20 | #include "wx/txtstrm.h" |
d7463f75 JS |
21 | #include "configtoolview.h" |
22 | #include "configtooldoc.h" | |
23 | #include "configtree.h" | |
24 | #include "wxconfigtool.h" | |
25 | #include "mainframe.h" | |
26 | #include "propeditor.h" | |
27 | #include "utils.h" | |
28 | #include "custompropertydialog.h" | |
29 | ||
30 | IMPLEMENT_DYNAMIC_CLASS(ctConfigToolView, wxView) | |
31 | ||
32 | BEGIN_EVENT_TABLE(ctConfigToolView, wxView) | |
33 | EVT_MENU(ctID_ADD_ITEM_CHECKBOX, ctConfigToolView::OnAddCheckBoxItem) | |
34 | EVT_MENU(ctID_ADD_ITEM_RADIOBUTTON, ctConfigToolView::OnAddRadioButtonItem) | |
35 | EVT_MENU(ctID_ADD_ITEM_GROUP, ctConfigToolView::OnAddGroupItem) | |
36 | EVT_MENU(ctID_ADD_ITEM_CHECK_GROUP, ctConfigToolView::OnAddCheckGroupItem) | |
37 | EVT_MENU(ctID_ADD_ITEM_RADIO_GROUP, ctConfigToolView::OnAddRadioGroupItem) | |
38 | EVT_MENU(ctID_ADD_ITEM_STRING, ctConfigToolView::OnAddStringItem) | |
39 | EVT_MENU(ctID_RENAME_ITEM, ctConfigToolView::OnRenameItem) | |
40 | EVT_MENU(ctID_DELETE_ITEM, ctConfigToolView::OnDeleteItem) | |
41 | ||
42 | EVT_MENU(wxID_COPY, ctConfigToolView::OnCopy) | |
43 | EVT_MENU(wxID_CUT, ctConfigToolView::OnCut) | |
44 | EVT_MENU(wxID_PASTE, ctConfigToolView::OnPaste) | |
45 | ||
46 | EVT_UPDATE_UI(wxID_COPY, ctConfigToolView::OnUpdateCopy) | |
47 | EVT_UPDATE_UI(wxID_CUT, ctConfigToolView::OnUpdateCut) | |
48 | EVT_UPDATE_UI(wxID_PASTE, ctConfigToolView::OnUpdatePaste) | |
49 | ||
50 | EVT_MENU(ctID_ITEM_HELP, ctConfigToolView::OnItemHelp) | |
51 | ||
52 | EVT_UPDATE_UI(ctID_ADD_ITEM_CHECKBOX, ctConfigToolView::OnUpdateAddItem) | |
53 | EVT_UPDATE_UI(ctID_ADD_ITEM_RADIOBUTTON, ctConfigToolView::OnUpdateAddItem) | |
54 | EVT_UPDATE_UI(ctID_ADD_ITEM_GROUP, ctConfigToolView::OnUpdateAddItem) | |
55 | EVT_UPDATE_UI(ctID_ADD_ITEM_CHECK_GROUP, ctConfigToolView::OnUpdateAddItem) | |
56 | EVT_UPDATE_UI(ctID_ADD_ITEM_RADIO_GROUP, ctConfigToolView::OnUpdateAddItem) | |
57 | EVT_UPDATE_UI(ctID_ADD_ITEM_STRING, ctConfigToolView::OnUpdateAddItem) | |
58 | EVT_UPDATE_UI(ctID_RENAME_ITEM, ctConfigToolView::OnUpdateCut) | |
59 | EVT_UPDATE_UI(ctID_DELETE_ITEM, ctConfigToolView::OnUpdateCut) | |
60 | EVT_UPDATE_UI(ctID_ITEM_HELP, ctConfigToolView::OnUpdateItemHelp) | |
61 | ||
62 | EVT_MENU(ctID_TREE_COPY, ctConfigToolView::OnContextCopy) | |
63 | EVT_MENU(ctID_TREE_CUT, ctConfigToolView::OnContextCut) | |
64 | EVT_MENU(ctID_TREE_PASTE_BEFORE, ctConfigToolView::OnContextPasteBefore) | |
65 | EVT_MENU(ctID_TREE_PASTE_AFTER, ctConfigToolView::OnContextPasteAfter) | |
66 | EVT_MENU(ctID_TREE_PASTE_AS_CHILD, ctConfigToolView::OnContextPasteAsChild) | |
67 | EVT_UPDATE_UI(ctID_TREE_COPY, ctConfigToolView::OnUpdateContextCopy) | |
68 | EVT_UPDATE_UI(ctID_TREE_CUT, ctConfigToolView::OnUpdateContextCut) | |
69 | EVT_UPDATE_UI(ctID_TREE_PASTE_BEFORE, ctConfigToolView::OnUpdateContextPasteBefore) | |
70 | EVT_UPDATE_UI(ctID_TREE_PASTE_AFTER, ctConfigToolView::OnUpdateContextPasteAfter) | |
71 | EVT_UPDATE_UI(ctID_TREE_PASTE_AS_CHILD, ctConfigToolView::OnUpdateContextPasteAsChild) | |
72 | ||
73 | EVT_MENU(ctID_ADD_CUSTOM_PROPERTY, ctConfigToolView::OnAddCustomProperty) | |
74 | EVT_MENU(ctID_EDIT_CUSTOM_PROPERTY, ctConfigToolView::OnEditCustomProperty) | |
75 | EVT_MENU(ctID_DELETE_CUSTOM_PROPERTY, ctConfigToolView::OnDeleteCustomProperty) | |
76 | EVT_UPDATE_UI(ctID_ADD_CUSTOM_PROPERTY, ctConfigToolView::OnUpdateAddCustomProperty) | |
77 | EVT_UPDATE_UI(ctID_EDIT_CUSTOM_PROPERTY, ctConfigToolView::OnUpdateEditCustomProperty) | |
78 | EVT_UPDATE_UI(ctID_DELETE_CUSTOM_PROPERTY, ctConfigToolView::OnUpdateDeleteCustomProperty) | |
79 | ||
4fe30bce | 80 | EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, ctConfigToolView::OnTabSelect) |
d7463f75 JS |
81 | |
82 | EVT_MENU(ctID_SAVE_SETUP_FILE, ctConfigToolView::OnSaveSetupFile) | |
83 | EVT_MENU(ctID_SAVE_CONFIGURE_COMMAND, ctConfigToolView::OnSaveConfigureCommand) | |
84 | EVT_UPDATE_UI(ctID_SAVE_SETUP_FILE, ctConfigToolView::OnUpdateSaveSetupFile) | |
85 | EVT_UPDATE_UI(ctID_SAVE_CONFIGURE_COMMAND, ctConfigToolView::OnUpdateSaveConfigureCommand) | |
e7767867 JS |
86 | |
87 | EVT_MENU(wxID_FIND, ctConfigToolView::OnFind) | |
88 | EVT_UPDATE_UI(wxID_FIND, ctConfigToolView::OnUpdateFind) | |
89 | ||
afc51590 JS |
90 | EVT_MENU(ctID_GO, ctConfigToolView::OnGo) |
91 | EVT_UPDATE_UI(ctID_GO, ctConfigToolView::OnUpdateGo) | |
92 | ||
d7463f75 JS |
93 | END_EVENT_TABLE() |
94 | ||
d7463f75 JS |
95 | // What to do when a view is created. Creates actual |
96 | // windows for displaying the view. | |
97 | bool ctConfigToolView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) | |
98 | { | |
4fe30bce | 99 | wxGetApp().GetDocManager()->ActivateView(this, true); |
d7463f75 JS |
100 | wxGetApp().GetMainFrame()->SetDocument((ctConfigToolDoc*) doc); |
101 | wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument((ctConfigToolDoc*) doc) ; | |
102 | wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument((ctConfigToolDoc*) doc) ; | |
103 | ||
4fe30bce | 104 | return true; |
d7463f75 JS |
105 | } |
106 | ||
69da0d99 | 107 | void ctConfigToolView::OnDraw(wxDC *WXUNUSED(dc)) |
d7463f75 JS |
108 | { |
109 | } | |
110 | ||
111 | void ctConfigToolView::OnUpdate(wxView *WXUNUSED(sender), wxObject *hintObj) | |
112 | { | |
113 | ctConfigToolDoc* doc = wxDynamicCast(GetDocument(), ctConfigToolDoc); | |
114 | ctConfigTreeCtrl* treeCtrl = wxGetApp().GetMainFrame()->GetConfigTreeCtrl(); | |
115 | if (!treeCtrl) | |
116 | return; | |
254a2129 | 117 | |
d7463f75 | 118 | wxASSERT (doc != NULL); |
254a2129 | 119 | |
d7463f75 | 120 | ctConfigItem* selItem = NULL; |
254a2129 | 121 | |
d7463f75 JS |
122 | wxTreeItemId sel = treeCtrl->GetSelection(); |
123 | if (sel.IsOk()) | |
124 | { | |
125 | ctTreeItemData* data = (ctTreeItemData*) treeCtrl->GetItemData(sel); | |
126 | if (data) | |
127 | selItem = data->GetConfigItem() ; | |
128 | } | |
254a2129 | 129 | |
d7463f75 JS |
130 | ctConfigToolHint* hint = (ctConfigToolHint*) hintObj; |
131 | int hintOp = ctNoHint; | |
132 | if (hint) | |
133 | hintOp = hint->m_op; | |
254a2129 | 134 | |
d7463f75 JS |
135 | switch (hintOp) |
136 | { | |
137 | case ctInitialUpdate: | |
138 | { | |
139 | if (doc && doc->GetTopItem()) | |
140 | { | |
141 | wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->DeleteAllItems(); | |
142 | AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), doc->GetTopItem()); | |
143 | wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Expand(doc->GetTopItem()->GetTreeItemId()); | |
144 | } | |
145 | } | |
146 | break; | |
254a2129 | 147 | case ctSelChanged: |
d7463f75 JS |
148 | { |
149 | if (selItem) | |
150 | { | |
151 | wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem); | |
254a2129 | 152 | } |
d7463f75 JS |
153 | } |
154 | break; | |
155 | case ctAllSaved: | |
156 | { | |
157 | // TODO: update windows and frame title | |
158 | } | |
159 | break; | |
160 | case ctFilenameChanged: | |
161 | { | |
162 | wxGetApp().GetMainFrame()->UpdateFrameTitle(); | |
163 | } | |
164 | break; | |
165 | case ctClear: | |
166 | { | |
167 | // TODO: update windows | |
168 | treeCtrl->DeleteAllItems(); | |
169 | wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(NULL); | |
170 | break; | |
254a2129 | 171 | } |
d7463f75 JS |
172 | case ctValueChanged: |
173 | { | |
174 | // ctConfigItem& ti = *(ctConfigItem *)hint->m_item; | |
175 | wxGetApp().GetMainFrame()->GetPropertyEditor()->ShowItem(selItem); | |
254a2129 | 176 | } |
d7463f75 | 177 | break; |
254a2129 | 178 | |
d7463f75 JS |
179 | default: |
180 | break; | |
181 | } | |
182 | } | |
183 | ||
184 | // Clean up windows used for displaying the view. | |
69da0d99 | 185 | bool ctConfigToolView::OnClose(bool WXUNUSED(deleteWindow)) |
d7463f75 JS |
186 | { |
187 | if (!GetDocument()->Close()) | |
4fe30bce | 188 | return false; |
d7463f75 JS |
189 | |
190 | ctConfigToolHint hint(NULL, ctClear); | |
191 | GetDocument()->UpdateAllViews (NULL, & hint); | |
192 | ||
4fe30bce | 193 | wxGetApp().GetDocManager()->ActivateView(this, false); |
d7463f75 | 194 | |
4fe30bce | 195 | Activate(false); |
254a2129 | 196 | |
d7463f75 JS |
197 | wxGetApp().GetMainFrame()->SetDocument(NULL); |
198 | wxGetApp().GetMainFrame()->GetSetupPage()->SetDocument(NULL) ; | |
199 | wxGetApp().GetMainFrame()->GetConfigurePage()->SetDocument(NULL) ; | |
200 | ||
4fe30bce | 201 | return true; |
d7463f75 JS |
202 | } |
203 | ||
204 | void ctConfigToolView::OnChangeFilename() | |
205 | { | |
206 | if (wxGetApp().GetTopWindow() && GetDocument()) | |
207 | { | |
208 | wxString docTitle(wxFileNameFromPath(GetDocument()->GetFilename())); | |
209 | wxStripExtension(docTitle); | |
210 | GetDocument()->SetTitle(docTitle); | |
211 | ||
212 | wxString name(GetDocument()->GetFilename()); | |
213 | wxStripExtension(name); | |
214 | ||
215 | wxString title; | |
216 | ||
217 | wxString modifiedMarker; | |
218 | if (GetDocument()->IsModified()) | |
219 | modifiedMarker = wxT("*"); | |
220 | ||
221 | title = docTitle + modifiedMarker + wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName() ; | |
222 | ||
223 | ((wxFrame*) wxGetApp().GetTopWindow())->SetTitle(title); | |
224 | } | |
225 | } | |
226 | ||
227 | // General disabler | |
228 | void ctConfigToolView::OnUpdateDisable(wxUpdateUIEvent& event) | |
229 | { | |
4fe30bce | 230 | event.Enable( false ); |
d7463f75 JS |
231 | } |
232 | ||
233 | void ctConfigToolView::OnUpdateAddItem(wxUpdateUIEvent& event) | |
234 | { | |
4fe30bce | 235 | event.Enable( true ); |
d7463f75 JS |
236 | } |
237 | ||
238 | /// Add item and its children to the tree | |
239 | void ctConfigToolView::AddItems(ctConfigTreeCtrl* treeControl, ctConfigItem* item) | |
240 | { | |
241 | SyncItem(treeControl, item); | |
242 | ||
243 | int count = item->GetChildCount(); | |
244 | int i; | |
245 | for (i = 0; i < count; i++) | |
246 | { | |
247 | ctConfigItem* child = item->GetChild(i); | |
248 | AddItems(treeControl, child); | |
249 | } | |
250 | } | |
251 | ||
252 | /// Gets the tree item in sync with the item | |
253 | void ctConfigToolView::SyncItem(ctConfigTreeCtrl* treeControl, ctConfigItem* item) | |
254 | { | |
255 | if (!item->GetTreeItemId().IsOk()) | |
256 | { | |
257 | if (!item->GetParent()) | |
258 | { | |
677ded95 | 259 | item->SetTreeItem(treeControl->AddRoot(wxEmptyString, -1, -1, new ctTreeItemData(item))); |
d7463f75 JS |
260 | } |
261 | else | |
262 | { | |
263 | // Find the item to insert the new item after. | |
264 | ctConfigItem* previousItem = item->FindPreviousSibling(); | |
265 | if (previousItem && previousItem->GetTreeItemId().IsOk()) | |
266 | { | |
267 | item->SetTreeItem(treeControl->InsertItem(item->GetParent()->GetTreeItemId(), | |
268 | previousItem->GetTreeItemId(), | |
269 | item->GetName(), -1, -1, new ctTreeItemData(item))); | |
270 | } | |
271 | else if (!previousItem && item->GetParent()->GetChildCount() > 1 | |
272 | ) | |
273 | { | |
274 | // Insert at the beginning | |
275 | item->SetTreeItem(treeControl->InsertItem(item->GetParent()->GetTreeItemId(), | |
276 | (size_t) 0, // Insert at first position | |
277 | item->GetName(), -1, -1, new ctTreeItemData(item))); | |
278 | } | |
279 | else | |
280 | { | |
281 | item->SetTreeItem(treeControl->AppendItem(item->GetParent()->GetTreeItemId(), | |
282 | item->GetName(), -1, -1, new ctTreeItemData(item))); | |
283 | } | |
284 | } | |
285 | } | |
286 | ||
287 | if (item->GetTreeItemId().IsOk()) | |
288 | { | |
289 | treeControl->SetItemText(item->GetTreeItemId(), item->GetName()); | |
290 | ||
291 | int iconId = 0; | |
292 | ||
293 | if (item->GetType() == ctTypeGroup) | |
294 | { | |
295 | iconId = treeControl->GetIconTable().GetIconId(wxT("Group"), 0, item->IsActive()); | |
296 | } | |
297 | else if (item->GetType() == ctTypeCheckGroup) | |
298 | { | |
299 | iconId = treeControl->GetIconTable().GetIconId(wxT("CheckGroup"), item->IsEnabled() ? 0 : 1, item->IsActive()); | |
300 | } | |
301 | else if (item->GetType() == ctTypeRadioGroup) | |
302 | { | |
303 | iconId = treeControl->GetIconTable().GetIconId(wxT("RadioGroup"), item->IsEnabled() ? 0 : 1, item->IsActive()); | |
304 | } | |
305 | else if (item->GetType() == ctTypeBoolCheck) | |
306 | { | |
307 | iconId = treeControl->GetIconTable().GetIconId(wxT("Checkbox"), item->IsEnabled() ? 0 : 1, item->IsActive()); | |
308 | } | |
309 | else if (item->GetType() == ctTypeBoolRadio) | |
310 | { | |
311 | iconId = treeControl->GetIconTable().GetIconId(wxT("Radiobutton"), item->IsEnabled() ? 0 : 1, item->IsActive()); | |
312 | } | |
313 | treeControl->SetItemImage(item->GetTreeItemId(), iconId, wxTreeItemIcon_Normal); | |
314 | treeControl->SetItemImage(item->GetTreeItemId(), iconId, wxTreeItemIcon_Selected); | |
315 | ||
316 | if (treeControl->GetSelection() == item->GetTreeItemId()) | |
317 | { | |
318 | if (wxGetApp().GetMainFrame()->GetPropertyEditor()->GetItem()) | |
319 | wxGetApp().GetMainFrame()->GetPropertyEditor()->UpdateTitle(); | |
320 | } | |
321 | } | |
322 | } | |
323 | ||
324 | /// Clicked an icon | |
325 | void ctConfigToolView::OnIconLeftDown(ctConfigTreeCtrl* treeControl, ctConfigItem* item) | |
326 | { | |
327 | if (!item->IsActive()) | |
328 | return; | |
329 | ||
330 | if (item->GetType() == ctTypeCheckGroup || | |
331 | item->GetType() == ctTypeBoolCheck || | |
332 | item->GetType() == ctTypeBoolRadio || | |
333 | item->GetType() == ctTypeRadioGroup | |
334 | ) | |
335 | { | |
336 | // Don't toggle a radio button that's already | |
337 | // enabled. | |
338 | if ((item->GetType() == ctTypeBoolRadio || item->GetType() == ctTypeRadioGroup) | |
339 | && item->IsEnabled()) | |
340 | return; | |
341 | ||
342 | item->Enable(!item->IsEnabled()); | |
343 | ||
4fe30bce | 344 | GetDocument()->Modify(true); |
d7463f75 JS |
345 | OnChangeFilename(); |
346 | ||
347 | SyncItem(treeControl, item); | |
348 | ||
349 | wxList considered; | |
d7463f75 JS |
350 | if ((item->GetType() == ctTypeBoolRadio || item->GetType() == ctTypeRadioGroup) && item->IsEnabled()) |
351 | { | |
352 | item->PropagateRadioButton(considered); | |
353 | } | |
afc51590 JS |
354 | item->PropagateChange(considered); |
355 | ||
356 | // Update the setup.h and configure text | |
357 | if (wxGetApp().GetMainFrame()->GetMainNotebook()->GetSelection() > 0) | |
358 | { | |
359 | RegenerateSetup(); | |
360 | } | |
d7463f75 JS |
361 | } |
362 | } | |
363 | ||
364 | /// Returns the selected config item, if any. | |
365 | ctConfigItem* ctConfigToolView::GetSelection() | |
366 | { | |
367 | wxTreeCtrl* treeCtrl = wxGetApp().GetMainFrame()->GetConfigTreeCtrl(); | |
368 | if (!treeCtrl) | |
369 | return NULL; | |
370 | ||
371 | wxTreeItemId sel = treeCtrl->GetSelection(); | |
372 | if (sel.IsOk()) | |
373 | { | |
374 | ctTreeItemData* data = (ctTreeItemData*) treeCtrl->GetItemData(sel); | |
375 | if (data) | |
376 | return data->GetConfigItem() ; | |
377 | } | |
378 | return NULL; | |
379 | } | |
380 | ||
381 | /// Add a checkbox item | |
69da0d99 | 382 | void ctConfigToolView::OnAddCheckBoxItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
383 | { |
384 | AddItem(ctTypeBoolCheck, _("New checkbox item")); | |
385 | } | |
386 | ||
387 | /// Add a radiobutton item | |
69da0d99 | 388 | void ctConfigToolView::OnAddRadioButtonItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
389 | { |
390 | AddItem(ctTypeBoolRadio, _("New radio button item")); | |
391 | } | |
392 | ||
393 | /// Add a group item | |
69da0d99 | 394 | void ctConfigToolView::OnAddGroupItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
395 | { |
396 | AddItem(ctTypeGroup, _("New group item")); | |
397 | } | |
398 | ||
399 | /// Add a group option item | |
69da0d99 | 400 | void ctConfigToolView::OnAddCheckGroupItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
401 | { |
402 | AddItem(ctTypeCheckGroup, _("New check group item")); | |
403 | } | |
404 | ||
405 | /// Add a group option item | |
69da0d99 | 406 | void ctConfigToolView::OnAddRadioGroupItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
407 | { |
408 | AddItem(ctTypeRadioGroup, _("New radio group item")); | |
409 | } | |
410 | ||
411 | /// Add a string item | |
69da0d99 | 412 | void ctConfigToolView::OnAddStringItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
413 | { |
414 | AddItem(ctTypeString, _("New string item")); | |
415 | } | |
416 | ||
417 | /// Add an item | |
418 | void ctConfigToolView::AddItem(ctConfigType type, const wxString& msg) | |
419 | { | |
420 | ctConfigItem* sel = GetSelection(); | |
421 | if (sel) | |
422 | { | |
677ded95 WS |
423 | wxString name = wxGetTextFromUser(_("Please enter a name for the new item."), msg); |
424 | if (!name.empty()) | |
d7463f75 JS |
425 | { |
426 | ctConfigItem* parent ; | |
427 | ctConfigItem* insertBefore ; | |
428 | if (sel->CanHaveChildren()) | |
429 | { | |
430 | parent = sel; | |
431 | insertBefore = NULL; | |
432 | } | |
433 | else | |
434 | { | |
435 | parent = sel->GetParent(); | |
436 | insertBefore = sel->FindNextSibling(); | |
437 | } | |
254a2129 | 438 | |
d7463f75 JS |
439 | ctConfigItem* newItem = new ctConfigItem(NULL, type, name); |
440 | newItem->InitProperties(); | |
441 | ||
442 | newItem->GetDocument()->GetCommandProcessor()->Submit( | |
443 | new ctConfigCommand(msg, ctCMD_NEW_ELEMENT, NULL, newItem, | |
444 | parent, insertBefore)); | |
445 | } | |
446 | } | |
447 | } | |
448 | ||
449 | /// Delete an item | |
69da0d99 | 450 | void ctConfigToolView::OnDeleteItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
451 | { |
452 | ctConfigItem* sel = GetSelection(); | |
453 | if (sel) | |
454 | { | |
f8105809 | 455 | wxString name(sel->GetName()); |
d7463f75 | 456 | wxString msg; |
f8105809 | 457 | msg.Printf(_("Delete %s?"), (const wxChar*) name); |
d7463f75 JS |
458 | if (wxYES == wxMessageBox(msg, _("Delete item"), wxICON_QUESTION|wxYES_NO)) |
459 | { | |
460 | wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(sel->GetTreeItemId()); | |
461 | } | |
462 | } | |
463 | } | |
464 | ||
465 | /// Rename an item | |
69da0d99 | 466 | void ctConfigToolView::OnRenameItem(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
467 | { |
468 | ctConfigItem* sel = GetSelection(); | |
469 | if (sel) | |
470 | { | |
471 | wxString name = wxGetTextFromUser(_("Please enter a new name for the item."), | |
472 | _("Rename item"), sel->GetName()); | |
677ded95 | 473 | if (!name.empty()) |
d7463f75 JS |
474 | { |
475 | sel->SetName(name); | |
476 | SyncItem(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), sel); | |
477 | ||
478 | ctConfigToolHint hint(NULL, ctSelChanged); | |
479 | GetDocument()->UpdateAllViews (NULL, & hint); | |
480 | } | |
481 | } | |
482 | } | |
483 | ||
484 | /// Copy an item to the clipboard | |
69da0d99 | 485 | void ctConfigToolView::OnCopy(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
486 | { |
487 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
488 | ctConfigItem* sel = GetSelection(); | |
489 | if (sel) | |
490 | { | |
491 | doc->SetClipboardItem(sel->DeepClone()); | |
492 | } | |
493 | } | |
494 | ||
495 | /// Copy an item to the clipboard and cut the item | |
69da0d99 | 496 | void ctConfigToolView::OnCut(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
497 | { |
498 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
499 | ctConfigItem* sel = GetSelection(); | |
500 | if (sel) | |
501 | { | |
502 | { | |
503 | ctConfigCommand* cmd = new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT, | |
504 | sel, (ctConfigItem*) NULL); | |
505 | doc->GetCommandProcessor()->Submit(cmd); | |
506 | } | |
507 | } | |
508 | } | |
509 | ||
510 | /// Paste an item from the clipboard to the tree | |
69da0d99 | 511 | void ctConfigToolView::OnPaste(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
512 | { |
513 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
514 | ctConfigItem* sel = GetSelection(); | |
515 | if (sel && doc->GetClipboardItem()) | |
516 | { | |
517 | ctConfigItem* parent ; | |
518 | ctConfigItem* insertBefore ; | |
519 | if (sel->CanHaveChildren()) | |
520 | { | |
521 | parent = sel; | |
522 | insertBefore = NULL; | |
523 | } | |
524 | else | |
525 | { | |
526 | parent = sel->GetParent(); | |
527 | insertBefore = sel->FindNextSibling(); | |
528 | } | |
529 | ||
530 | ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone(); | |
531 | ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE, | |
532 | NULL, newItem, parent, insertBefore); | |
533 | doc->GetCommandProcessor()->Submit(cmd); | |
534 | } | |
535 | } | |
536 | ||
537 | /// Update for copy command | |
538 | void ctConfigToolView::OnUpdateCopy(wxUpdateUIEvent& event) | |
539 | { | |
540 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
541 | event.Enable( doc && GetSelection() && GetSelection()->GetParent() ); | |
542 | } | |
543 | ||
544 | /// Update for cut | |
545 | void ctConfigToolView::OnUpdateCut(wxUpdateUIEvent& event) | |
546 | { | |
547 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
548 | event.Enable( doc && GetSelection() && GetSelection()->GetParent() ); | |
549 | } | |
550 | ||
551 | /// Update for paste | |
552 | void ctConfigToolView::OnUpdatePaste(wxUpdateUIEvent& event) | |
553 | { | |
554 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
555 | event.Enable( doc && doc->GetClipboardItem() && GetSelection() ); | |
556 | } | |
557 | ||
558 | /// Copy an item to the clipboard | |
69da0d99 | 559 | void ctConfigToolView::OnContextCopy(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
560 | { |
561 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
562 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
563 | if (doc && sel) | |
564 | { | |
565 | doc->SetClipboardItem(sel->DeepClone()); | |
566 | } | |
567 | } | |
568 | ||
569 | /// Copy an item to the clipboard and cut the item | |
69da0d99 | 570 | void ctConfigToolView::OnContextCut(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
571 | { |
572 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
573 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
574 | if (sel) | |
575 | { | |
576 | { | |
577 | ctConfigCommand* cmd = new ctConfigCommand(wxT("Cut Config Item"), ctCMD_CUT, | |
578 | sel, (ctConfigItem*) NULL); | |
579 | doc->GetCommandProcessor()->Submit(cmd); | |
580 | } | |
581 | } | |
582 | } | |
583 | ||
584 | /// Paste an item from the clipboard to the tree | |
69da0d99 | 585 | void ctConfigToolView::OnContextPasteBefore(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
586 | { |
587 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
588 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
589 | if (sel && doc->GetClipboardItem()) | |
590 | { | |
591 | ctConfigItem* parent = sel->GetParent(); | |
592 | ctConfigItem* insertBefore = sel; | |
593 | ||
594 | ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone(); | |
595 | ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE, | |
596 | NULL, newItem, parent, insertBefore); | |
597 | doc->GetCommandProcessor()->Submit(cmd); | |
598 | } | |
599 | } | |
600 | ||
601 | /// Paste an item from the clipboard to the tree | |
69da0d99 | 602 | void ctConfigToolView::OnContextPasteAfter(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
603 | { |
604 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
605 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
606 | if (sel && doc->GetClipboardItem()) | |
607 | { | |
608 | ctConfigItem* parent = sel->GetParent(); | |
609 | ctConfigItem* insertBefore = sel->FindNextSibling(); | |
610 | ||
611 | ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone(); | |
612 | ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE, | |
613 | NULL, newItem, parent, insertBefore); | |
614 | doc->GetCommandProcessor()->Submit(cmd); | |
615 | } | |
616 | } | |
617 | ||
618 | /// Paste an item from the clipboard to the tree | |
69da0d99 | 619 | void ctConfigToolView::OnContextPasteAsChild(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
620 | { |
621 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
622 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
623 | if (sel && doc->GetClipboardItem()) | |
624 | { | |
625 | if (sel->CanHaveChildren()) | |
626 | { | |
627 | ctConfigItem* parent = sel; | |
628 | ctConfigItem* insertBefore = NULL; | |
254a2129 | 629 | |
d7463f75 JS |
630 | ctConfigItem* newItem = doc->GetClipboardItem()->DeepClone(); |
631 | ctConfigCommand* cmd = new ctConfigCommand(wxT("Paste Config Item"), ctCMD_PASTE, | |
632 | NULL, newItem, parent, insertBefore); | |
633 | doc->GetCommandProcessor()->Submit(cmd); | |
634 | } | |
635 | } | |
636 | } | |
637 | ||
638 | /// Copy an item to the clipboard | |
639 | void ctConfigToolView::OnUpdateContextCopy(wxUpdateUIEvent& event) | |
640 | { | |
641 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
642 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
643 | event.Enable( doc && sel && sel->GetParent() ); | |
644 | } | |
645 | ||
646 | /// Copy an item to the clipboard and cut the item | |
647 | void ctConfigToolView::OnUpdateContextCut(wxUpdateUIEvent& event) | |
648 | { | |
649 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
650 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
651 | event.Enable( doc && sel && sel->GetParent() ); | |
652 | } | |
653 | ||
654 | /// Paste an item from the clipboard to the tree | |
655 | void ctConfigToolView::OnUpdateContextPasteBefore(wxUpdateUIEvent& event) | |
656 | { | |
657 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
658 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
659 | event.Enable( doc && sel && sel->GetParent() && doc->GetClipboardItem() ); | |
660 | } | |
661 | ||
662 | /// Paste an item from the clipboard to the tree | |
663 | void ctConfigToolView::OnUpdateContextPasteAfter(wxUpdateUIEvent& event) | |
664 | { | |
665 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
666 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
667 | event.Enable( doc && sel && sel->GetParent() && doc->GetClipboardItem() ); | |
668 | } | |
669 | ||
670 | /// Paste an item from the clipboard to the tree | |
671 | void ctConfigToolView::OnUpdateContextPasteAsChild(wxUpdateUIEvent& event) | |
672 | { | |
673 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
674 | ctConfigItem* sel = wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetContextItem(); | |
675 | event.Enable( doc && sel && sel->CanHaveChildren() && doc->GetClipboardItem() ); | |
676 | } | |
677 | ||
678 | /// Item help | |
69da0d99 | 679 | void ctConfigToolView::OnItemHelp(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
680 | { |
681 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
682 | if ( doc && GetSelection() ) | |
683 | { | |
684 | wxString helpTopic = GetSelection()->GetPropertyString(wxT("help-topic")); | |
677ded95 | 685 | if (!helpTopic.empty()) |
d7463f75 JS |
686 | { |
687 | wxGetApp().GetReferenceHelpController().DisplaySection(helpTopic); | |
688 | } | |
689 | } | |
690 | } | |
691 | ||
692 | /// Item help update | |
693 | void ctConfigToolView::OnUpdateItemHelp(wxUpdateUIEvent& event) | |
694 | { | |
695 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
696 | event.Enable( doc && GetSelection() ); | |
697 | } | |
698 | ||
699 | /// Add a custom property | |
69da0d99 | 700 | void ctConfigToolView::OnAddCustomProperty(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
701 | { |
702 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
703 | ctConfigItem* sel = GetSelection(); | |
704 | ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor(); | |
705 | if (doc && sel && editor) | |
706 | { | |
707 | ctCustomPropertyDialog dialog(wxGetApp().GetMainFrame(), | |
4fe30bce | 708 | wxID_ANY, _("Add a custom property")); |
d7463f75 JS |
709 | if (dialog.ShowModal() == wxID_OK) |
710 | { | |
711 | wxString name = dialog.GetPropertyName(); | |
712 | wxString type = dialog.GetPropertyType(); | |
713 | wxString descr = dialog.GetPropertyDescription(); | |
714 | wxString editorType = dialog.GetEditorType(); | |
715 | wxArrayString choices = dialog.GetChoices(); | |
716 | ||
717 | if (sel->GetProperties().FindProperty(name)) | |
718 | { | |
719 | wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"), | |
720 | wxOK|wxICON_INFORMATION); | |
721 | return; | |
722 | } | |
723 | ctProperty* property = new ctProperty; | |
724 | if (type == wxT("bool")) | |
4fe30bce | 725 | property->GetVariant() = wxVariant(false, name); |
d7463f75 JS |
726 | else if (type == wxT("double")) |
727 | property->GetVariant() = wxVariant((double) 0.0, name); | |
728 | else if (type == wxT("long")) | |
729 | property->GetVariant() = wxVariant((long) 0, name); | |
730 | else | |
677ded95 | 731 | property->GetVariant() = wxVariant(wxEmptyString, name); |
4fe30bce | 732 | property->SetCustom(true); |
d7463f75 JS |
733 | property->SetDescription(descr); |
734 | property->SetChoices(choices); | |
735 | property->SetEditorType(editorType); | |
736 | ||
737 | sel->GetProperties().AddProperty(property); | |
738 | editor->ShowItem(sel); | |
739 | OnChangeFilename(); | |
740 | } | |
741 | } | |
742 | } | |
743 | ||
744 | /// Edit a custom property | |
69da0d99 | 745 | void ctConfigToolView::OnEditCustomProperty(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
746 | { |
747 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
748 | ctConfigItem* sel = GetSelection(); | |
749 | ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor(); | |
750 | if (doc && sel && editor) | |
751 | { | |
752 | int row; | |
753 | ctProperty* property = editor->FindSelectedProperty(row) ; | |
754 | if (property && property->IsCustom()) | |
755 | { | |
756 | wxString oldName = property->GetName(); | |
757 | wxString oldDescription = property->GetDescription(); | |
758 | wxString oldType = property->GetVariant().GetType(); | |
759 | wxString oldEditorType = property->GetEditorType(); | |
760 | wxArrayString oldChoices = property->GetChoices(); | |
254a2129 | 761 | |
d7463f75 | 762 | ctCustomPropertyDialog dialog(wxGetApp().GetMainFrame(), |
4fe30bce | 763 | wxID_ANY, _("Edit custom property")); |
d7463f75 JS |
764 | dialog.SetPropertyName(oldName); |
765 | dialog.SetPropertyType(oldType); | |
766 | dialog.SetPropertyDescription(oldDescription); | |
767 | if (dialog.ShowModal() == wxID_OK) | |
768 | { | |
769 | wxString name = dialog.GetPropertyName(); | |
770 | wxString type = dialog.GetPropertyType(); | |
771 | wxString editorType = dialog.GetEditorType(); | |
772 | wxArrayString choices = dialog.GetChoices(); | |
773 | wxString descr = dialog.GetPropertyDescription(); | |
254a2129 | 774 | |
d7463f75 JS |
775 | if (name != oldName && sel->GetProperties().FindProperty(name)) |
776 | { | |
777 | wxMessageBox(_("Sorry, this name already exists."), _T("Add custom property"), | |
778 | wxOK|wxICON_INFORMATION); | |
779 | return; | |
780 | } | |
781 | if (type != oldType) | |
782 | { | |
783 | if (type == wxT("bool")) | |
4fe30bce | 784 | property->GetVariant() = wxVariant(false, name); |
d7463f75 JS |
785 | else if (type == wxT("double")) |
786 | property->GetVariant() = wxVariant((double) 0.0, name); | |
787 | else if (type == wxT("long")) | |
788 | property->GetVariant() = wxVariant((long) 0, name); | |
789 | else | |
677ded95 | 790 | property->GetVariant() = wxVariant(wxEmptyString, name); |
d7463f75 JS |
791 | } |
792 | if (name != oldName) | |
793 | property->GetVariant().SetName(name); | |
794 | ||
795 | if (choices != oldChoices) | |
796 | property->SetChoices(choices); | |
797 | ||
798 | if (editorType != oldEditorType) | |
799 | property->SetEditorType(editorType); | |
800 | ||
801 | if (name != oldName) | |
802 | property->GetVariant().SetName(name); | |
803 | ||
4fe30bce | 804 | property->SetCustom(true); |
d7463f75 JS |
805 | |
806 | if (descr != oldDescription) | |
807 | property->SetDescription(descr); | |
254a2129 | 808 | |
d7463f75 JS |
809 | editor->ShowItem(sel); |
810 | OnChangeFilename(); | |
811 | } | |
812 | } | |
813 | } | |
814 | } | |
815 | ||
816 | /// Delete a custom property | |
69da0d99 | 817 | void ctConfigToolView::OnDeleteCustomProperty(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
818 | { |
819 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
820 | ctConfigItem* sel = GetSelection(); | |
821 | ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor(); | |
822 | if (doc && sel && editor) | |
823 | { | |
824 | int row; | |
825 | ctProperty* property = editor->FindSelectedProperty(row) ; | |
826 | if (property && property->IsCustom()) | |
827 | { | |
828 | wxString name(property->GetName()); | |
829 | wxString msg; | |
830 | msg.Printf(_("Delete custom property '%s'?"), (const wxChar*) name); | |
831 | if (wxYES == wxMessageBox(msg, _("Delete property"), wxICON_EXCLAMATION|wxYES_NO)) | |
832 | { | |
833 | sel->GetProperties().RemoveProperty(property); | |
834 | editor->ShowItem(sel); | |
835 | delete property; | |
836 | OnChangeFilename(); | |
837 | } | |
838 | } | |
839 | } | |
840 | } | |
841 | ||
842 | /// Add a custom property: update event | |
843 | void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent& event) | |
844 | { | |
845 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
846 | event.Enable( doc && GetSelection() && GetSelection()->GetParent() ); | |
847 | } | |
848 | ||
849 | /// Edit a custom property: update event | |
850 | void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent& event) | |
851 | { | |
852 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
853 | ctConfigItem* sel = GetSelection(); | |
854 | ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor(); | |
855 | int row; | |
856 | event.Enable( doc && sel && sel->GetParent() && editor && | |
857 | editor->FindSelectedProperty(row) && | |
858 | editor->FindSelectedProperty(row)->IsCustom() ); | |
859 | } | |
860 | ||
861 | /// Delete a custom property: update event | |
862 | void ctConfigToolView::OnUpdateDeleteCustomProperty(wxUpdateUIEvent& event) | |
863 | { | |
864 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
865 | ctConfigItem* sel = GetSelection(); | |
866 | ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor(); | |
867 | int row; | |
868 | event.Enable( doc && sel && sel->GetParent() && editor && | |
869 | editor->FindSelectedProperty(row) && | |
870 | editor->FindSelectedProperty(row)->IsCustom() ); | |
871 | } | |
872 | ||
873 | /// Regenerate setup.h and configure command | |
874 | void ctConfigToolView::RegenerateSetup() | |
875 | { | |
876 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
877 | ctOutputWindow* setupPage = wxGetApp().GetMainFrame()->GetSetupPage() ; | |
878 | ctOutputWindow* configurePage = wxGetApp().GetMainFrame()->GetConfigurePage() ; | |
879 | ||
880 | wxString setupStr = doc->GenerateSetup(); | |
881 | wxString configureStr = doc->GenerateConfigureCommand(); | |
882 | ||
883 | setupPage->SetText(setupStr); | |
884 | configurePage->SetText(configureStr); | |
885 | } | |
886 | ||
887 | /// Regenerate if selected a tab | |
888 | void ctConfigToolView::OnTabSelect(wxNotebookEvent& event) | |
889 | { | |
890 | if (wxGetApp().GetMainFrame()->GetMainNotebook() != event.GetEventObject()) | |
891 | { | |
892 | event.Skip(); | |
893 | return; | |
894 | } | |
895 | ||
896 | if (event.GetSelection() > 0) | |
897 | { | |
898 | RegenerateSetup(); | |
899 | } | |
900 | } | |
901 | ||
69da0d99 | 902 | void ctConfigToolView::OnSaveSetupFile(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
903 | { |
904 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
905 | wxString setupStr = doc->GenerateSetup(); | |
906 | ||
907 | wxString filename = _T("setup.h"); | |
afc51590 | 908 | wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir; |
677ded95 | 909 | if (path.empty()) |
4fe30bce | 910 | path = doc->GetFrameworkDir(false); |
d7463f75 | 911 | wxString wildcard = _T("Header files (*.h)|*.h|All files (*.*)|*.*"); |
254a2129 | 912 | |
d7463f75 JS |
913 | wxFileDialog dialog(wxTheApp->GetTopWindow(), |
914 | _("Save Setup File As"), | |
915 | path, filename , | |
916 | wildcard, wxSAVE|wxOVERWRITE_PROMPT); | |
254a2129 | 917 | |
d7463f75 JS |
918 | if (dialog.ShowModal() == wxID_OK) |
919 | { | |
920 | wxString fullPath = dialog.GetPath(); | |
afc51590 | 921 | wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); |
d7463f75 | 922 | |
8d3261f9 WS |
923 | wxFileOutputStream osFile(fullPath); |
924 | if (!osFile.Ok()) | |
d7463f75 JS |
925 | { |
926 | wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK); | |
927 | return; | |
928 | } | |
929 | ||
8d3261f9 | 930 | wxTextOutputStream stream(osFile); |
d7463f75 | 931 | stream << setupStr; |
254a2129 | 932 | } |
d7463f75 JS |
933 | } |
934 | ||
69da0d99 | 935 | void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent& WXUNUSED(event)) |
d7463f75 JS |
936 | { |
937 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
938 | wxString configureStr = doc->GenerateConfigureCommand(); | |
939 | ||
940 | wxString filename = _T("configurewx.sh"); | |
afc51590 | 941 | wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir; |
677ded95 | 942 | if (path.empty()) |
4fe30bce | 943 | path = doc->GetFrameworkDir(false); |
d7463f75 | 944 | wxString wildcard = _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*"); |
254a2129 | 945 | |
d7463f75 JS |
946 | wxFileDialog dialog(wxTheApp->GetTopWindow(), |
947 | _("Save Configure Command File As"), | |
948 | path, filename , | |
949 | wildcard, wxSAVE|wxOVERWRITE_PROMPT); | |
254a2129 | 950 | |
d7463f75 JS |
951 | if (dialog.ShowModal() == wxID_OK) |
952 | { | |
953 | wxString fullPath = dialog.GetPath(); | |
afc51590 | 954 | wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); |
d7463f75 | 955 | |
8d3261f9 WS |
956 | wxFileOutputStream osFile(fullPath); |
957 | if (!osFile.Ok()) | |
d7463f75 JS |
958 | { |
959 | wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION|wxOK); | |
960 | return; | |
961 | } | |
962 | ||
8d3261f9 | 963 | wxTextOutputStream stream(osFile); |
d7463f75 | 964 | stream << configureStr; |
254a2129 | 965 | } |
d7463f75 JS |
966 | } |
967 | ||
968 | void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent& event) | |
969 | { | |
4fe30bce | 970 | event.Enable(true); |
d7463f75 JS |
971 | } |
972 | ||
973 | void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent& event) | |
974 | { | |
4fe30bce | 975 | event.Enable(true); |
d7463f75 | 976 | } |
e7767867 JS |
977 | |
978 | /// Find text | |
69da0d99 | 979 | void ctConfigToolView::OnFind(wxCommandEvent& WXUNUSED(event)) |
e7767867 JS |
980 | { |
981 | ctFindReplaceDialog* dialog = wxGetApp().GetMainFrame()->GetFindDialog(); | |
982 | if (dialog) | |
983 | { | |
984 | dialog->Raise(); | |
985 | } | |
986 | ||
987 | if (!dialog) | |
988 | { | |
989 | int style = wxFR_NOUPDOWN; | |
990 | wxString caption(wxT("Find text in settings")); | |
991 | int flags = wxFR_DOWN; | |
992 | if (wxGetApp().GetSettings().m_matchCase) | |
993 | flags|=wxFR_MATCHCASE; | |
994 | if (wxGetApp().GetSettings().m_matchWholeWord) | |
995 | flags|=wxFR_WHOLEWORD; | |
996 | ||
997 | ctFindReplaceDialog::sm_findData.SetFlags(flags); | |
998 | ||
999 | dialog = new ctFindReplaceDialog(wxGetApp().GetMainFrame(), caption, style); | |
4fe30bce | 1000 | dialog->Show(true); |
e7767867 JS |
1001 | } |
1002 | } | |
1003 | ||
1004 | /// Update find text | |
1005 | void ctConfigToolView::OnUpdateFind(wxUpdateUIEvent& event) | |
1006 | { | |
4fe30bce | 1007 | event.Enable(true); |
e7767867 JS |
1008 | } |
1009 | ||
afc51590 | 1010 | /// Save default file type |
69da0d99 | 1011 | void ctConfigToolView::OnGo(wxCommandEvent& WXUNUSED(event)) |
afc51590 JS |
1012 | { |
1013 | ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); | |
1014 | wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir; | |
677ded95 | 1015 | if (!path.empty()) |
afc51590 JS |
1016 | { |
1017 | if (wxGetApp().GetSettings().m_defaultFileKind == wxT("Setup file")) | |
1018 | { | |
1019 | // setup.h | |
1020 | wxString setupStr = doc->GenerateSetup(); | |
1021 | ||
1022 | wxString fullPath = path + wxFILE_SEP_PATH + wxT("setup.h"); | |
1023 | if (wxFileExists(fullPath)) | |
1024 | { | |
1025 | wxString msg; | |
1026 | msg.Printf(wxT("Overwrite existing file %s?"), (const wxChar*) fullPath); | |
1027 | int ans = wxMessageBox(msg, _("Save Setup File"), wxICON_QUESTION|wxYES_NO|wxCANCEL); | |
1028 | if (ans == wxCANCEL) | |
1029 | return; | |
1030 | if (ans == wxNO) | |
1031 | return; | |
1032 | } | |
1033 | wxFileOutputStream stream(fullPath); | |
1034 | if (!stream.Ok()) | |
1035 | { | |
1036 | wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK); | |
1037 | return; | |
1038 | } | |
1039 | stream << setupStr; | |
1040 | } | |
1041 | else if (wxGetApp().GetSettings().m_defaultFileKind == wxT("Configure script")) | |
1042 | { | |
1043 | // configurewx.sh | |
1044 | wxString configureStr = doc->GenerateConfigureCommand(); | |
1045 | ||
1046 | wxString fullPath = path + wxFILE_SEP_PATH + wxT("configurewx.sh"); | |
1047 | if (wxFileExists(fullPath)) | |
1048 | { | |
1049 | wxString msg; | |
1050 | msg.Printf(wxT("Overwrite existing file %s?"), (const wxChar*) fullPath); | |
1051 | int ans = wxMessageBox(msg, _("Save Configure Script"), wxICON_QUESTION|wxYES_NO|wxCANCEL); | |
1052 | if (ans == wxCANCEL) | |
1053 | return; | |
1054 | if (ans == wxNO) | |
1055 | return; | |
1056 | } | |
1057 | wxFileOutputStream stream(fullPath); | |
1058 | if (!stream.Ok()) | |
1059 | { | |
1060 | wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Script"), wxICON_EXCLAMATION|wxOK); | |
1061 | return; | |
1062 | } | |
1063 | stream << configureStr; | |
1064 | } | |
1065 | else | |
1066 | { | |
1067 | wxMessageBox(wxT("Unrecognised default file type.")); | |
1068 | } | |
1069 | } | |
1070 | } | |
1071 | ||
1072 | /// Update | |
1073 | void ctConfigToolView::OnUpdateGo(wxUpdateUIEvent& event) | |
1074 | { | |
1075 | wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir; | |
677ded95 | 1076 | event.Enable(!path.empty()); |
afc51590 JS |
1077 | } |
1078 | ||
e7767867 JS |
1079 | //---------------------------------------------------------------------------- |
1080 | // ctFindReplaceDialog | |
1081 | //---------------------------------------------------------------------------- | |
1082 | ||
1083 | BEGIN_EVENT_TABLE(ctFindReplaceDialog, wxFindReplaceDialog) | |
4fe30bce WS |
1084 | EVT_FIND(wxID_ANY, ctFindReplaceDialog::OnFind) |
1085 | EVT_FIND_NEXT(wxID_ANY, ctFindReplaceDialog::OnFind) | |
1086 | EVT_FIND_CLOSE(wxID_ANY, ctFindReplaceDialog::OnClose) | |
e7767867 JS |
1087 | END_EVENT_TABLE() |
1088 | ||
1089 | wxFindReplaceData ctFindReplaceDialog::sm_findData; | |
1090 | wxString ctFindReplaceDialog::sm_currentItem = wxEmptyString; | |
1091 | ||
1092 | ctFindReplaceDialog::ctFindReplaceDialog( wxWindow *parent, const wxString& title, | |
1093 | long style): | |
1094 | wxFindReplaceDialog( parent, & sm_findData, title, style ) | |
1095 | { | |
1096 | sm_currentItem = wxEmptyString; | |
1097 | ||
1098 | if (parent) | |
1099 | ((ctMainFrame*) parent)->SetFindDialog(this); | |
1100 | } | |
1101 | ||
1102 | void ctFindReplaceDialog::OnFind(wxFindDialogEvent& event) | |
1103 | { | |
1104 | wxString textToFind = event.GetFindString(); | |
1105 | bool matchCase = ((event.GetFlags() & wxFR_MATCHCASE) != 0); | |
1106 | bool wholeWord = ((event.GetFlags() & wxFR_WHOLEWORD) != 0); | |
1107 | ||
1108 | wxGetApp().GetSettings().m_matchCase = matchCase; | |
1109 | wxGetApp().GetSettings().m_matchWholeWord = wholeWord; | |
1110 | ||
1111 | if (!DoFind(textToFind, matchCase, wholeWord)) | |
1112 | { | |
1113 | wxMessageBox(wxT("No more matches."), wxT("Search"), wxOK|wxICON_INFORMATION, this); | |
1114 | } | |
1115 | } | |
1116 | ||
1117 | bool ctFindReplaceDialog::DoFind(const wxString& textToFind, bool matchCase, bool wholeWord, bool wrap) | |
1118 | { | |
1119 | ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument(); | |
1120 | if (!doc) | |
4fe30bce | 1121 | return false; |
e7767867 JS |
1122 | ctConfigToolView* view = (ctConfigToolView*) doc->GetFirstView(); |
1123 | ||
1124 | ctConfigItem* currentItem = NULL; | |
1125 | ctConfigItem* focusItem = view->GetSelection(); | |
1126 | if (!focusItem) | |
1127 | { | |
1128 | focusItem = doc->GetTopItem(); | |
1129 | if (!focusItem) | |
4fe30bce | 1130 | return false; |
e7767867 JS |
1131 | } |
1132 | ||
677ded95 | 1133 | if (!sm_currentItem.empty()) |
e7767867 JS |
1134 | { |
1135 | currentItem = doc->GetTopItem()->FindItem(sm_currentItem); | |
1136 | } | |
1137 | ||
1138 | // If we were at this item last time, skip the first one. | |
1139 | bool skipFirstItem = (currentItem == focusItem); | |
1140 | currentItem = FindNextItem(doc, currentItem, textToFind, matchCase, wholeWord, wrap, | |
1141 | skipFirstItem); | |
1142 | ||
1143 | if (currentItem) | |
1144 | { | |
1145 | sm_currentItem = currentItem->GetName(); | |
1146 | wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(currentItem->GetTreeItemId()); | |
4fe30bce | 1147 | return true; |
e7767867 JS |
1148 | } |
1149 | else | |
1150 | { | |
1151 | sm_currentItem = wxEmptyString; | |
1152 | } | |
1153 | ||
4fe30bce | 1154 | return false; |
e7767867 JS |
1155 | } |
1156 | ||
1157 | ctConfigItem* ctFindReplaceDialog::FindNextItem(ctConfigToolDoc* doc, | |
1158 | ctConfigItem* item, | |
1159 | const wxString& text, | |
1160 | bool matchCase, | |
1161 | bool matchWordOnly, | |
1162 | bool wrap, | |
1163 | bool skipFirst) | |
1164 | { | |
1165 | ctConfigItem* firstInDoc = NULL; | |
1166 | ||
1167 | wxString text2(text); | |
1168 | if (!matchCase) | |
1169 | text2.MakeLower(); | |
1170 | ||
1171 | ctConfigItem* found = NULL; | |
1172 | ctConfigItem* next = item; | |
1173 | ||
1174 | int i = 0; | |
1175 | do | |
1176 | { | |
1177 | // If starting the search from beginning, we can now | |
1178 | // set the value of 'item' in the 2nd iteration without immediately | |
1179 | // dropping out of the while loop because card == next | |
1180 | if (!item && (i > 0)) | |
1181 | item = firstInDoc; | |
1182 | ||
1183 | // We might want to start from this item if skipFirst is false. | |
1184 | if ((i == 0) && !skipFirst && next) | |
1185 | { | |
1186 | } | |
1187 | else | |
1188 | next = doc->FindNextItem(next, wrap); | |
1189 | ||
1190 | // Save to be used in iteration 2 | |
1191 | if ((i == 0) && !item) | |
1192 | firstInDoc = next; | |
1193 | ||
1194 | if (next) | |
1195 | { | |
1196 | wxString str(next->GetName()); | |
1197 | wxString description(next->GetPropertyString(wxT("description"))); | |
1198 | wxString notes(next->GetPropertyString(wxT("notes"))); | |
1199 | if (!matchCase) | |
1200 | { | |
1201 | str.MakeLower(); | |
1202 | description.MakeLower(); | |
1203 | notes.MakeLower(); | |
1204 | } | |
1205 | if (ctMatchString(str, text2, matchWordOnly) || | |
1206 | ctMatchString(description, text2, matchWordOnly) || | |
1207 | ctMatchString(notes, text2, matchWordOnly)) | |
1208 | { | |
1209 | found = next; | |
1210 | } | |
1211 | } | |
1212 | else | |
1213 | break; // Didn't find an item at all | |
1214 | ||
1215 | i ++; | |
1216 | } | |
1217 | while (!found && item != next); | |
1218 | ||
1219 | if (item == found && !firstInDoc) | |
1220 | return NULL; | |
1221 | else | |
1222 | return found; | |
1223 | } | |
1224 | ||
1225 | void ctFindReplaceDialog::OnClose(wxFindDialogEvent& event) | |
1226 | { | |
1227 | bool matchCase = ((event.GetFlags() & wxFR_MATCHCASE) != 0); | |
1228 | bool wholeWord = ((event.GetFlags() & wxFR_WHOLEWORD) != 0); | |
1229 | wxGetApp().GetSettings().m_matchCase = matchCase; | |
1230 | wxGetApp().GetSettings().m_matchWholeWord = wholeWord; | |
1231 | ||
1232 | this->Destroy(); | |
1233 | ((ctMainFrame*) GetParent())->SetFindDialog(NULL); | |
1234 | } |