📄 packagesdlg.cpp
字号:
if (availableList->Selected(i)) availableList->Deselect(i); for (i = 0; i < useList->GetCount(); i++) if (useList->Selected(i)) useList->Deselect(i); availableList->Clear(); useList->Clear(); ClearDescription(); wxString s2(m_keywords); s2.MakeLower(); // Tokenize wxArrayString keywords; wxStringTokenizer tok(s2); while (tok.HasMoreTokens()) { keywords.Add(tok.GetNextToken()); } // Initialize the controls for (i = 0; i < GetCount(); i++) { const wxString& str = m_items[i]; wxListBox* lb = m_arnItems[i] ? useList : availableList; wxString macroName(pDoc->GetPackageName (str)); // check if the package is a hardware package if ((!wxGetApp().GetSettings().m_omitHardwarePackages) || !pDoc->GetCdlPkgData ()->is_hardware_package (ecUtils::UnicodeToStdStr (macroName))) { bool matches = TRUE; if (!m_keywords.IsEmpty()) { // Descriptive name wxString s1(str); s1.MakeLower(); // macro name wxString s3(macroName); s3.MakeLower(); // Match all aliases const std::vector<std::string> & aliases = pDoc->GetCdlPkgData ()->get_package_aliases (ecUtils::UnicodeToStdStr (macroName)); if (wxGetApp().GetSettings().m_matchPackageNamesExactly) { int noMatches = 0; if (s2 == s1 || s2 == s3) noMatches ++; size_t j; for (j = 0; j < aliases.size(); j ++) { wxString alias(aliases[j].c_str()); alias.MakeLower(); if (s2 == alias) noMatches ++; } matches = (noMatches > 0); } else { // Concatenate all possible text together, and match against that wxString toMatch; toMatch += s1; toMatch += s3; size_t j; for (j = 0; j < aliases.size(); j ++) { wxString alias(aliases[j].c_str()); alias.MakeLower(); toMatch += alias; } matches = MatchesKeyword(keywords, toMatch); } } if (matches) lb->Append(str, (void*) i); } } UpdateAddRemoveButtons(); if (availableList->GetCount() == 1) { availableList->SetSelection(0); UpdatePackageDescription(); UpdateVersionList (); UpdateHardwareSelectionFlag (); } else if (useList->GetCount() == 1) { useList->SetSelection(0); UpdatePackageDescription(); UpdateVersionList (); UpdateHardwareSelectionFlag (); } wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS ); // Necessary or TransferDataToWindow will cause insertion position to change textCtrl->SetInsertionPointEnd();}void ecPackagesDialog::Add(wxListBox* from, wxListBox* to){ wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); wxArrayInt selections; wxStringList selectionsStrings; int n = from -> GetSelections( selections ); if (n > 0) { int i; for (i = 0; i < selections.GetCount(); i++) { wxString str = from -> GetString(selections[i]); selectionsStrings.Add(str); } // Now delete from one list and remove from t'other for (i = 0; i < selectionsStrings.Number(); i++) { wxString str = selectionsStrings[i]; // Remove int toDelete = from -> FindString(str); int itemIndex = -1; if (toDelete > -1) { itemIndex = (int) from -> GetClientData(toDelete); from -> Delete(toDelete); } wxASSERT (itemIndex > -1); // Add to -> Append(str, (void*) itemIndex); if (to == useList) { m_added.Add(str); } else { m_added.Remove(str); } // Select it int addedIndex = to->FindString(str); to->Select(addedIndex); } //ClearDescription(); ClearSelections(* from); UpdateHardwareSelectionFlag(); UpdatePackageDescription(); to->SetFocus(); }}void ecPackagesDialog::OnAdd(wxCommandEvent& event){ if (m_bHardwarePackageSelected) { HardwarePackageMessageBox (); return; } wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); Add(availableList, useList); UpdateAddRemoveButtons();}void ecPackagesDialog::OnRemove(wxCommandEvent& event){ if (m_bHardwarePackageSelected) { HardwarePackageMessageBox (); return; } wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); Add(useList, availableList); UpdateAddRemoveButtons();}void ecPackagesDialog::OnDblClickListBox1(wxCommandEvent& event){ if (m_bHardwarePackageSelected) { HardwarePackageMessageBox (); return; } wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); Add(availableList, useList); UpdateAddRemoveButtons();}void ecPackagesDialog::OnDblClickListBox2(wxCommandEvent& event){ if (m_bHardwarePackageSelected) { HardwarePackageMessageBox (); return; } wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); Add(useList, availableList); UpdateAddRemoveButtons();}void ecPackagesDialog::OnClickListBox1(wxCommandEvent& event){ wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); #if 0 int sel = event.GetSelection(); if (sel > -1) { // TODO: check that this works for multiple-selection listboxes DisplayDescription(availableList->GetString(sel)); }#endif ClearSelections(*useList); UpdatePackageDescription (); UpdateVersionList (); UpdateHardwareSelectionFlag (); UpdateAddRemoveButtons();}void ecPackagesDialog::OnClickListBox2(wxCommandEvent& event){ wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); #if 0 int sel = event.GetSelection(); if (sel > -1) { // TODO: check that this works for multiple-selection listboxes DisplayDescription(useList->GetString(sel)); }#endif ClearSelections(*availableList); UpdatePackageDescription (); UpdateVersionList (); UpdateHardwareSelectionFlag (); UpdateAddRemoveButtons();}void ecPackagesDialog::OnSelectVersion(wxCommandEvent& event){ wxListBox* availableList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_AVAILABLE_LIST ); wxListBox* useList = (wxListBox*) FindWindow( ecID_PACKAGES_DIALOG_USE_LIST ); wxChoice* versionChoice = (wxChoice*) FindWindow( ecID_PACKAGES_DIALOG_VERSION ); if (-1 == versionChoice->GetSelection ()) // if there is no version selection return; // do nothing wxListBox * pListBox = NULL; wxArrayInt selected1, selected2; availableList->GetSelections(selected1); useList->GetSelections(selected2); int nListSelCount = selected1.GetCount (); if (nListSelCount > 0) { pListBox = availableList; } else { nListSelCount = selected2.GetCount (); if (nListSelCount) pListBox = useList; } wxASSERT (pListBox); if (!pListBox) return; // retrieve the list box indices of the selected packages wxArrayInt* selected = (pListBox == availableList ? & selected1 : & selected2); int nIndex; for (nIndex = 0; nIndex < nListSelCount; nIndex++) // for each selected package { // set the package version to that specified in the version combo box wxString str = versionChoice->GetString(nIndex); // itemIndex is the index into the list of item names. It gets stored with all the listbox items. int itemIndex = (int) pListBox->GetClientData((*selected)[nIndex]); m_currentVersions[(size_t)itemIndex] = str; }}void ecPackagesDialog::OnClearKeywords(wxCommandEvent& event){ wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS ); textCtrl->SetValue(wxT("")); TransferDataFromWindow(); Fill(); m_updateLists = FALSE; wxStartTimer(); FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS )->SetFocus();}void ecPackagesDialog::OnUpdateKeywordText(wxCommandEvent& event){ // Work around a bug in GTK+ that sends a text update command when // clicking on one of the listboxes. wxTextCtrl* textCtrl = (wxTextCtrl*) FindWindow( ecID_PACKAGES_DIALOG_KEYWORDS ); wxString value = textCtrl->GetValue(); if (value == m_keywords) return; TransferDataFromWindow(); m_updateLists = TRUE; wxStartTimer();}void ecPackagesDialog::OnClickOmitHardwarePackages(wxCommandEvent& event){ TransferDataFromWindow(); Fill();}void ecPackagesDialog::OnClickExactMatch(wxCommandEvent& event){ TransferDataFromWindow(); Fill();}void ecPackagesDialog::OnIdle(wxIdleEvent& event){ long elapsed = wxGetElapsedTime(FALSE); if (m_updateLists && (elapsed > m_updateInterval)) { m_updateLists = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -