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