📄 templatesdlg.cpp
字号:
wxHashTable ht(wxKEY_STRING); wxArrayString ar; for (target_i = targets.begin (); target_i != targets.end (); target_i++) { const std::vector<std::string> & aliases = doc->GetCdlPkgData ()->get_target_aliases (* target_i); // use the first alias (if any) as the description wxString strTargetDescription = aliases.size () ? aliases [0].c_str () : target_i->c_str (); ar.Add(strTargetDescription); ht.Put(strTargetDescription, (wxObject*) (void*) &(*target_i)); } ar.Sort((wxArrayString::CompareFunction) & wxStringCompareFunction); int nIndex = 0; unsigned int i; for (i = 0; i < ar.GetCount(); i ++) { wxString strTargetDescription = ar[i]; std::string *t_i = (std::string*) (void*) ht.Get(strTargetDescription); cdlHardwareCtrl->Append(strTargetDescription, (void*) t_i); // store the target iterator std::string str(* (t_i)); if (m_hardware == str.c_str()) // if current target... { int sel = 0; int i; for (i = 0; i <= nIndex; i++) if (cdlHardwareCtrl->GetClientData(i) == (void*) &(*t_i)) sel = i; cdlHardwareCtrl->SetSelection (sel); // ...select the string } nIndex ++; }#endif if (-1 == cdlHardwareCtrl->GetSelection ()) // if no target selected... cdlHardwareCtrl->SetSelection (0); // ...select the first one // populate the template combo box m_template = doc->GetCdlConfig ()->get_template ().c_str(); const std::vector<std::string> & templates = doc->GetCdlPkgData ()->get_templates (); std::vector<std::string>::const_iterator template_i; nIndex = 0; for (template_i = templates.begin (); template_i != templates.end (); template_i++) { wxString strTemplateDescription = template_i->c_str (); cdlPackageCtrl->Append(strTemplateDescription, (void*) &(*template_i)); // store the template iterator /// m_cboCdlTemplate.SetItemData (nIndex, (DWORD) template_i); // store the template iterator std::string str(* (template_i)); if (m_template == str.c_str()) // if current template... cdlPackageCtrl->SetSelection(nIndex); // ...select the string nIndex ++; } if (-1 == cdlPackageCtrl->GetSelection()) // if no template selected... cdlPackageCtrl->SetSelection(0); // ...select the first one // display initial target and template descriptions wxCommandEvent dummyEvent; OnSelHardwareTemplates(dummyEvent); OnSelPackageTemplates(dummyEvent); // populate the template version combo box UpdateVersionList (doc->GetTemplateVersion ());}void ecTemplatesDialog::OnCancel(wxCommandEvent& event){ event.Skip();}void ecTemplatesDialog::OnOK(wxCommandEvent& event){ event.Skip();}void ecTemplatesDialog::OnDetails(wxCommandEvent& event){ wxWindow* win1 = FindWindow(ecID_TEMPLATES_DIALOG_PACKAGES); wxASSERT( win1 != NULL ); bool show = !win1->IsShown(); ShowDetails(show);}void ecTemplatesDialog::ShowDetails(bool show){ wxWindow* win1 = FindWindow(ecID_TEMPLATES_DIALOG_PACKAGES); wxWindow* win2 = FindWindow(ecID_TEMPLATES_DIALOG_PACKAGES_MSG); wxButton* button = (wxButton*) FindWindow(ecID_TEMPLATES_DIALOG_DETAILS); if (show) { GetSizer()->Add( win2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); GetSizer()->Add( win1, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); button->SetLabel("&Details <<"); } else { GetSizer()->Remove(win1); GetSizer()->Remove(win2); button->SetLabel("&Details >>"); } win1->Show(show); win2->Show(show); Layout(); GetSizer()->Fit( this );}void ecTemplatesDialog::OnSelHardwareTemplates(wxCommandEvent& event){ wxComboBox* cdlHardwareCtrl = (wxComboBox*) FindWindow( ecID_TEMPLATES_DIALOG_HARDWARE_TEMPLATES ) ; wxChoice* cdlPackageCtrl = (wxChoice*) FindWindow( ecID_TEMPLATES_DIALOG_PACKAGE_TEMPLATES ) ; ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); // the target has changed so retrieve the new target description const int nIndex = cdlHardwareCtrl->GetSelection (); //std::vector<std::string>::const_iterator template_i = (std::vector<std::string>::const_iterator) cdlHardwareCtrl->GetClientData (nIndex); std::string* template_i = (std::string*) cdlHardwareCtrl->GetClientData (nIndex); m_hardware = template_i->c_str(); m_strCdlHardwareDescription = doc->GetCdlPkgData ()->get_target_description ((const wxChar*) m_hardware).c_str (); m_strCdlHardwareDescription = ecUtils::StripExtraWhitespace (m_strCdlHardwareDescription); UpdateDetails (); // display new hardware packages in details box TransferDataToWindow (); // display new target description}void ecTemplatesDialog::OnSelPackageTemplates(wxCommandEvent& event){ wxComboBox* cdlHardwareCtrl = (wxComboBox*) FindWindow( ecID_TEMPLATES_DIALOG_HARDWARE_TEMPLATES ) ; wxChoice* cdlPackageCtrl = (wxChoice*) FindWindow( ecID_TEMPLATES_DIALOG_PACKAGE_TEMPLATES ) ; // the template has changed so update the version combo box int nIndex = cdlPackageCtrl->GetSelection (); //std::vector<std::string>::const_iterator template_i = (std::vector<std::string>::const_iterator) cdlPackageCtrl->GetClientData (nIndex); std::string *template_i = (std::string*) cdlPackageCtrl->GetClientData (nIndex); m_template = template_i->c_str(); UpdateVersionList (wxT("")); // repopulate template versions combo box and select most recent version}void ecTemplatesDialog::OnSelPackageVersion(wxCommandEvent& event){ wxString strVersion; ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); wxChoice* cdlVersionCtrl = (wxChoice*) FindWindow( ecID_TEMPLATES_DIALOG_VERSION ) ; strVersion = cdlVersionCtrl->GetStringSelection (); //TRACE (_T("Version '%s' selected\n"), strVersion); m_template_version = ecUtils::UnicodeToStdStr (strVersion).c_str(); m_strCdlTemplateDescription = doc->GetCdlPkgData ()->get_template_description (m_template.c_str(), m_template_version.c_str()).c_str (); m_strCdlTemplateDescription = ecUtils::StripExtraWhitespace (m_strCdlTemplateDescription); UpdateDetails (); // display new template packages in details box TransferDataToWindow (); // display new template description}void ecTemplatesDialog::UpdateVersionList(const wxString& defaultVersion){ wxComboBox* cdlHardwareCtrl = (wxComboBox*) FindWindow( ecID_TEMPLATES_DIALOG_HARDWARE_TEMPLATES ) ; wxChoice* cdlPackageCtrl = (wxChoice*) FindWindow( ecID_TEMPLATES_DIALOG_PACKAGE_TEMPLATES ) ; wxChoice* cdlVersionCtrl = (wxChoice*) FindWindow( ecID_TEMPLATES_DIALOG_VERSION ) ; ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); // clear the version combo box cdlVersionCtrl->Clear (); // get the template version information const std::vector<std::string>& versions = doc->GetCdlPkgData ()->get_template_versions (m_template.c_str()); wxASSERT (versions.size () > 0); // add the template versions to the version combo box for (unsigned int version = 0; version < versions.size (); version++) { // TRACE (_T("Adding version '%s'\n"), CString (versions [version].c_str ())); cdlVersionCtrl->Append (versions [version].c_str ()); } // select the appropriate version in the version combo box if (defaultVersion.IsEmpty()) { // if no default version specified cdlVersionCtrl->SetSelection (versions.size () - 1); // select the most recent version } else { // a default version was specified cdlVersionCtrl->SetStringSelection (defaultVersion); } wxCommandEvent dummyEvent; OnSelPackageVersion(dummyEvent); // enable the version combo box only if there are multiple versions cdlVersionCtrl->Enable (versions.size () > 1);}void ecTemplatesDialog::UpdateDetails(){ ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc(); // retrieve the template and target package names const std::vector<std::string> & template_packages = doc->GetCdlPkgData ()->get_template_packages (m_template.c_str(), m_template_version.c_str()); std::vector<std::string> packages = doc->GetCdlPkgData ()->get_target_packages (m_hardware.c_str()); packages.insert (packages.end (), template_packages.begin (), template_packages.end ()); // retrieve the zeroth (verbose) package alias for each package std::vector<std::string> aliases; unsigned int i; for (i = 0; i < packages.size (); i++) { if (doc->GetCdlPkgData ()->is_known_package (packages [i])) // if the package is installed { aliases.push_back (doc->GetCdlPkgData ()->get_package_aliases (packages [i]) [0]); } else // package is not installed { aliases.push_back ("Unknown package " + packages [i]); } } // sort the aliases into alphabetical order std::sort (aliases.begin (), aliases.end ()); // copy the aliases into the details box m_strCdlTemplatePackages = wxT(""); for (i = 0; i < aliases.size (); i++) { m_strCdlTemplatePackages += aliases [i].c_str ();#ifdef __WXMSW__ m_strCdlTemplatePackages += wxT("\r\n"); // add a CRLF between each alias#else m_strCdlTemplatePackages += wxT("\n"); // add a LF between each alias#endif } // TODO: does this work for CRLF? m_strCdlTemplatePackages.Trim (TRUE); // remove the trailing CRLF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -