1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Implementation file for ecPackagesDialog
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "packagesdlg.h"
57 // Includes other headers for precompiled compilation
64 #include "wx/cshelp.h"
65 #include "wx/valgen.h"
66 #include "wx/tokenzr.h"
68 #include "configtool.h"
69 #include "packagesdlg.h"
70 #include "configtooldoc.h"
73 BEGIN_EVENT_TABLE(ecPackagesDialog, ecDialog)
74 EVT_BUTTON(wxID_OK, ecPackagesDialog::OnOK)
75 EVT_BUTTON(wxID_CANCEL, ecPackagesDialog::OnCancel)
76 EVT_BUTTON(ecID_PACKAGES_DIALOG_ADD, ecPackagesDialog::OnAdd)
77 EVT_BUTTON(ecID_PACKAGES_DIALOG_REMOVE, ecPackagesDialog::OnRemove)
78 EVT_LISTBOX_DCLICK(ecID_PACKAGES_DIALOG_AVAILABLE_LIST, ecPackagesDialog::OnDblClickListBox1)
79 EVT_LISTBOX_DCLICK(ecID_PACKAGES_DIALOG_USE_LIST, ecPackagesDialog::OnDblClickListBox2)
80 EVT_LISTBOX(ecID_PACKAGES_DIALOG_AVAILABLE_LIST, ecPackagesDialog::OnClickListBox1)
81 EVT_LISTBOX(ecID_PACKAGES_DIALOG_USE_LIST, ecPackagesDialog::OnClickListBox2)
82 EVT_LISTBOX(ecID_PACKAGES_DIALOG_VERSION, ecPackagesDialog::OnSelectVersion)
83 EVT_INIT_DIALOG(ecPackagesDialog::OnInitDialog)
84 EVT_BUTTON(ecID_PACKAGES_DIALOG_CLEAR, ecPackagesDialog::OnClearKeywords)
85 EVT_CHECKBOX(ecID_PACKAGES_DIALOG_OMIT_HARDWARE, ecPackagesDialog::OnClickOmitHardwarePackages)
86 EVT_CHECKBOX(ecID_PACKAGES_DIALOG_EXACT_MATCH, ecPackagesDialog::OnClickExactMatch)
87 EVT_TEXT(ecID_PACKAGES_DIALOG_KEYWORDS, ecPackagesDialog::OnUpdateKeywordText)
88 EVT_IDLE(ecPackagesDialog::OnIdle)
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
96 ecPackagesDialog::ecPackagesDialog(wxWindow* parent):
99 m_bHardwarePackageSelected = FALSE;
100 m_keywords = wxEmptyString;
101 m_updateLists = FALSE;
102 m_updateInterval = 600; // Milliseconds
105 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
107 ecDialog::Create(parent, ecID_PACKAGES_DIALOG, _("Packages"),
108 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
110 CreateControls(this);
117 ecPackagesDialog::~ecPackagesDialog()
122 // TODO: implement wxLB_SORT style in wxGTK.
123 void ecPackagesDialog::CreateControls(wxWindow* parent)
125 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
127 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
129 wxSizer *item2 = new wxBoxSizer( wxVERTICAL );
131 wxStaticText *item3 = new wxStaticText( parent, wxID_STATIC, _("Available &packages:"), wxDefaultPosition, wxDefaultSize, 0 );
132 item2->Add( item3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
134 wxString *strs4 = (wxString*) NULL;
135 wxListBox *item4 = new wxListBox( parent, ecID_PACKAGES_DIALOG_AVAILABLE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs4, wxLB_SORT|wxLB_HSCROLL );
136 item2->Add( item4, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
138 item1->Add( item2, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
140 wxSizer *item5 = new wxBoxSizer( wxVERTICAL );
142 wxButton *item6 = new wxButton( parent, ecID_PACKAGES_DIALOG_ADD, _("&Add >>"), wxDefaultPosition, wxDefaultSize, 0 );
143 item5->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
145 wxButton *item7 = new wxButton( parent, ecID_PACKAGES_DIALOG_REMOVE, _("<< &Remove"), wxDefaultPosition, wxDefaultSize, 0 );
146 item5->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
148 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 0 );
150 wxSizer *item8 = new wxBoxSizer( wxVERTICAL );
152 wxStaticText *item9 = new wxStaticText( parent, wxID_STATIC, _("&Use these packages:"), wxDefaultPosition, wxDefaultSize, 0 );
153 item8->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
155 wxString *strs10 = (wxString*) NULL;
156 wxListBox *item10 = new wxListBox( parent, ecID_PACKAGES_DIALOG_USE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs10, wxLB_SORT|wxLB_HSCROLL );
157 item8->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
159 item1->Add( item8, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
161 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
163 wxStaticText *item11 = new wxStaticText( parent, wxID_STATIC, _("&Version:"), wxDefaultPosition, wxDefaultSize, 0 );
164 item0->Add( item11, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
166 wxString *strs12 = (wxString*) NULL;
167 wxChoice *item12 = new wxChoice( parent, ecID_PACKAGES_DIALOG_VERSION, wxDefaultPosition, wxSize(100,-1), 0, strs12, 0 );
168 item0->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 10 );
170 wxTextCtrl *item13 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_DESCRIPTION, _(""), wxDefaultPosition, wxSize(80,110), wxTE_MULTILINE );
171 item0->Add( item13, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 10 );
173 wxStaticText *item14 = new wxStaticText( parent, wxID_STATIC, _("&Keywords:"), wxDefaultPosition, wxDefaultSize, 0 );
174 item0->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
176 wxSizer *item15 = new wxBoxSizer( wxHORIZONTAL );
178 wxTextCtrl *item16 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_KEYWORDS, _(""), wxDefaultPosition, wxSize(80,-1), 0 );
179 item15->Add( item16, 1, wxALIGN_CENTRE|wxALL, 5 );
181 wxButton *item17 = new wxButton( parent, ecID_PACKAGES_DIALOG_CLEAR, _("C&lear"), wxDefaultPosition, wxDefaultSize, 0 );
182 item15->Add( item17, 0, wxALIGN_CENTRE|wxALL, 5 );
184 item0->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
186 wxSizer *item18 = new wxBoxSizer( wxHORIZONTAL );
188 wxCheckBox *item19 = new wxCheckBox( parent, ecID_PACKAGES_DIALOG_OMIT_HARDWARE, _("&Omit hardware packages"), wxDefaultPosition, wxDefaultSize, 0 );
189 item18->Add( item19, 0, wxALIGN_CENTRE|wxALL, 5 );
191 wxCheckBox *item20 = new wxCheckBox( parent, ecID_PACKAGES_DIALOG_EXACT_MATCH, _("&Match exactly"), wxDefaultPosition, wxDefaultSize, 0 );
192 item18->Add( item20, 0, wxALIGN_CENTRE|wxALL, 5 );
194 item18->Add( 20, 20, 1, wxALIGN_CENTRE|wxALL, 5 );
196 wxButton *item21 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
197 item21->SetDefault();
198 item18->Add( item21, 0, wxALIGN_CENTRE|wxALL, 5 );
200 wxButton *item22 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
201 item18->Add( item22, 0, wxALIGN_CENTRE|wxALL, 5 );
203 item0->Add( item18, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
206 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
208 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
210 wxSizer *item2 = new wxBoxSizer( wxVERTICAL );
212 wxStaticText *item3 = new wxStaticText( parent, wxID_STATIC, _("Available &packages:"), wxDefaultPosition, wxDefaultSize, 0 );
213 item2->Add( item3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
215 wxString *strs4 = (wxString*) NULL;
216 wxListBox *item4 = new wxListBox( parent, ecID_PACKAGES_DIALOG_AVAILABLE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs4, wxLB_SORT|wxLB_HSCROLL );
217 item2->Add( item4, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
219 item1->Add( item2, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
221 wxSizer *item5 = new wxBoxSizer( wxVERTICAL );
223 wxButton *item6 = new wxButton( parent, ecID_PACKAGES_DIALOG_ADD, _("&Add >>"), wxDefaultPosition, wxDefaultSize, 0 );
224 item5->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
226 wxButton *item7 = new wxButton( parent, ecID_PACKAGES_DIALOG_REMOVE, _("<< &Remove"), wxDefaultPosition, wxDefaultSize, 0 );
227 item5->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
229 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 0 );
231 wxSizer *item8 = new wxBoxSizer( wxVERTICAL );
233 wxStaticText *item9 = new wxStaticText( parent, wxID_STATIC, _("&Use these packages:"), wxDefaultPosition, wxDefaultSize, 0 );
234 item8->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
236 wxString *strs10 = (wxString*) NULL;
237 wxListBox *item10 = new wxListBox( parent, ecID_PACKAGES_DIALOG_USE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs10, wxLB_SORT|wxLB_HSCROLL );
238 item8->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
240 item1->Add( item8, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
242 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
244 wxStaticText *item11 = new wxStaticText( parent, wxID_STATIC, _("&Version:"), wxDefaultPosition, wxDefaultSize, 0 );
245 item0->Add( item11, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
247 wxString *strs12 = (wxString*) NULL;
248 wxChoice *item12 = new wxChoice( parent, ecID_PACKAGES_DIALOG_VERSION, wxDefaultPosition, wxSize(100,-1), 0, strs12, 0 );
249 item0->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 10 );
251 wxTextCtrl *item13 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_DESCRIPTION, _(""), wxDefaultPosition, wxSize(80,110), wxTE_MULTILINE );
252 item0->Add( item13, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 10 );
254 wxStaticText *item14 = new wxStaticText( parent, wxID_STATIC, _("&Keywords:"), wxDefaultPosition, wxDefaultSize, 0 );
255 item0->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
257 wxSizer *item15 = new wxBoxSizer( wxHORIZONTAL );
259 wxTextCtrl *item16 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_KEYWORDS, _(""), wxDefaultPosition, wxSize(80,-1), 0 );
260 item15->Add( item16, 1, wxALIGN_CENTRE|wxALL, 5 );
262 wxButton *item17 = new wxButton( parent, ecID_PACKAGES_DIALOG_CLEAR, _("C&lear"), wxDefaultPosition, wxDefaultSize, 0 );
263 item15->Add( item17, 0, wxALIGN_CENTRE|wxALL, 5 );
265 item0->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
267 wxSizer *item18 = new wxBoxSizer( wxHORIZONTAL );
269 wxCheckBox *item19 = new wxCheckBox( parent, ecID_PACKAGES_DIALOG_OMIT_HARDWARE, _("Omit hardware packages"), wxDefaultPosition, wxDefaultSize, 0 );
270 item18->Add( item19, 0, wxALIGN_CENTRE|wxALL, 5 );
272 item18->Add( 20, 20, 1, wxALIGN_CENTRE|wxALL, 5 );
274 wxButton *item20 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
275 item20->SetDefault();
276 item18->Add( item20, 0, wxALIGN_CENTRE|wxALL, 5 );
278 wxButton *item21 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
279 item18->Add( item21, 0, wxALIGN_CENTRE|wxALL, 5 );
281 item0->Add( item18, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
285 wxButton *contextButton = new wxContextHelpButton( parent );
286 item18->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
289 parent->FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetFocus();
291 parent->SetAutoLayout( TRUE );
292 parent->SetSizer( item0 );
294 item0->Fit( parent );
295 //item0->SetSizeHints( parent );
297 // Add context-sensitive help text
298 parent->FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST )->SetHelpText(_("Displays the list of packages available, but not currently loaded."));
299 parent->FindWindow( ecID_PACKAGES_DIALOG_USE_LIST )->SetHelpText(_("Displays the list of packages currently loaded."));
300 parent->FindWindow( ecID_PACKAGES_DIALOG_ADD )->SetHelpText(_("Add one or more packages to the list to be loaded."));
301 parent->FindWindow( ecID_PACKAGES_DIALOG_REMOVE )->SetHelpText(_("Removes one or more packages from the list to be loaded."));
302 parent->FindWindow( ecID_PACKAGES_DIALOG_VERSION )->SetHelpText(_("Displays the version of the selected packages."));
303 parent->FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION )->SetHelpText(_("Displays a description of the selected package (blank if more than one package is selected)."));
304 parent->FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetHelpText(_("Enter keywords here to restrict displayed packages."));
305 parent->FindWindow( ecID_PACKAGES_DIALOG_CLEAR )->SetHelpText(_("Clears the keyword field."));
306 parent->FindWindow( ecID_PACKAGES_DIALOG_OMIT_HARDWARE)->SetHelpText(_("Check this to omit hardware packages, uncheck to show all packages."));
307 parent->FindWindow( ecID_PACKAGES_DIALOG_EXACT_MATCH )->SetHelpText(_("Check this to display exact matches between keyword and aliases (case insensitive)."));
308 parent->FindWindow( wxID_OK )->SetHelpText(_("Closes the dialog and saves any changes you have made."));
309 parent->FindWindow( wxID_CANCEL )->SetHelpText(_("Closes the dialog without saving any changes you have made."));
312 parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));
316 parent->FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION )->SetValidator(wxGenericValidator(& m_packageDescription));
317 parent->FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetValidator(wxGenericValidator(& m_keywords));
318 parent->FindWindow( ecID_PACKAGES_DIALOG_OMIT_HARDWARE )->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_omitHardwarePackages));
319 parent->FindWindow( ecID_PACKAGES_DIALOG_EXACT_MATCH )->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_matchPackageNamesExactly));
322 void ecPackagesDialog::OnInitDialog(wxInitDialogEvent& event)
324 // Note: InitControls must be here, because data will be added
325 // between construction of the dialog, and OnInitDialog.
327 TransferDataToWindow();
330 void ecPackagesDialog::InitControls()
335 void ecPackagesDialog::OnCancel(wxCommandEvent& event)
340 void ecPackagesDialog::OnOK(wxCommandEvent& event)
342 TransferDataFromWindow();
346 // For each word in keywords, is it contained in 'str'?
347 bool ecPackagesDialog::MatchesKeyword(wxArrayString& keywords, const wxString& str)
349 // _Every_ keyword must match
351 for (i = 0; i < keywords.GetCount(); i++)
353 if (str.Find(keywords[i]) == -1)
359 void ecPackagesDialog::Fill()
361 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
362 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
363 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
365 // wxGTK doesn't deselect items properly when clearing, I think
367 for (i = 0; i < availableList->GetCount(); i++)
368 if (availableList->Selected(i))
369 availableList->Deselect(i);
370 for (i = 0; i < useList->GetCount(); i++)
371 if (useList->Selected(i))
372 useList->Deselect(i);
374 availableList->Clear();
378 wxString s2(m_keywords);
382 wxArrayString keywords;
383 wxStringTokenizer tok(s2);
384 while (tok.HasMoreTokens())
386 keywords.Add(tok.GetNextToken());
389 // Initialize the controls
390 for (i = 0; i < GetCount()-1; i++)
392 const wxString& str = m_items[i];
393 wxListBox* lb = m_arnItems[i] ? useList : availableList;
395 wxString macroName(pDoc->GetPackageName (str));
397 // check if the package is a hardware package
399 if ((!wxGetApp().GetSettings().m_omitHardwarePackages) || !pDoc->GetCdlPkgData ()->is_hardware_package (ecUtils::UnicodeToStdStr (macroName)))
403 if (!m_keywords.IsEmpty())
410 wxString s3(macroName);
414 const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_package_aliases (ecUtils::UnicodeToStdStr (macroName));
416 if (wxGetApp().GetSettings().m_matchPackageNamesExactly)
420 if (s2 == s1 || s2 == s3)
424 for (j = 0; j < aliases.size(); j ++)
426 wxString alias(aliases[j].c_str());
432 matches = (noMatches > 0);
437 // Concatenate all possible text together, and match against that
445 for (j = 0; j < aliases.size(); j ++)
447 wxString alias(aliases[j].c_str());
452 matches = MatchesKeyword(keywords, toMatch);
457 lb->Append(str, (void*) i);
461 UpdateAddRemoveButtons();
463 if (availableList->GetCount() == 1)
465 availableList->SetSelection(0);
466 UpdatePackageDescription();
467 UpdateVersionList ();
468 UpdateHardwareSelectionFlag ();
470 else if (useList->GetCount() == 1)
472 useList->SetSelection(0);
473 UpdatePackageDescription();
474 UpdateVersionList ();
475 UpdateHardwareSelectionFlag ();
477 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS );
478 // Necessary or TransferDataToWindow will cause insertion position to change
479 textCtrl->SetInsertionPointEnd();
482 void ecPackagesDialog::Add(wxListBox* from, wxListBox* to)
484 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
486 wxArrayInt selections;
487 wxStringList selectionsStrings;
488 int n = from -> GetSelections( selections );
493 for (i = 0; i < selections.GetCount(); i++)
495 wxString str = from -> GetString(selections[i]);
496 selectionsStrings.Add(str);
499 // Now delete from one list and remove from t'other
500 for (i = 0; i < selectionsStrings.Number(); i++)
502 wxString str = selectionsStrings[i];
505 int toDelete = from -> FindString(str);
509 itemIndex = (int) from -> GetClientData(toDelete);
510 from -> Delete(toDelete);
513 wxASSERT (itemIndex > -1);
516 to -> Append(str, (void*) itemIndex);
528 int addedIndex = to->FindString(str);
529 to->Select(addedIndex);
532 //ClearDescription();
533 ClearSelections(* from);
534 UpdateHardwareSelectionFlag();
535 UpdatePackageDescription();
540 void ecPackagesDialog::OnAdd(wxCommandEvent& event)
542 if (m_bHardwarePackageSelected)
544 HardwarePackageMessageBox ();
547 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
548 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
550 Add(availableList, useList);
552 UpdateAddRemoveButtons();
555 void ecPackagesDialog::OnRemove(wxCommandEvent& event)
557 if (m_bHardwarePackageSelected)
559 HardwarePackageMessageBox ();
563 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
564 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
566 Add(useList, availableList);
568 UpdateAddRemoveButtons();
571 void ecPackagesDialog::OnDblClickListBox1(wxCommandEvent& event)
573 if (m_bHardwarePackageSelected)
575 HardwarePackageMessageBox ();
579 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
580 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
582 Add(availableList, useList);
584 UpdateAddRemoveButtons();
587 void ecPackagesDialog::OnDblClickListBox2(wxCommandEvent& event)
589 if (m_bHardwarePackageSelected)
591 HardwarePackageMessageBox ();
595 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
596 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
598 Add(useList, availableList);
600 UpdateAddRemoveButtons();
603 void ecPackagesDialog::OnClickListBox1(wxCommandEvent& event)
605 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
606 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
609 int sel = event.GetSelection();
612 // TODO: check that this works for multiple-selection listboxes
613 DisplayDescription(availableList->GetString(sel));
617 ClearSelections(*useList);
618 UpdatePackageDescription ();
619 UpdateVersionList ();
620 UpdateHardwareSelectionFlag ();
621 UpdateAddRemoveButtons();
624 void ecPackagesDialog::OnClickListBox2(wxCommandEvent& event)
626 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
627 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
630 int sel = event.GetSelection();
633 // TODO: check that this works for multiple-selection listboxes
634 DisplayDescription(useList->GetString(sel));
638 ClearSelections(*availableList);
639 UpdatePackageDescription ();
640 UpdateVersionList ();
641 UpdateHardwareSelectionFlag ();
642 UpdateAddRemoveButtons();
645 void ecPackagesDialog::OnSelectVersion(wxCommandEvent& event)
647 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
648 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
649 wxChoice* versionChoice = (wxChoice*) FindWindow( ecID_PACKAGES_DIALOG_VERSION );
651 if (-1 == versionChoice->GetSelection ()) // if there is no version selection
652 return; // do nothing
654 wxListBox * pListBox = NULL;
656 wxArrayInt selected1, selected2;
657 availableList->GetSelections(selected1);
658 useList->GetSelections(selected2);
660 int nListSelCount = selected1.GetCount ();
661 if (nListSelCount > 0)
663 pListBox = availableList;
667 nListSelCount = selected2.GetCount ();
677 // retrieve the list box indices of the selected packages
679 wxArrayInt* selected = (pListBox == availableList ? & selected1 : & selected2);
682 for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
684 // set the package version to that specified in the version combo box
685 wxString str = versionChoice->GetString(nIndex);
687 // itemIndex is the index into the list of item names. It gets stored with all the listbox items.
688 int itemIndex = (int) pListBox->GetClientData((*selected)[nIndex]);
689 m_currentVersions[(size_t)itemIndex] = str;
693 void ecPackagesDialog::OnClearKeywords(wxCommandEvent& event)
695 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS );
696 textCtrl->SetValue(wxT(""));
697 TransferDataFromWindow();
699 m_updateLists = FALSE;
701 FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetFocus();
704 void ecPackagesDialog::OnUpdateKeywordText(wxCommandEvent& event)
706 // Work around a bug in GTK+ that sends a text update command when
707 // clicking on one of the listboxes.
708 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS );
709 wxString value = textCtrl->GetValue();
710 if (value == m_keywords)
713 TransferDataFromWindow();
714 m_updateLists = TRUE;
718 void ecPackagesDialog::OnClickOmitHardwarePackages(wxCommandEvent& event)
720 TransferDataFromWindow();
724 void ecPackagesDialog::OnClickExactMatch(wxCommandEvent& event)
726 TransferDataFromWindow();
730 void ecPackagesDialog::OnIdle(wxIdleEvent& event)
732 long elapsed = wxGetElapsedTime(FALSE);
733 if (m_updateLists && (elapsed > m_updateInterval))
735 m_updateLists = FALSE;
741 void ecPackagesDialog::Insert(const wxString& str, bool added, const wxString& descr, const wxString& version)
743 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
744 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
747 m_descriptions.Add(str);
748 m_currentVersions.Add(version);
749 m_arnItems.Add(added);
754 //(added ? useList : availableList) -> Append(str);
757 bool ecPackagesDialog::IsAdded(const wxString& str)
759 return (m_added.Index(str) != wxNOT_FOUND);
761 // return (((wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ))->FindString(str) > -1) ;
764 static int ecPositionInStringList(const wxStringList& list, const wxString& item)
767 for (i = 0 ; i < list.Number(); i++)
775 void ecPackagesDialog::DisplayDescription(const wxString& item)
777 //wxTextCtrl* descrCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION ) ;
778 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
780 // int pos = ecPositionInStringList(m_items, item);
784 // wxString descr = m_descriptions[pos];
786 // text += wxT("\n");
788 wxString macroName(pDoc->GetPackageName (item));
791 const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_package_aliases (ecUtils::UnicodeToStdStr (macroName));
794 for (j = 0; j < aliases.size(); j ++)
797 text += wxT(".\nAliases: ");
801 wxString alias(aliases[j].c_str());
804 text += wxT("\nMacro: ");
808 wxString descr = pDoc->GetCdlPkgData ()->get_package_description (ecUtils::UnicodeToStdStr (macroName)).c_str ();
810 text += ecUtils::StripExtraWhitespace (descr);
812 m_packageDescription = text;
814 //descrCtrl->SetValue(text);
818 void ecPackagesDialog::ClearDescription()
820 wxTextCtrl* descrCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION ) ;
821 descrCtrl->SetValue(wxEmptyString);
824 wxString ecPackagesDialog::GetVersion (const wxString& item)
827 for (nCount = GetCount() - 1; nCount >= 0; --nCount)
829 if (m_items [nCount] == item)
831 return m_currentVersions [nCount];
835 return wxEmptyString;
838 void ecPackagesDialog::UpdateHardwareSelectionFlag()
840 m_bHardwarePackageSelected = FALSE;
842 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
843 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
844 wxListBox * pListBox = NULL;
846 wxArrayInt selections1, selections2;
847 wxArrayInt* selections = NULL;
848 availableList->GetSelections(selections1);
849 useList->GetSelections(selections2);
851 int nListSelCount = selections1.GetCount ();
854 pListBox = availableList;
855 selections = & selections1;
859 nListSelCount = selections2.GetCount ();
863 selections = & selections2;
867 if (pListBox) // if there are packages selected
869 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
871 // retrieve the list box indices of the selected packages
873 //int * arnIndices = new int [nListSelCount];
874 //pListBox->GetSelItems (nListSelCount, arnIndices);
877 for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
879 wxString strPackageAlias = pListBox->GetString((*selections)[nIndex]);
881 // check if the package is a hardware package
883 //TRACE (_T("Checking '%s' for hardware status\n"), strPackageAlias);
884 if (pDoc->GetCdlPkgData ()->is_hardware_package (ecUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias))))
886 m_bHardwarePackageSelected = TRUE;
893 void ecPackagesDialog::HardwarePackageMessageBox()
895 // TODO: could give the user the choice of going to the template dialog.
896 wxMessageBox (wxT("Add and remove hardware packages by selecting a new hardware template."),
897 wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
900 void ecPackagesDialog::UpdatePackageDescription ()
902 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
904 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
905 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
907 wxListBox * pListBox = NULL;
909 wxArrayInt selections1, selections2;
910 wxArrayInt* selections = NULL;
911 availableList->GetSelections(selections1);
912 useList->GetSelections(selections2);
914 if (1 == selections1.GetCount ())
916 pListBox = availableList;
917 selections = & selections1;
919 else if (1 == selections2.GetCount ())
922 selections = & selections2;
925 if (pListBox && selections)
927 int nIndex = (*selections)[0];
928 wxString strPackageAlias = pListBox->GetString(nIndex);
930 DisplayDescription(strPackageAlias);
931 //m_packageDescription = pDoc->GetCdlPkgData ()->get_package_description (ecUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias))).c_str ();
932 //m_packageDescription = ecUtils::StripExtraWhitespace (m_packageDescription);
936 m_packageDescription = wxEmptyString;
938 TransferDataToWindow ();
941 void ecPackagesDialog::UpdateVersionList ()
943 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
945 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
946 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
947 wxChoice* versionChoice = (wxChoice*) FindWindow( ecID_PACKAGES_DIALOG_VERSION );
949 versionChoice->Clear(); // clear the version combo box
951 wxArrayInt selections1, selections2;
952 wxArrayInt* selections = NULL;
953 availableList->GetSelections(selections1);
954 useList->GetSelections(selections2);
955 wxListBox* pListBox = NULL;
957 if (selections1.GetCount () > 0)
959 pListBox = availableList;
960 selections = & selections1;
962 else if (selections2.GetCount () > 0)
965 selections = & selections2;
968 if (pListBox) // if there are packages selected
970 std::list<std::string> common_versions;
971 bool bCommonSelectedVersion = true;
972 int nCommonVersionIndex=-1;
973 int nListSelCount = selections->GetCount();
975 // retrieve the list box indices of the selected packages
977 //int * arnIndices = new int [nListSelCount];
978 //pListBox->GetSelItems (nListSelCount, arnIndices);
980 for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
982 // retrieve the first package alias
983 wxString strPackageAlias = pListBox->GetString ((*selections)[nIndex]);
985 // retrieve the dialog item array index for use in
986 // comparing current version strings
987 const int nVersionIndex = (int) pListBox->GetClientData ((*selections)[nIndex]);
989 // retrieve the installed version array
991 //TRACE (_T("Retrieving versions for '%s'\n"), strPackageAlias);
992 const std::vector<std::string>& versions = pDoc->GetCdlPkgData ()->get_package_versions (ecUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias)));
994 if (0 == nIndex) // if this is the first selected package
996 // use the version array to initialise a linked list of version
997 // strings held in common between the selected packages
999 for (uCount = 0; uCount < versions.size (); uCount++)
1001 //TRACE (_T("Adding common version '%s'\n"), wxString (versions [uCount].c_str ()));
1002 common_versions.push_back (versions [uCount]);
1004 nCommonVersionIndex = nVersionIndex; // save the item array index
1006 else // this is not the first selected package
1008 std::list<std::string>::iterator i_common_versions = common_versions.begin ();
1009 while (i_common_versions != common_versions.end ()) // iterate through the common versions
1011 if (versions.end () == std::find (versions.begin (), versions.end (), * i_common_versions)) // if the common version is not in the versions list
1013 //TRACE (_T("Removing common version '%s'\n"), CString (i_common_versions->c_str ()));
1014 common_versions.erase (i_common_versions++); // remove the version from the common versions list
1018 i_common_versions++;
1021 if (bCommonSelectedVersion) // if the selected versions of all preceding packages are identical
1023 // check if the selected version of this package matches that of the preceding ones
1024 bCommonSelectedVersion = (m_currentVersions [nVersionIndex] == m_currentVersions [nCommonVersionIndex]);
1029 // add the common versions to the version combo box
1031 std::list<std::string>::iterator i_common_versions;
1032 for (i_common_versions = common_versions.begin (); i_common_versions != common_versions.end (); i_common_versions++)
1034 //TRACE (_T("Adding version '%s'\n"), CString (i_common_versions->c_str ()));
1035 versionChoice->Append(wxString (i_common_versions->c_str ()));
1038 // select the common current version (if any) in the version combo box
1040 if (bCommonSelectedVersion)
1042 //TRACE (_T("Selecting version '%s'\n"), m_arstrVersions [nCommonVersionIndex]);
1043 versionChoice->SetStringSelection (m_currentVersions [nCommonVersionIndex]);
1046 // enable the version combo box only if there are multiple common versions
1048 versionChoice->Enable (common_versions.size () > 1);
1050 else // there are no packages selected
1052 versionChoice->Enable (FALSE); // disable the version combo box
1056 void ecPackagesDialog::UpdateAddRemoveButtons()
1058 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
1059 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
1061 wxArrayInt selections1, selections2;
1062 availableList->GetSelections(selections1);
1063 useList->GetSelections(selections2);
1065 FindWindow( ecID_PACKAGES_DIALOG_ADD )->Enable( selections1.GetCount() > 0 );
1066 FindWindow( ecID_PACKAGES_DIALOG_REMOVE )->Enable( selections2.GetCount() > 0 );
1069 void ecPackagesDialog::ClearSelections(wxListBox& lbox)
1072 for (i = 0; i < lbox.Number(); i++)
1078 void ecPackagesTimer::Notify()
1080 static bool s_inNotify = FALSE;
1087 // On Windows, simply having the timer going will ping the message queue
1088 // and cause idle processing to happen.
1089 // On Unix, this doesn't happen so we have to do the processing explicitly.
1096 m_dialog->OnIdle(event);