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