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