📄 mainfrm.cpp
字号:
void CMainFrame::OnViewOutput() { arView[Output].bVisible^=1; arView[Output].pParent->ShowPane(arView[Output].pView,arView[Output].bVisible);}void CMainFrame::OnUpdateViewOutput(CCmdUI* pCmdUI) { pCmdUI->SetCheck(arView[Output].bVisible);} void CMainFrame::OnUpdateBuildConfigure(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnBuildStop() { m_sp.Kill(); // leave the rest to OnSubprocessComplete()}void CMainFrame::OnUpdateBuildStop(CCmdUI* pCmdUI) { pCmdUI->Enable(m_sp.ProcessAlive());}void CMainFrame::OnConfigurationBuild() { Build();}DWORD CMainFrame::ThreadFunc(LPVOID param){ CMainFrame *pMain=(CMainFrame *)param; CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); CString strCmd(_T("make -n ")); strCmd+=pMain->m_strBuildTarget; SetCurrentDirectory(pDoc->BuildTree()); String strOut; CSubprocess sp; sp.Run(strOut,strCmd); // Don't attempt to change the thermometer itself - not safe from a separate thread pMain->m_nThermometerMax=pDoc->GetCompilationCount(strOut); return 0;}void CMainFrame::Build(const CString &strWhat/*=_T("")*/){ ASSERT(!m_sp.ProcessAlive()); CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); if(!arView[Output].bVisible){ SendMessage(WM_COMMAND,ID_VIEW_OUTPUT,0); } if(pDoc->IsModified()||pDoc->BuildTree().IsEmpty()){ SendMessage (WM_COMMAND, ID_FILE_SAVE); } if(!(pDoc->IsModified()||pDoc->BuildTree().IsEmpty())){ // verify the save worked CString strCmd (_T("make")); if(!strWhat.IsEmpty()){ strCmd+=_TCHAR(' '); strCmd+=strWhat; } if(!GetApp()->m_strMakeOptions.IsEmpty()){ strCmd+=_TCHAR(' '); strCmd+=GetApp()->m_strMakeOptions; } strCmd += _T(" --directory "); // Quoting the name may not mix with the 'sh' command on Unix, so only do it // under Windows where it's more likely there will be spaces needing quoting.#ifdef _WINDOWS CString buildDir(pDoc->BuildTree()); #if 1 // ecUSE_ECOS_X_NOTATION std::string cPath = cygpath(std::string(pDoc->BuildTree())); buildDir = cPath.c_str();#endif strCmd += CString(_T("\"")) + buildDir + CString(_T("\""));#else strCmd += CString(pDoc->BuildTree()) ;#endif if(PrepareEnvironment()){ m_strBuildTarget=strWhat; SetThermometerMax(250); // This is just a guess. The thread we are about to spawn will work out the correct answer m_nLogicalLines=0; UpdateThermometer(0); CloseHandle(CreateThread(NULL, 0, ThreadFunc, this, 0 ,&m_dwThreadId)); CString strMsg; strMsg.Format(_T("Building %s"),strWhat); SetIdleMessage(strMsg); SetTimer(42,1000,0); // This timer checks for process completion SetCurrentDirectory(pDoc->BuildTree()); m_sp.Run(SubprocessOutputFunc, this, strCmd, false); SetIdleMessage(); } }}CConfigToolApp * CMainFrame::GetApp(){ return (CConfigToolApp *)AfxGetApp();}void CMainFrame::ActivateFrame(int nCmdShow) { CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); CRect rcDefault; SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcDefault, 0); // Insist on nothing more than 1000 width, with the golden ratio rcDefault.DeflateRect(max(0,(rcDefault.Width()-1000)/2),max(0,(rcDefault.Height()-618)/2)); GetApp()->RestoreWindowPlacement (this, _T("Window size"),rcDefault); LoadBarState(_T("DockState")); ShowControlBar(&m_wndMLTToolBar,arView[MLT].bVisible,false); CFrameWnd::ActivateFrame(nCmdShow); // must be before we muck about with the splitters CRect rcClient; GetClientRect(rcClient); for(int j=0;j<sizeof arSplit/sizeof arSplit[0];j++){ Split &s=arSplit[j]; if(s.pSplit){ CString strKey; strKey.Format(_T("Split %d"),j); const CString strSplit(GetApp()->GetProfileString(_T("Split"),strKey)); double fSplit=s.fFrac; _tscanf(_T("%f"),&fSplit); s.pSplit->SetSplitPoint(fSplit); s.pSplit->RecalcLayout(); } } for(int i=0;i<PaneTypeMax;i++){ ViewStruct &v=arView[(PaneType)i]; v.pParent->ShowPane(v.pView,v.bVisible); } RecalcLayout(); pDoc->UpdateFailingRuleCount(); }void CMainFrame::OnDestroy() { GetApp()->SaveWindowPlacement (this, _T("Window size")); for(int i=0;i<PaneTypeMax;i++){ LOGFONT lf; ViewStruct &v=arView[(PaneType)i]; v.font.GetLogFont(&lf); GetApp()->SaveFont(v.pszName,lf); } for(int j=0;j<sizeof arSplit/sizeof arSplit[0];j++){ Split &s=arSplit[j]; if(s.pSplit){ CString strSplit; strSplit.Format(_T("%f"),s.pSplit->GetSplitPoint()); CString strKey; strKey.Format(_T("%d"),j); GetApp()->WriteProfileString(_T("Split"),strKey,strSplit); } } for(j=0;j<sizeof arSplit/sizeof arSplit[0];j++){ Split &s=arSplit[j]; if(s.pSplit){ deleteZ(s.pSplit); } } if(m_sp.ProcessAlive()){ m_sp.Kill(); } for(i=0;i<sizeof arView/sizeof arView[0];i++){ GetApp()->WriteProfileInt(_T("Windows"), arView[i].pszName, arView[i].bVisible); } CFrameWnd::OnDestroy();}void CMainFrame::OnBuildTests() { Build("tests");}void CMainFrame::OnUpdateBuildTests(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnUpdateFileSave(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnUpdateFileSaveAs(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnUpdateFileNew(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnUpdateAppExit(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam) { CFrameWnd::OnSysCommand(nID, lParam);}void CMainFrame::OnUpdateConfigurationRefresh(CCmdUI* pCmdUI) { CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); pCmdUI->Enable(!m_sp.ProcessAlive() && !pDoc->BuildTree().IsEmpty());}void CMainFrame::OnConfigurationRefresh() { CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); pDoc->Reload();}void CMainFrame::OnViewSettings() { CViewOptions dlg; dlg.DoModal();}void CMainFrame::OnHelp() // Help->Configuration Tool Help{ CConfigTool::GetConfigToolDoc()->ShowURL(CUtils::LoadString(IDS_CONFIGTOOL_HELP));}void CMainFrame::OnSize(UINT nType, int cx, int cy) { CFrameWnd::OnSize(nType, cx, cy); if(m_wndStatusBar){ cx=max(0,cx-m_nFailRulePaneSize-m_nThermometerPaneSize-m_nPercentagePaneSize); m_wndStatusBar.SetPaneInfo(StatusPane, 0, SBPS_STRETCH , 0); m_wndStatusBar.SetPaneInfo(ThermometerPane, 0, SBPS_NORMAL, m_nThermometerPaneSize); m_wndStatusBar.SetPaneInfo(PercentagePane, 0, SBPS_NORMAL, m_nPercentagePaneSize); m_wndStatusBar.SetPaneInfo(FailRulePane, 0, SBPS_NORMAL, m_nFailRulePaneSize); CRect rc; m_wndStatusBar.GetItemRect(ThermometerPane, rc); // Reposition the progress control correctly! m_Progress.SetWindowPos(&wndTop, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0); }}void CMainFrame::OnUpdateConfigurationRepository(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnWindowNext() { BumpWindow(+1);}void CMainFrame::OnWindowPrev() { BumpWindow(-1);}void CMainFrame::BumpWindow(int nInc){ CWnd *pWnd=CWnd::GetFocus(); if(pWnd){ int nWindows=sizeof arView/sizeof arView[0]; for(int i=0;i<nWindows;i++){ CWnd *pThisWnd=arView[i].pView; if(pWnd->m_hWnd==pThisWnd->m_hWnd){ for(int j=((i+nInc+nWindows)%nWindows);j!=i;j=((j+nInc+nWindows)%nWindows)){ if(arView[j].bVisible){ arView[j].pView->SetFocus(); return; } } } } }}void CMainFrame::OnHelpSubmitPr() { CString strURL; if(strURL.LoadString(IDS_ECOS_PR_URL)){ CConfigTool::GetConfigToolDoc()->ShowURL(strURL); }}void CMainFrame::OnHelpEcos() { CString strURL; if(strURL.LoadString(IDS_ECOS_SOURCEWARE_URL)){ CConfigTool::GetConfigToolDoc()->ShowURL(strURL); }}void CMainFrame::OnHelpEcoshome() { CString strURL; if(strURL.LoadString(IDS_ECOS_HOME_URL)){ CConfigTool::GetConfigToolDoc()->ShowURL(strURL); }}void CMainFrame::OnHelpRedHatHome() { CString strURL; if(strURL.LoadString(IDS_RED_HAT_HOME_URL)){ CConfigTool::GetConfigToolDoc()->ShowURL(strURL); }}void CMainFrame::OnHelpUitron() { CString strURL; if(strURL.LoadString(IDS_UITRON_HOME_URL)){ CConfigTool::GetConfigToolDoc()->ShowURL(strURL); }}void CMainFrame::OnBuildClean() { Build("clean");}void CMainFrame::OnUpdateBuildClean(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_sp.ProcessAlive());}void CMainFrame::OnToolsShell() { if(PrepareEnvironment()){ CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); const CFileName strOldFolder(CFileName::SetCurrentDirectory(pDoc->BuildTree())); CUtils::Launch(_T(""),CUtils::LoadString(IDS_SHELL_NAME)); if(!strOldFolder.IsEmpty()){ // if the current directory was changed SetCurrentDirectory(strOldFolder); // restore the previous current directory } }}bool CMainFrame::PrepareEnvironment(bool bWithBuildTools /* = true */){ CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc(); CConfigToolApp *pApp=(CConfigToolApp *)GetApp(); ::SetEnvironmentVariable(_T("PATH"),pApp->m_strOriginalPath); const CString strPrefix(pDoc->CurrentTargetPrefix()); CFileName strBinDir; bool rc=(! bWithBuildTools) || pApp->m_arstrBinDirs.Lookup(strPrefix,strBinDir); if(!rc){ SendMessage(WM_COMMAND,ID_TOOLS_PATHS,0); rc=pApp->m_arstrBinDirs.Lookup(strPrefix,strBinDir); } if(rc){ CFileName strUserBinDir(pApp->m_strUserToolsDir); if(strUserBinDir.IsEmpty()){ if(1==pDoc->m_arstrUserToolPaths.GetSize()){ pApp->m_strUserToolsDir=pDoc->m_arstrUserToolPaths[0]; } else { SendMessage(WM_COMMAND,ID_USERTOOLS_PATHS,0); } strUserBinDir=pApp->m_strUserToolsDir; } if(!strUserBinDir.IsEmpty()){ // calculate the directory of the host tools from this application's module name CFileName strHostToolsBinDir; ::GetModuleFileName (::GetModuleHandle (NULL), strHostToolsBinDir.GetBuffer (1 + MAX_PATH), MAX_PATH); strHostToolsBinDir.ReleaseBuffer (); strHostToolsBinDir = strHostToolsBinDir.Head ();#ifdef _DEBUG strHostToolsBinDir = _T("C:\\Progra~1\\Redhat~1\\eCos");#endif // tools directories are in the order host-tools, user-tools, comp-tools, install/bin (if present), contrib-tools (if present) on the path const CFileName strContribBinDir(strUserBinDir,_T("..\\contrib\\bin")); CFileName strUsrBinDir(strUserBinDir,_T("..\\usr\\bin")); const CFileName strInstallBinDir(pDoc->InstallTree (),_T("bin")); // In case strUserBinDir is e.g. c:\program files\red hat\cygwin-00r1\usertools\h-i686-pc-cygwin\bin if (!strUsrBinDir.IsDir ()) strUsrBinDir = CFileName(strUserBinDir + _T("..\\..\\..\\H-i686-pc-cygwin\\bin")); if ( (strUsrBinDir.IsDir () && ! CUtils::AddToPath (strUsrBinDir)) || (strContribBinDir.IsDir () && ! CUtils::AddToPath (strContribBinDir)) || (strInstallBinDir.IsDir () && ! CUtils::AddToPath (strInstallBinDir)) || (bWithBuildTools && ! CUtils::AddToPath (strBinDir)) || ! CUtils::AddToPath (strUserBinDir) || ! CUtils::AddToPath (strHostToolsBinDir)) { CUtils::MessageBoxF(_T("Failed to set PATH environment variable - rc=%d"),GetLastError()); rc=false; } else { if(!SetEnvironmentVariable(_T("MAKE_MODE"),_T("unix"))){ CUtils::MessageBoxF(_T("Failed to set MAKE_MODE environment variable - rc=%d"),GetLastError()); rc=false; } else { SetEnvironmentVariable(_T("GDBTK_LIBRARY"),NULL); SetEnvironmentVariable(_T("GCC_EXEC_PREFIX"),NULL); SetEnvironmentVariable(_T("ECOS_REPOSITORY"),pDoc->PackagesDir()); // useful for ecosconfig if (! pDoc->BuildTree().IsEmpty()) CygMount(pDoc->BuildTree()[0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -