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