1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 // Copyright (C) 2003 John Dallaway
7 // This program is part of the eCos host tools.
9 // This program is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the Free
11 // Software Foundation; either version 2 of the License, or (at your option)
14 // This program is distributed in the hope that it will be useful, but WITHOUT
15 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 // You should have received a copy of the GNU General Public License along with
20 // this program; if not, write to the Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // ----------------------------------------------------------------------------
25 //####COPYRIGHTEND####
28 //===========================================================================
29 //#####DESCRIPTIONBEGIN####
31 // Author(s): julians, jld
32 // Contact(s): julians
36 // Description: Implementation file for ecPackagesDialog
43 //####DESCRIPTIONEND####
45 //===========================================================================
47 // ============================================================================
49 // ============================================================================
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 #pragma implementation "packagesdlg.h"
58 // Includes other headers for precompiled compilation
65 #include "wx/cshelp.h"
66 #include "wx/valgen.h"
67 #include "wx/tokenzr.h"
69 #include "configtool.h"
70 #include "packagesdlg.h"
71 #include "configtooldoc.h"
74 BEGIN_EVENT_TABLE(ecPackagesDialog, ecDialog)
75 EVT_BUTTON(wxID_OK, ecPackagesDialog::OnOK)
76 EVT_BUTTON(wxID_CANCEL, ecPackagesDialog::OnCancel)
77 EVT_BUTTON(ecID_PACKAGES_DIALOG_ADD, ecPackagesDialog::OnAdd)
78 EVT_BUTTON(ecID_PACKAGES_DIALOG_REMOVE, ecPackagesDialog::OnRemove)
79 EVT_LISTBOX_DCLICK(ecID_PACKAGES_DIALOG_AVAILABLE_LIST, ecPackagesDialog::OnDblClickListBox1)
80 EVT_LISTBOX_DCLICK(ecID_PACKAGES_DIALOG_USE_LIST, ecPackagesDialog::OnDblClickListBox2)
81 EVT_LISTBOX(ecID_PACKAGES_DIALOG_AVAILABLE_LIST, ecPackagesDialog::OnClickListBox1)
82 EVT_LISTBOX(ecID_PACKAGES_DIALOG_USE_LIST, ecPackagesDialog::OnClickListBox2)
83 EVT_LISTBOX(ecID_PACKAGES_DIALOG_VERSION, ecPackagesDialog::OnSelectVersion)
84 EVT_INIT_DIALOG(ecPackagesDialog::OnInitDialog)
85 EVT_BUTTON(ecID_PACKAGES_DIALOG_CLEAR, ecPackagesDialog::OnClearKeywords)
86 EVT_CHECKBOX(ecID_PACKAGES_DIALOG_OMIT_HARDWARE, ecPackagesDialog::OnClickOmitHardwarePackages)
87 EVT_CHECKBOX(ecID_PACKAGES_DIALOG_EXACT_MATCH, ecPackagesDialog::OnClickExactMatch)
88 EVT_TEXT(ecID_PACKAGES_DIALOG_KEYWORDS, ecPackagesDialog::OnUpdateKeywordText)
89 EVT_IDLE(ecPackagesDialog::OnIdle)
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
97 ecPackagesDialog::ecPackagesDialog(wxWindow* parent):
100 m_bHardwarePackageSelected = FALSE;
101 m_keywords = wxEmptyString;
102 m_updateLists = FALSE;
103 m_updateInterval = 600; // Milliseconds
106 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
108 ecDialog::Create(parent, ecID_PACKAGES_DIALOG, _("Packages"),
109 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
111 CreateControls(this);
118 ecPackagesDialog::~ecPackagesDialog()
123 // TODO: implement wxLB_SORT style in wxGTK.
124 void ecPackagesDialog::CreateControls(wxWindow* parent)
126 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
128 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
130 wxSizer *item2 = new wxBoxSizer( wxVERTICAL );
132 wxStaticText *item3 = new wxStaticText( parent, wxID_STATIC, _("Available &packages:"), wxDefaultPosition, wxDefaultSize, 0 );
133 item2->Add( item3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
135 wxString *strs4 = (wxString*) NULL;
136 wxListBox *item4 = new wxListBox( parent, ecID_PACKAGES_DIALOG_AVAILABLE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs4, wxLB_SORT|wxLB_HSCROLL );
137 item2->Add( item4, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
139 item1->Add( item2, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
141 wxSizer *item5 = new wxBoxSizer( wxVERTICAL );
143 wxButton *item6 = new wxButton( parent, ecID_PACKAGES_DIALOG_ADD, _("&Add >>"), wxDefaultPosition, wxDefaultSize, 0 );
144 item5->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
146 wxButton *item7 = new wxButton( parent, ecID_PACKAGES_DIALOG_REMOVE, _("<< &Remove"), wxDefaultPosition, wxDefaultSize, 0 );
147 item5->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
149 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 0 );
151 wxSizer *item8 = new wxBoxSizer( wxVERTICAL );
153 wxStaticText *item9 = new wxStaticText( parent, wxID_STATIC, _("&Use these packages:"), wxDefaultPosition, wxDefaultSize, 0 );
154 item8->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
156 wxString *strs10 = (wxString*) NULL;
157 wxListBox *item10 = new wxListBox( parent, ecID_PACKAGES_DIALOG_USE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs10, wxLB_SORT|wxLB_HSCROLL );
158 item8->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
160 item1->Add( item8, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
162 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
164 wxStaticText *item11 = new wxStaticText( parent, wxID_STATIC, _("&Version:"), wxDefaultPosition, wxDefaultSize, 0 );
165 item0->Add( item11, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
167 wxString *strs12 = (wxString*) NULL;
168 wxChoice *item12 = new wxChoice( parent, ecID_PACKAGES_DIALOG_VERSION, wxDefaultPosition, wxSize(100,-1), 0, strs12, 0 );
169 item0->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 10 );
171 wxTextCtrl *item13 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_DESCRIPTION, _(""), wxDefaultPosition, wxSize(80,110), wxTE_MULTILINE );
172 item0->Add( item13, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 10 );
174 wxStaticText *item14 = new wxStaticText( parent, wxID_STATIC, _("&Keywords:"), wxDefaultPosition, wxDefaultSize, 0 );
175 item0->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
177 wxSizer *item15 = new wxBoxSizer( wxHORIZONTAL );
179 wxTextCtrl *item16 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_KEYWORDS, _(""), wxDefaultPosition, wxSize(80,-1), 0 );
180 item15->Add( item16, 1, wxALIGN_CENTRE|wxALL, 5 );
182 wxButton *item17 = new wxButton( parent, ecID_PACKAGES_DIALOG_CLEAR, _("C&lear"), wxDefaultPosition, wxDefaultSize, 0 );
183 item15->Add( item17, 0, wxALIGN_CENTRE|wxALL, 5 );
185 item0->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
187 wxSizer *item18 = new wxBoxSizer( wxHORIZONTAL );
189 wxCheckBox *item19 = new wxCheckBox( parent, ecID_PACKAGES_DIALOG_OMIT_HARDWARE, _("&Omit hardware packages"), wxDefaultPosition, wxDefaultSize, 0 );
190 item18->Add( item19, 0, wxALIGN_CENTRE|wxALL, 5 );
192 wxCheckBox *item20 = new wxCheckBox( parent, ecID_PACKAGES_DIALOG_EXACT_MATCH, _("&Match exactly"), wxDefaultPosition, wxDefaultSize, 0 );
193 item18->Add( item20, 0, wxALIGN_CENTRE|wxALL, 5 );
195 item18->Add( 20, 20, 1, wxALIGN_CENTRE|wxALL, 5 );
197 wxButton *item21 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
198 item21->SetDefault();
199 item18->Add( item21, 0, wxALIGN_CENTRE|wxALL, 5 );
201 wxButton *item22 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
202 item18->Add( item22, 0, wxALIGN_CENTRE|wxALL, 5 );
204 item0->Add( item18, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
207 wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
209 wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
211 wxSizer *item2 = new wxBoxSizer( wxVERTICAL );
213 wxStaticText *item3 = new wxStaticText( parent, wxID_STATIC, _("Available &packages:"), wxDefaultPosition, wxDefaultSize, 0 );
214 item2->Add( item3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
216 wxString *strs4 = (wxString*) NULL;
217 wxListBox *item4 = new wxListBox( parent, ecID_PACKAGES_DIALOG_AVAILABLE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs4, wxLB_SORT|wxLB_HSCROLL );
218 item2->Add( item4, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
220 item1->Add( item2, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
222 wxSizer *item5 = new wxBoxSizer( wxVERTICAL );
224 wxButton *item6 = new wxButton( parent, ecID_PACKAGES_DIALOG_ADD, _("&Add >>"), wxDefaultPosition, wxDefaultSize, 0 );
225 item5->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
227 wxButton *item7 = new wxButton( parent, ecID_PACKAGES_DIALOG_REMOVE, _("<< &Remove"), wxDefaultPosition, wxDefaultSize, 0 );
228 item5->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
230 item1->Add( item5, 0, wxALIGN_CENTRE|wxALL, 0 );
232 wxSizer *item8 = new wxBoxSizer( wxVERTICAL );
234 wxStaticText *item9 = new wxStaticText( parent, wxID_STATIC, _("&Use these packages:"), wxDefaultPosition, wxDefaultSize, 0 );
235 item8->Add( item9, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
237 wxString *strs10 = (wxString*) NULL;
238 wxListBox *item10 = new wxListBox( parent, ecID_PACKAGES_DIALOG_USE_LIST, wxDefaultPosition, wxSize(230,190), 0, strs10, wxLB_SORT|wxLB_HSCROLL );
239 item8->Add( item10, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
241 item1->Add( item8, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
243 item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
245 wxStaticText *item11 = new wxStaticText( parent, wxID_STATIC, _("&Version:"), wxDefaultPosition, wxDefaultSize, 0 );
246 item0->Add( item11, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
248 wxString *strs12 = (wxString*) NULL;
249 wxChoice *item12 = new wxChoice( parent, ecID_PACKAGES_DIALOG_VERSION, wxDefaultPosition, wxSize(100,-1), 0, strs12, 0 );
250 item0->Add( item12, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 10 );
252 wxTextCtrl *item13 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_DESCRIPTION, _(""), wxDefaultPosition, wxSize(80,110), wxTE_MULTILINE );
253 item0->Add( item13, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 10 );
255 wxStaticText *item14 = new wxStaticText( parent, wxID_STATIC, _("&Keywords:"), wxDefaultPosition, wxDefaultSize, 0 );
256 item0->Add( item14, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
258 wxSizer *item15 = new wxBoxSizer( wxHORIZONTAL );
260 wxTextCtrl *item16 = new wxTextCtrl( parent, ecID_PACKAGES_DIALOG_KEYWORDS, _(""), wxDefaultPosition, wxSize(80,-1), 0 );
261 item15->Add( item16, 1, wxALIGN_CENTRE|wxALL, 5 );
263 wxButton *item17 = new wxButton( parent, ecID_PACKAGES_DIALOG_CLEAR, _("C&lear"), wxDefaultPosition, wxDefaultSize, 0 );
264 item15->Add( item17, 0, wxALIGN_CENTRE|wxALL, 5 );
266 item0->Add( item15, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
268 wxSizer *item18 = new wxBoxSizer( wxHORIZONTAL );
270 wxCheckBox *item19 = new wxCheckBox( parent, ecID_PACKAGES_DIALOG_OMIT_HARDWARE, _("Omit hardware packages"), wxDefaultPosition, wxDefaultSize, 0 );
271 item18->Add( item19, 0, wxALIGN_CENTRE|wxALL, 5 );
273 item18->Add( 20, 20, 1, wxALIGN_CENTRE|wxALL, 5 );
275 wxButton *item20 = new wxButton( parent, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
276 item20->SetDefault();
277 item18->Add( item20, 0, wxALIGN_CENTRE|wxALL, 5 );
279 wxButton *item21 = new wxButton( parent, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
280 item18->Add( item21, 0, wxALIGN_CENTRE|wxALL, 5 );
282 item0->Add( item18, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
286 wxButton *contextButton = new wxContextHelpButton( parent );
287 item18->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
290 parent->FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetFocus();
292 parent->SetAutoLayout( TRUE );
293 parent->SetSizer( item0 );
295 item0->Fit( parent );
296 //item0->SetSizeHints( parent );
298 // Add context-sensitive help text
299 parent->FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST )->SetHelpText(_("Displays the list of packages available, but not currently loaded."));
300 parent->FindWindow( ecID_PACKAGES_DIALOG_USE_LIST )->SetHelpText(_("Displays the list of packages currently loaded."));
301 parent->FindWindow( ecID_PACKAGES_DIALOG_ADD )->SetHelpText(_("Add one or more packages to the list to be loaded."));
302 parent->FindWindow( ecID_PACKAGES_DIALOG_REMOVE )->SetHelpText(_("Removes one or more packages from the list to be loaded."));
303 parent->FindWindow( ecID_PACKAGES_DIALOG_VERSION )->SetHelpText(_("Displays the version of the selected packages."));
304 parent->FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION )->SetHelpText(_("Displays a description of the selected package (blank if more than one package is selected)."));
305 parent->FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetHelpText(_("Enter keywords here to restrict displayed packages."));
306 parent->FindWindow( ecID_PACKAGES_DIALOG_CLEAR )->SetHelpText(_("Clears the keyword field."));
307 parent->FindWindow( ecID_PACKAGES_DIALOG_OMIT_HARDWARE)->SetHelpText(_("Check this to omit hardware packages, uncheck to show all packages."));
308 parent->FindWindow( ecID_PACKAGES_DIALOG_EXACT_MATCH )->SetHelpText(_("Check this to display exact matches between keyword and aliases (case insensitive)."));
309 parent->FindWindow( wxID_OK )->SetHelpText(_("Closes the dialog and saves any changes you have made."));
310 parent->FindWindow( wxID_CANCEL )->SetHelpText(_("Closes the dialog without saving any changes you have made."));
313 parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));
317 parent->FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION )->SetValidator(wxGenericValidator(& m_packageDescription));
318 parent->FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetValidator(wxGenericValidator(& m_keywords));
319 parent->FindWindow( ecID_PACKAGES_DIALOG_OMIT_HARDWARE )->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_omitHardwarePackages));
320 parent->FindWindow( ecID_PACKAGES_DIALOG_EXACT_MATCH )->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_matchPackageNamesExactly));
323 void ecPackagesDialog::OnInitDialog(wxInitDialogEvent& event)
325 // Note: InitControls must be here, because data will be added
326 // between construction of the dialog, and OnInitDialog.
328 TransferDataToWindow();
331 void ecPackagesDialog::InitControls()
336 void ecPackagesDialog::OnCancel(wxCommandEvent& event)
341 void ecPackagesDialog::OnOK(wxCommandEvent& event)
343 TransferDataFromWindow();
347 // For each word in keywords, is it contained in 'str'?
348 bool ecPackagesDialog::MatchesKeyword(wxArrayString& keywords, const wxString& str)
350 // _Every_ keyword must match
352 for (i = 0; i < keywords.GetCount(); i++)
354 if (str.Find(keywords[i]) == -1)
360 void ecPackagesDialog::Fill()
362 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
363 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
364 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
366 // wxGTK doesn't deselect items properly when clearing, I think
368 for (i = 0; i < availableList->GetCount(); i++)
369 if (availableList->Selected(i))
370 availableList->Deselect(i);
371 for (i = 0; i < useList->GetCount(); i++)
372 if (useList->Selected(i))
373 useList->Deselect(i);
375 availableList->Clear();
379 wxString s2(m_keywords);
383 wxArrayString keywords;
384 wxStringTokenizer tok(s2);
385 while (tok.HasMoreTokens())
387 keywords.Add(tok.GetNextToken());
390 // Initialize the controls
391 for (i = 0; i < GetCount(); i++)
393 const wxString& str = m_items[i];
394 wxListBox* lb = m_arnItems[i] ? useList : availableList;
396 wxString macroName(pDoc->GetPackageName (str));
398 // check if the package is a hardware package
400 if ((!wxGetApp().GetSettings().m_omitHardwarePackages) || !pDoc->GetCdlPkgData ()->is_hardware_package (ecUtils::UnicodeToStdStr (macroName)))
404 if (!m_keywords.IsEmpty())
411 wxString s3(macroName);
415 const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_package_aliases (ecUtils::UnicodeToStdStr (macroName));
417 if (wxGetApp().GetSettings().m_matchPackageNamesExactly)
421 if (s2 == s1 || s2 == s3)
425 for (j = 0; j < aliases.size(); j ++)
427 wxString alias(aliases[j].c_str());
433 matches = (noMatches > 0);
438 // Concatenate all possible text together, and match against that
446 for (j = 0; j < aliases.size(); j ++)
448 wxString alias(aliases[j].c_str());
453 matches = MatchesKeyword(keywords, toMatch);
458 lb->Append(str, (void*) i);
462 UpdateAddRemoveButtons();
464 if (availableList->GetCount() == 1)
466 availableList->SetSelection(0);
467 UpdatePackageDescription();
468 UpdateVersionList ();
469 UpdateHardwareSelectionFlag ();
471 else if (useList->GetCount() == 1)
473 useList->SetSelection(0);
474 UpdatePackageDescription();
475 UpdateVersionList ();
476 UpdateHardwareSelectionFlag ();
478 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS );
479 // Necessary or TransferDataToWindow will cause insertion position to change
480 textCtrl->SetInsertionPointEnd();
483 void ecPackagesDialog::Add(wxListBox* from, wxListBox* to)
485 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
487 wxArrayInt selections;
488 wxStringList selectionsStrings;
489 int n = from -> GetSelections( selections );
494 for (i = 0; i < selections.GetCount(); i++)
496 wxString str = from -> GetString(selections[i]);
497 selectionsStrings.Add(str);
500 // Now delete from one list and remove from t'other
501 for (i = 0; i < selectionsStrings.Number(); i++)
503 wxString str = selectionsStrings[i];
506 int toDelete = from -> FindString(str);
510 itemIndex = (int) from -> GetClientData(toDelete);
511 from -> Delete(toDelete);
514 wxASSERT (itemIndex > -1);
517 to -> Append(str, (void*) itemIndex);
529 int addedIndex = to->FindString(str);
530 to->Select(addedIndex);
533 //ClearDescription();
534 ClearSelections(* from);
535 UpdateHardwareSelectionFlag();
536 UpdatePackageDescription();
541 void ecPackagesDialog::OnAdd(wxCommandEvent& event)
543 if (m_bHardwarePackageSelected)
545 HardwarePackageMessageBox ();
548 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
549 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
551 Add(availableList, useList);
553 UpdateAddRemoveButtons();
556 void ecPackagesDialog::OnRemove(wxCommandEvent& event)
558 if (m_bHardwarePackageSelected)
560 HardwarePackageMessageBox ();
564 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
565 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
567 Add(useList, availableList);
569 UpdateAddRemoveButtons();
572 void ecPackagesDialog::OnDblClickListBox1(wxCommandEvent& event)
574 if (m_bHardwarePackageSelected)
576 HardwarePackageMessageBox ();
580 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
581 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
583 Add(availableList, useList);
585 UpdateAddRemoveButtons();
588 void ecPackagesDialog::OnDblClickListBox2(wxCommandEvent& event)
590 if (m_bHardwarePackageSelected)
592 HardwarePackageMessageBox ();
596 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
597 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
599 Add(useList, availableList);
601 UpdateAddRemoveButtons();
604 void ecPackagesDialog::OnClickListBox1(wxCommandEvent& event)
606 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
607 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
610 int sel = event.GetSelection();
613 // TODO: check that this works for multiple-selection listboxes
614 DisplayDescription(availableList->GetString(sel));
618 ClearSelections(*useList);
619 UpdatePackageDescription ();
620 UpdateVersionList ();
621 UpdateHardwareSelectionFlag ();
622 UpdateAddRemoveButtons();
625 void ecPackagesDialog::OnClickListBox2(wxCommandEvent& event)
627 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
628 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
631 int sel = event.GetSelection();
634 // TODO: check that this works for multiple-selection listboxes
635 DisplayDescription(useList->GetString(sel));
639 ClearSelections(*availableList);
640 UpdatePackageDescription ();
641 UpdateVersionList ();
642 UpdateHardwareSelectionFlag ();
643 UpdateAddRemoveButtons();
646 void ecPackagesDialog::OnSelectVersion(wxCommandEvent& event)
648 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
649 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
650 wxChoice* versionChoice = (wxChoice*) FindWindow( ecID_PACKAGES_DIALOG_VERSION );
652 if (-1 == versionChoice->GetSelection ()) // if there is no version selection
653 return; // do nothing
655 wxListBox * pListBox = NULL;
657 wxArrayInt selected1, selected2;
658 availableList->GetSelections(selected1);
659 useList->GetSelections(selected2);
661 int nListSelCount = selected1.GetCount ();
662 if (nListSelCount > 0)
664 pListBox = availableList;
668 nListSelCount = selected2.GetCount ();
678 // retrieve the list box indices of the selected packages
680 wxArrayInt* selected = (pListBox == availableList ? & selected1 : & selected2);
683 for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
685 // set the package version to that specified in the version combo box
686 wxString str = versionChoice->GetString(nIndex);
688 // itemIndex is the index into the list of item names. It gets stored with all the listbox items.
689 int itemIndex = (int) pListBox->GetClientData((*selected)[nIndex]);
690 m_currentVersions[(size_t)itemIndex] = str;
694 void ecPackagesDialog::OnClearKeywords(wxCommandEvent& event)
696 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS );
697 textCtrl->SetValue(wxT(""));
698 TransferDataFromWindow();
700 m_updateLists = FALSE;
702 FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetFocus();
705 void ecPackagesDialog::OnUpdateKeywordText(wxCommandEvent& event)
707 // Work around a bug in GTK+ that sends a text update command when
708 // clicking on one of the listboxes.
709 wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS );
710 wxString value = textCtrl->GetValue();
711 if (value == m_keywords)
714 TransferDataFromWindow();
715 m_updateLists = TRUE;
719 void ecPackagesDialog::OnClickOmitHardwarePackages(wxCommandEvent& event)
721 TransferDataFromWindow();
725 void ecPackagesDialog::OnClickExactMatch(wxCommandEvent& event)
727 TransferDataFromWindow();
731 void ecPackagesDialog::OnIdle(wxIdleEvent& event)
733 long elapsed = wxGetElapsedTime(FALSE);
734 if (m_updateLists && (elapsed > m_updateInterval))
736 m_updateLists = FALSE;
742 void ecPackagesDialog::Insert(const wxString& str, bool added, const wxString& descr, const wxString& version)
744 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
745 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
748 m_descriptions.Add(str);
749 m_currentVersions.Add(version);
750 m_arnItems.Add(added);
755 //(added ? useList : availableList) -> Append(str);
758 bool ecPackagesDialog::IsAdded(const wxString& str)
760 return (m_added.Index(str) != wxNOT_FOUND);
762 // return (((wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ))->FindString(str) > -1) ;
765 static int ecPositionInStringList(const wxStringList& list, const wxString& item)
768 for (i = 0 ; i < list.Number(); i++)
776 void ecPackagesDialog::DisplayDescription(const wxString& item)
778 //wxTextCtrl* descrCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION ) ;
779 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
781 // int pos = ecPositionInStringList(m_items, item);
785 // wxString descr = m_descriptions[pos];
787 // text += wxT("\n");
789 wxString macroName(pDoc->GetPackageName (item));
792 const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_package_aliases (ecUtils::UnicodeToStdStr (macroName));
795 for (j = 0; j < aliases.size(); j ++)
798 text += wxT(".\nAliases: ");
802 wxString alias(aliases[j].c_str());
805 text += wxT("\nMacro: ");
809 wxString descr = pDoc->GetCdlPkgData ()->get_package_description (ecUtils::UnicodeToStdStr (macroName)).c_str ();
811 text += ecUtils::StripExtraWhitespace (descr);
813 m_packageDescription = text;
815 //descrCtrl->SetValue(text);
819 void ecPackagesDialog::ClearDescription()
821 wxTextCtrl* descrCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_DESCRIPTION ) ;
822 descrCtrl->SetValue(wxEmptyString);
825 wxString ecPackagesDialog::GetVersion (const wxString& item)
828 for (nCount = GetCount() - 1; nCount >= 0; --nCount)
830 if (m_items [nCount] == item)
832 return m_currentVersions [nCount];
836 return wxEmptyString;
839 void ecPackagesDialog::UpdateHardwareSelectionFlag()
841 m_bHardwarePackageSelected = FALSE;
843 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
844 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
845 wxListBox * pListBox = NULL;
847 wxArrayInt selections1, selections2;
848 wxArrayInt* selections = NULL;
849 availableList->GetSelections(selections1);
850 useList->GetSelections(selections2);
852 int nListSelCount = selections1.GetCount ();
855 pListBox = availableList;
856 selections = & selections1;
860 nListSelCount = selections2.GetCount ();
864 selections = & selections2;
868 if (pListBox) // if there are packages selected
870 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
872 // retrieve the list box indices of the selected packages
874 //int * arnIndices = new int [nListSelCount];
875 //pListBox->GetSelItems (nListSelCount, arnIndices);
878 for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
880 wxString strPackageAlias = pListBox->GetString((*selections)[nIndex]);
882 // check if the package is a hardware package
884 //TRACE (_T("Checking '%s' for hardware status\n"), strPackageAlias);
885 if (pDoc->GetCdlPkgData ()->is_hardware_package (ecUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias))))
887 m_bHardwarePackageSelected = TRUE;
894 void ecPackagesDialog::HardwarePackageMessageBox()
896 // TODO: could give the user the choice of going to the template dialog.
897 wxMessageBox (wxT("Add and remove hardware packages by selecting a new hardware template."),
898 wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK, this);
901 void ecPackagesDialog::UpdatePackageDescription ()
903 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
905 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
906 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
908 wxListBox * pListBox = NULL;
910 wxArrayInt selections1, selections2;
911 wxArrayInt* selections = NULL;
912 availableList->GetSelections(selections1);
913 useList->GetSelections(selections2);
915 if (1 == selections1.GetCount ())
917 pListBox = availableList;
918 selections = & selections1;
920 else if (1 == selections2.GetCount ())
923 selections = & selections2;
926 if (pListBox && selections)
928 int nIndex = (*selections)[0];
929 wxString strPackageAlias = pListBox->GetString(nIndex);
931 DisplayDescription(strPackageAlias);
932 //m_packageDescription = pDoc->GetCdlPkgData ()->get_package_description (ecUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias))).c_str ();
933 //m_packageDescription = ecUtils::StripExtraWhitespace (m_packageDescription);
937 m_packageDescription = wxEmptyString;
939 TransferDataToWindow ();
942 void ecPackagesDialog::UpdateVersionList ()
944 ecConfigToolDoc * pDoc = wxGetApp().GetConfigToolDoc ();
946 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
947 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
948 wxChoice* versionChoice = (wxChoice*) FindWindow( ecID_PACKAGES_DIALOG_VERSION );
950 versionChoice->Clear(); // clear the version combo box
952 wxArrayInt selections1, selections2;
953 wxArrayInt* selections = NULL;
954 availableList->GetSelections(selections1);
955 useList->GetSelections(selections2);
956 wxListBox* pListBox = NULL;
958 if (selections1.GetCount () > 0)
960 pListBox = availableList;
961 selections = & selections1;
963 else if (selections2.GetCount () > 0)
966 selections = & selections2;
969 if (pListBox) // if there are packages selected
971 std::list<std::string> common_versions;
972 bool bCommonSelectedVersion = true;
973 int nCommonVersionIndex=-1;
974 int nListSelCount = selections->GetCount();
976 // retrieve the list box indices of the selected packages
978 //int * arnIndices = new int [nListSelCount];
979 //pListBox->GetSelItems (nListSelCount, arnIndices);
981 for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package
983 // retrieve the first package alias
984 wxString strPackageAlias = pListBox->GetString ((*selections)[nIndex]);
986 // retrieve the dialog item array index for use in
987 // comparing current version strings
988 const int nVersionIndex = (int) pListBox->GetClientData ((*selections)[nIndex]);
990 // retrieve the installed version array
992 //TRACE (_T("Retrieving versions for '%s'\n"), strPackageAlias);
993 const std::vector<std::string>& versions = pDoc->GetCdlPkgData ()->get_package_versions (ecUtils::UnicodeToStdStr (pDoc->GetPackageName (strPackageAlias)));
995 if (0 == nIndex) // if this is the first selected package
997 // use the version array to initialise a linked list of version
998 // strings held in common between the selected packages
1000 for (uCount = 0; uCount < versions.size (); uCount++)
1002 //TRACE (_T("Adding common version '%s'\n"), wxString (versions [uCount].c_str ()));
1003 common_versions.push_back (versions [uCount]);
1005 nCommonVersionIndex = nVersionIndex; // save the item array index
1007 else // this is not the first selected package
1009 std::list<std::string>::iterator i_common_versions = common_versions.begin ();
1010 while (i_common_versions != common_versions.end ()) // iterate through the common versions
1012 if (versions.end () == std::find (versions.begin (), versions.end (), * i_common_versions)) // if the common version is not in the versions list
1014 //TRACE (_T("Removing common version '%s'\n"), CString (i_common_versions->c_str ()));
1015 common_versions.erase (i_common_versions++); // remove the version from the common versions list
1019 i_common_versions++;
1022 if (bCommonSelectedVersion) // if the selected versions of all preceding packages are identical
1024 // check if the selected version of this package matches that of the preceding ones
1025 bCommonSelectedVersion = (m_currentVersions [nVersionIndex] == m_currentVersions [nCommonVersionIndex]);
1030 // add the common versions to the version combo box
1032 std::list<std::string>::iterator i_common_versions;
1033 for (i_common_versions = common_versions.begin (); i_common_versions != common_versions.end (); i_common_versions++)
1035 //TRACE (_T("Adding version '%s'\n"), CString (i_common_versions->c_str ()));
1036 versionChoice->Append(wxString (i_common_versions->c_str ()));
1039 // select the common current version (if any) in the version combo box
1041 if (bCommonSelectedVersion)
1043 //TRACE (_T("Selecting version '%s'\n"), m_arstrVersions [nCommonVersionIndex]);
1044 versionChoice->SetStringSelection (m_currentVersions [nCommonVersionIndex]);
1047 // enable the version combo box only if there are multiple common versions
1049 versionChoice->Enable (common_versions.size () > 1);
1051 else // there are no packages selected
1053 versionChoice->Enable (FALSE); // disable the version combo box
1057 void ecPackagesDialog::UpdateAddRemoveButtons()
1059 wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST );
1060 wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST );
1062 wxArrayInt selections1, selections2;
1063 availableList->GetSelections(selections1);
1064 useList->GetSelections(selections2);
1066 FindWindow( ecID_PACKAGES_DIALOG_ADD )->Enable( selections1.GetCount() > 0 );
1067 FindWindow( ecID_PACKAGES_DIALOG_REMOVE )->Enable( selections2.GetCount() > 0 );
1070 void ecPackagesDialog::ClearSelections(wxListBox& lbox)
1073 for (i = 0; i < lbox.Number(); i++)
1079 void ecPackagesTimer::Notify()
1081 static bool s_inNotify = FALSE;
1088 // On Windows, simply having the timer going will ping the message queue
1089 // and cause idle processing to happen.
1090 // On Unix, this doesn't happen so we have to do the processing explicitly.
1097 m_dialog->OnIdle(event);