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