📄 configtooldoc.cpp
字号:
wxBusyCursor wait; if(OpenRepository(strNewRepository,NewCdlPkgData,NewCdlInterp,NewCdlConfig,strNewPackagesDir)) { // select the "default" template if it exists // otherwise select the first available template std::string default_template = "default"; if (! NewCdlPkgData->is_known_template (default_template)) { const std::vector<std::string>& templates = NewCdlPkgData->get_templates (); if (templates.size () != 0) default_template = templates [0]; } m_templateVersion = ""; try { const std::vector<std::string>& template_versions = NewCdlPkgData->get_template_versions (default_template); NewCdlConfig->set_template (default_template, template_versions [0], &CdlParseErrorHandler, &CdlParseWarningHandler); m_templateVersion = template_versions [0].c_str(); } catch (CdlStringException exception) { wxString msg; msg.Printf(_("Error loading package template '%s':\n\n%s"), default_template.c_str (), exception.get_message ().c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } catch (...) { wxString msg; msg.Printf(_("Error loading package template '%s'."), default_template.c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } // check the configuration wxASSERT (NewCdlConfig->check_this (cyg_extreme)); // use the new package database, interpreter and configuration delete m_CdlConfig; // delete the previous configuration delete m_CdlInterp; // delete the previous interpreter delete m_CdlPkgData; // delete the previous package database m_CdlPkgData = NewCdlPkgData; m_CdlInterp = NewCdlInterp; m_CdlConfig = NewCdlConfig; // save the repository location SetRepository(strNewRepository); m_strPackagesDir = strNewPackagesDir; // clear the previously specified document file name (if any), // OnNewDocument() calls DeleteContents() so must be called // before AddAllItems() wxDocument::OnNewDocument (); // generate the CConfigItems from their CDL descriptions AddAllItems (); m_bRepositoryOpen=TRUE; // Rebuild help index if it needs building RebuildHelpIndex(FALSE); } else { // failure delete NewCdlConfig; NewCdlConfig = NULL; delete NewCdlInterp; NewCdlInterp = NULL; delete NewCdlPkgData; NewCdlPkgData = NULL; } // install a transaction handler callback function now that the tree exists EnableCallbacks(TRUE); } } wxGetApp().SetStatusText(wxEmptyString, FALSE); return m_bRepositoryOpen;}// Find a valid repository given a directory namebool ecConfigToolDoc::FindRepository (ecFileName& repositoryIn, ecFileName& repositoryOut) const{ if (repositoryIn.IsEmpty()) return FALSE; if (ecFileName(repositoryIn + wxT("ecos.db")).Exists()) { repositoryOut = repositoryIn; repositoryIn = wxPathOnly(repositoryIn); return TRUE; } else if (ecFileName(ecFileName(repositoryIn) + ecFileName(wxT("ecc")) + wxT("ecos.db")).Exists()) { repositoryOut = repositoryIn + wxT("ecc"); return TRUE; } else if (ecFileName(ecFileName(repositoryIn) + ecFileName(wxT("packages")) + wxT("ecos.db")).Exists()) { repositoryOut = repositoryIn + wxT("packages"); return TRUE; } else { return FALSE; }}bool ecConfigToolDoc::OpenRepository (ecFileName& strNewRepository, CdlPackagesDatabase &NewCdlPkgData,CdlInterpreter &NewCdlInterp,CdlConfiguration &NewCdlConfig, wxString &strNewPackagesDir){ bool rc=FALSE; if (strNewRepository.IsEmpty()) return FALSE; ecFileName strNewPackagesDir1; if (!FindRepository(strNewRepository, strNewPackagesDir1)) { wxString msg; msg.Printf(_("%s does not seem to be a source repository."), (const wxChar*) strNewRepository); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } else { strNewPackagesDir = strNewPackagesDir1; const wxString strDatabase = strNewPackagesDir + wxString(wxFILE_SEP_PATH) + wxT("ecos.db"); if(!wxFileExists(strDatabase)) { wxString msg; msg.Printf(_("%s does not seem to be a source repository: %s does not exist"), (const wxChar*) strNewRepository, (const wxChar*) strDatabase); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } else { // create a CDL repository, interpreter and configuration try {// create a new package database, interpreter and configuration NewCdlPkgData = CdlPackagesDatabaseBody::make ((const wxChar*) strNewPackagesDir, &CdlParseErrorHandler, &CdlParseWarningHandler); NewCdlInterp = CdlInterpreterBody::make (); NewCdlConfig = CdlConfigurationBody::make ("eCos", NewCdlPkgData, NewCdlInterp); } catch (CdlStringException exception) { wxString msg; msg.Printf(_("Error opening eCos repository:\n\n%s"), exception.get_message ().c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); return FALSE; } catch (...) { wxString msg; msg.Printf(_("Error opening eCos repository.")); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); return FALSE; } // select the default target if specified in the registry // otherwise select the first available target wxString default_hardware = GetDefaultHardware (); if (! NewCdlPkgData->is_known_target ((const wxChar*) default_hardware)) { const std::vector<std::string>& targets = NewCdlPkgData->get_targets (); if (targets.size () == 0) { wxString msg; msg.Printf(_("Error opening eCos repository:\n\nno hardware templates")); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); return FALSE; } else { default_hardware = targets [0].c_str(); } } try { m_strCdlErrorMessage = wxT(""); NewCdlConfig->set_hardware ((const wxChar*) default_hardware, &CdlParseErrorHandler, &CdlParseWarningHandler); } catch (CdlStringException exception) { if (m_strCdlErrorMessage.IsEmpty ()) { wxString msg; msg.Printf(_("Error loading the default hardware template '%s':\n\n%s"), default_hardware.c_str (), exception.get_message ().c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } else // report the most recent parser message in the message box since there may be no output pane in which to view it { wxString msg; msg.Printf(_("Error loading the default hardware template '%s':\n\n%s\n\nParser message:\n\n%s"), default_hardware.c_str (), exception.get_message ().c_str (), (const wxChar*) m_strCdlErrorMessage); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } return FALSE; } catch (...) { wxString msg; msg.Printf(_("Error loading the default hardware template '%s':\n\n%s"), default_hardware.c_str (), (const wxChar*) m_strCdlErrorMessage); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); return FALSE; } rc=TRUE; } } return rc;}void ecConfigToolDoc::SelectTemplate (const wxString& newTemplate, const wxString& newTemplateVersion){ if ((newTemplate != m_CdlConfig->get_template().c_str()) || (newTemplateVersion != m_templateVersion)){ wxBusyCursor wait; // this may take a little while DeleteItems(); m_templateVersion = wxT(""); try { m_CdlConfig->set_template (newTemplate.c_str(), newTemplateVersion.c_str(), CdlParseErrorHandler, CdlParseWarningHandler); m_templateVersion = newTemplateVersion; } catch (CdlStringException exception) { wxString msg; msg.Printf(wxT("Error loading package template '%s':\n\n%s"), (const wxChar*) newTemplate.c_str (), (const wxChar*) exception.get_message ().c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } catch (...) { wxString msg; msg.Printf(wxT("Error loading package template '%s'."), (const wxChar*) newTemplate.c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } RegenerateData(); if (!GetFilename().IsEmpty()) { // not a new document#if 0 // TODO CopyMLTFiles (); // copy new MLT files to the build tree as necessary#endif } Modify(TRUE); wxGetApp().GetMainFrame()->UpdateFrameTitle(); }}void ecConfigToolDoc::RegenerateData(){ wxBusyCursor wait; // This may take a little while AddAllItems (); // regenerate all the config items since the topology may have changed if (m_strLinkerScriptFolder.IsEmpty ()) { wxMessageBox(_("The eCos linker script macro CYGBLD_LINKER_SCRIPT is not defined."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } if (m_strMemoryLayoutFolder.IsEmpty ()) { wxMessageBox(_("The eCos memory layout macro CYGHWR_MEMORY_LAYOUT is not defined."), wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); } // TODO#if 0 SwitchMemoryLayout (TRUE); // the hardware template may have changed#endif if (GetDocumentSaved() && !wxGetApp().GetSettings().m_editSaveFileOnly) UpdateBuildInfo(); // TODO // CConfigTool::GetControlView()->SelectItem(Item(0));}void ecConfigToolDoc::SelectHardware (const wxString& newTemplate){ const std::string OldTemplate=m_CdlConfig->get_hardware(); if (newTemplate != OldTemplate.c_str()){ DeleteItems(); try { m_CdlConfig->set_hardware (newTemplate.c_str(), CdlParseErrorHandler, CdlParseWarningHandler); } catch (CdlStringException exception) { wxString msg; msg.Printf(_("Error loading hardware template '%s':\n\n%s"), (const wxChar*) newTemplate, (const wxChar*) exception.get_message ().c_str ()); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); m_CdlConfig->set_hardware (OldTemplate, CdlParseErrorHandler, CdlParseWarningHandler); } catch (...) { wxString msg; msg.Printf(_("Error loading hardware template '%s'."), (const wxChar*) newTemplate); wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK); m_CdlConfig->set_hardware (OldTemplate, CdlParseErrorHandler, CdlParseWarningHandler); } RegenerateData(); // TODO#if 0 if (!GetFilename().IsEmpty()) { CopyMLTFiles (); // copy new MLT files to the build tree as necessary }#endif Modify(TRUE); wxGetApp().GetMainFrame()->UpdateFrameTitle(); }}void ecConfigToolDoc::SelectPackages (){ // Crashes the Cygwin 1.0 compiler#ifndef __CYGWIN10__ ecPackagesDialog dlg(wxGetApp().GetTopWindow()); // This map holds the ecConfigItem pointers for the packages loaded before the dialog is invoked. // We cannot use Find(), which traverses all items - potentially those that have been removed wxHashTable arLoadedPackages(wxKEY_STRING); wxBeginBusyCursor(); // generate the contents of the add/remove list boxes const std::vector<std::string> & packages = m_CdlPkgData->get_packages (); std::vector<std::string>::const_iterator package_i; for (package_i = packages.begin (); package_i != packages.end (); package_i++) { // if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not list hardware packages { const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i); wxString strMacroName = package_i->c_str (); // use the first alias (if any) as the package identifier wxString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName.c_str(); ecConfigItem * pItem = Find (strMacroName); if (pItem) // if the package is loaded { arLoadedPackages.Put(strMacroName, pItem); // pass the currently selected package version string to the dialog box const CdlValuable valuable = pItem->GetCdlValuable(); dlg.Insert (strPackageName, TRUE, wxEmptyString, valuable ? wxString (valuable->get_value ().c_str ()) : wxString()); } else { // pass version string of the most latest version to the dialog box dlg.Insert (strPackageName, FALSE, wxEmptyString, wxString (m_CdlPkgData->get_package_versions (* package_i) [0].c_str ())); } } } wxEndBusyCursor(); if (wxID_OK == dlg.ShowModal ()) { bool bChanged = FALSE; // until proved otherwise // determine whether each package has changed loaded/unloaded state for (package_i = packages.begin (); package_i != packages.end (); package_i++) // if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not check hardware packages { const std::vector<std::string> & aliases = m_CdlPkgData->get_package_aliases (* package_i); wxString strMacroName = package_i->c_str (); // use the first alias (if any) as the package identifier wxString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName.c_str(); ecConfigItem *pItem = (ecConfigItem *) arLoadedPackages.Get(strMacroName); //bool bPreviouslyLoaded=arLoadedPackages.Lookup(strMacroName,(void *&)pItem); bool bPreviouslyLoaded = (pItem != NULL); bool bNowLoaded=dlg.IsAdded (strPackageName); // unload packages which are no longer required before // loading new ones to avoid potential duplicate macro definitions if (! bNowLoaded && bPreviouslyLoaded){ // The package was loaded but should now be unloaded: bChanged|=pItem->Unload(); } else if (bNowLoaded) {// if the package should be loaded const wxString strVersion(dlg.GetVersion (strPackageName)); if (bPreviouslyLoaded) { // if the package is already loaded CdlTransactionCallback::set_callback_fn (NULL); // avoid value refresh attempts during load/unload bChanged|=pItem->ChangeVersion(strVersion); CdlTransactionCallback::set_callback_fn (CdlTransactionHandler); // restore value refresh
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -