📄 quincy.cpp
字号:
}
// ----- the run command
bool CQuincyApp::ExecuteRunningProgram()
{
if (m_pDebugger != 0)
return m_pDebugger->ExecuteRunningProgram();
return false;
}
// ------- the step command
bool CQuincyApp::StepProgram()
{
if (m_pDebugger != 0)
return m_pDebugger->StepProgram();
return false;
}
bool CQuincyApp::StepTo(const CString& strFile, int nLineNo)
{
if (m_pDebugger != 0)
return m_pDebugger->StepTo(strFile, nLineNo);
steptobreakpoint = Breakpoint(strFile, nLineNo);
return false;
}
// ------- the step out command
void CQuincyApp::StepOut()
{
if (m_pDebugger != 0)
m_pDebugger->StepOut();
}
// ----- the step over command
void CQuincyApp::OnDebugStepover()
{
if (m_pDebugger == 0 || m_pDebugger->StepOver() == false)
m_pMainWnd->PostMessage(WM_COMMAND, ID_DEBUG_STEP);
}
// ------ disable stepping over if no document is open
void CQuincyApp::OnUpdateDebugStepover(CCmdUI* pCmdUI)
{
pCmdUI->Enable(false);
}
// ------ permit examining
void CQuincyApp::OnUpdateDebugExamine(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pDebugger && !m_pDebugger->isInProgram());
}
// ------ examine command
void CQuincyApp::OnDebugExamine()
{
ASSERT(m_pdlgExamine != 0);
if (GetEditorView() != 0) {
std::string str = GetEditorView()->SelectedText();
if (str.size() > 0)
m_pdlgExamine->m_strExpression = str.c_str();
}
m_pdlgExamine->DoModal();
}
// ------- get the value of a variable: used by watch and examine processes
void CQuincyApp::GetVariableValue(const CString& strVarName, CWnd* wnd)
{
if (m_pDebugger != 0)
m_pDebugger->GetVariableValue(strVarName, wnd);
}
void CQuincyApp::SetVariableValue(const CString& strVarName, const CString& strVarValue)
{
if (m_pDebugger != 0)
m_pDebugger->SetVariableValue(strVarName, strVarValue);
}
void CQuincyApp::CreateWatchWindow()
{
ASSERT(m_pdlgWatch != 0);
if (m_bWatchCreated != true) {
m_pdlgWatch->Create(IDD_WATCH);
m_bWatchCreated = true;
}
}
void CQuincyApp::PostWatchList()
{
if (m_pDebugger && m_pdlgWatch && m_bWatchCreated) {
int ct = m_pdlgWatch->GetWatchCount();
CString* wnames = m_pdlgWatch->GetWatchNames();
m_pDebugger->SetWatchExpressions(wnames, ct);
}
}
// --- called from CQuincyDoc class's Serialize function
void CQuincyApp::SerializeProjectOptions(CArchive& ar, int nSig)
{
if (ar.IsStoring()) {
ar << m_bDebugging;
ar << m_bExceptions;
ar << m_bRTTI;
if (nSig != 9797) {
ar << m_bStrict;
if (nSig == 2002) {
ar << m_nOptimize;
ar << m_strCmdLineOptions;
ar << m_CommandLinePromptOption;
ar << m_strCommandLine;
ar << m_strRuntimeDirectory;
}
}
}
else {
ar >> m_bDebugging;
ar >> m_bExceptions;
ar >> m_bRTTI;
if (nSig != 9797) {
ar >> m_bStrict;
if (nSig == 2002) {
ar >> m_nOptimize;
ar >> m_strCmdLineOptions;
ar >> m_CommandLinePromptOption;
ar >> m_strCommandLine;
ar >> m_strRuntimeDirectory;
}
}
}
SerializeOptions(ar, m_Defines);
SerializeOptions(ar, m_Includes);
SerializeOptions(ar, m_Libs);
}
// --- called only from above
void CQuincyApp::SerializeOptions(CArchive& ar, CStringArray& array)
{
if (ar.IsStoring()) {
int len = array.GetSize();
ar << len;
for (int i = 0; i < len; i++)
ar << array[i];
}
else {
array.RemoveAll();
int len;
ar >> len;
while (len--) {
CString str;
ar >> str;
array.Add(str);
}
}
}
bool CQuincyApp::IsOnCDROM(const CString& strFileSpec)
{
if (strFileSpec.GetLength() < 3)
return false;
char root[4];
for (int i = 0; i < 3; i++)
root[i] = strFileSpec[i];
root[i] = '\0';
return GetDriveType(root) == DRIVE_CDROM;
}
///////////////// breakpoint methods //////////////////////////
// ------ adjust breakpoints when user inserts or deletes lines
void CQuincyApp::AdjustTextLine(const CString& strFile, int nLineno, int nAdjust)
{
std::vector<Breakpoint> dels;
std::vector<Breakpoint> inss;
std::set<Breakpoint>::iterator iter;
// --- if deleting a line with a breakpoint, delete the breakpoint
if (nAdjust < 0) {
Breakpoint fr(strFile, nLineno+1);
iter = breakpoints.find(fr);
if (iter != breakpoints.end())
breakpoints.erase(iter);
}
// --- find the breakpoints for this file greater than the current line
Breakpoint fr(strFile, nLineno);
iter = std::lower_bound(breakpoints.begin(), breakpoints.end(), fr);
while (iter != breakpoints.end() &&
(*iter).m_strFile.CompareNoCase(strFile) == 0) {
Breakpoint fr = *iter;
dels.push_back(fr);
fr.m_nLineNo += nAdjust;
inss.push_back(fr);
iter++;
}
std::vector<Breakpoint>::iterator vfr;
for (vfr = dels.begin(); vfr != dels.end(); vfr++) {
iter = breakpoints.find(*vfr);
if (iter != breakpoints.end())
breakpoints.erase(iter);
}
for (vfr = inss.begin(); vfr != inss.end(); vfr++)
breakpoints.insert(*vfr);
}
// --- set or clear a breakpoint
void CQuincyApp::ToggleBreakpoint(const CString& strFile, int nLineNo)
{
Breakpoint fr(GetFileName(strFile), nLineNo);
std::set<Breakpoint>::iterator iter = breakpoints.find(fr);
if (iter == breakpoints.end())
breakpoints.insert(fr);
else {
breakpoints.erase(iter);
if (m_pDebugger != 0)
m_pDebugger->ClearBreakpoint(fr);
}
}
void CQuincyApp::AddBreakpoint(const CString& strFile, int nLineNo)
{
Breakpoint fr(GetFileName(strFile), nLineNo);
std::set<Breakpoint>::iterator iter = breakpoints.find(fr);
if (iter == breakpoints.end())
breakpoints.insert(fr);
}
// ------ test for a breakpoint set in a file at a line number
bool CQuincyApp::IsBreakpoint(const CString& strFile, int nLineno)
{
Breakpoint fr(strFile, nLineno);
std::set<Breakpoint>::iterator iter = breakpoints.find(fr);
bool bBrk = iter != breakpoints.end();
return bBrk;
}
Breakpoint CQuincyApp::SteptoBreakpoint()
{
Breakpoint pt = steptobreakpoint;
steptobreakpoint = Breakpoint();
return pt;
}
void CQuincyApp::OnDebugWatch()
{
CreateWatchWindow();
m_pdlgWatch->ShowWindow(SW_SHOW);
m_pdlgWatch->SetFocus();
if (m_pdlgWatch->GetWatchCount() == 0) {
if (GetEditorView() != 0) {
std::string str = GetEditorView()->SelectedText();
m_pdlgWatch->AddSelectedWatch(str);
}
else
m_pdlgWatch->AddWatch();
}
}
bool CQuincyApp::StopDebugging()
{
if (m_pDebugger != 0) {
if (AfxMessageBox("This stops the debugger. Continue?", MB_ICONQUESTION | MB_YESNO) == IDYES)
m_pDebugger->Stop();
else
return false;
}
return true;
}
void CQuincyApp::OnAppAbout()
{
CAboutDlg aboutDlg;
// --- display compiler version in about dialog
if (m_bCompilerIsInstalled)
aboutDlg.m_strCompilerVersion = "MinGW GCC version " + m_strVersion;
// --- display operating version in about dialog
aboutDlg.m_strOSVersion.Format("Windows %s Version %ld.%ld Build %ld",
(osversion.dwPlatformId == VER_PLATFORM_WIN32_NT) ? "NT" :
(osversion.dwMinorVersion < 10 ? "95" : "98"),
osversion.dwMajorVersion, osversion.dwMinorVersion,
(osversion.dwPlatformId == VER_PLATFORM_WIN32_NT) ? osversion.dwBuildNumber
: LOWORD(osversion.dwBuildNumber));
aboutDlg.DoModal();
}
void CQuincyApp::OnUpdateGrep(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bGrepIsInstalled);
}
#ifdef TYCPP
void CQuincyApp::OnUpdateTycpp(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bIsTutorial);
}
#endif
void CQuincyApp::OnHelp()
{
ShellExecute(0, "open", (m_strQuincyInstallPath + "\\quincy2002.htm").GetBuffer(0), 0, 0, SW_SHOW);
}
void CQuincyApp::OnUpdateHelp(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bBrowser);
}
void CQuincyApp::OnResourceeditor()
{
RunResourceEditor();
}
void CQuincyApp::OnUpdateResourceeditor(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bWEditResIsInstalled);
}
void CQuincyApp::OnFileOpen()
{
static char BASED_CODE szFilter[] =
"Quincy files (*.cpp,*.c,*.h,*.prj,*.rc)"
"|*.cpp; *.c; *.h; *.prj; *.rc|"
"All files (*.*)"
"|*.*|"
"|";
CFileDialog dlg(true,
0,
0,
OFN_HIDEREADONLY |
OFN_FILEMUSTEXIST |
OFN_NOCHANGEDIR |
OFN_PATHMUSTEXIST,
szFilter,
m_pMainWnd
);
if (dlg.DoModal() == IDOK)
OpenDocumentFile(dlg.GetPathName());
}
void CQuincyApp::SetMenuCommand(int id)
{
CMenu* pCMenu = ((CMainFrame*)(m_pMainWnd))->GetMenu();
pCMenu->CheckMenuItem(id, MF_CHECKED);
}
void CQuincyApp::ResetMenuCommand(int id)
{
CMenu* pCMenu = ((CMainFrame*)(m_pMainWnd))->GetMenu();
pCMenu->CheckMenuItem(id, MF_UNCHECKED);
}
void CQuincyApp::OnFilePrintSetup()
{
CQuincyPrintDialog pd(true);
pd.printlinenumbers = m_bPrintLineNos;
if (DoPrintDialog(&pd) == IDOK)
m_bPrintLineNos = pd.printlinenumbers;
}
void CQuincyApp::SetBuildingCPP(bool bSet)
{
ASSERT(m_pCompiler != 0);
m_pCompiler->SetBuildingCPP(bSet == true);
}
bool CQuincyApp::CompileRunning() const
{
return m_pCompiler == 0 ? false : m_pCompiler->CompileRunning();
}
void CQuincyApp::CreateGdbConsole()
{
ASSERT(m_pdlgGdbConsole != 0);
if (m_bGdbConsoleCreated != true) {
m_pdlgGdbConsole->Create(IDD_GDBCONSOLE);
m_bGdbConsoleCreated = true;
}
}
void CQuincyApp::OnViewGdbconsole()
{
CreateGdbConsole();
m_pdlgGdbConsole->ShowWindow(SW_SHOW);
m_pdlgGdbConsole->SetFocus();
}
void CQuincyApp::DisplayGdbText(char* txt)
{
if (m_pdlgGdbConsole != 0) {
if (m_bGdbConsoleCreated) {
char* cp = txt;
while (*cp) {
if (*cp == '\t')
*cp = ' ';
cp++;
}
if (!appendnexttext)
m_pdlgGdbConsole->AddString(txt);
else {
m_pdlgGdbConsole->AppendString(" ");
m_pdlgGdbConsole->AppendString(txt);
appendnexttext = false;
}
}
}
}
void CQuincyApp::ClearGdbConsole()
{
if (m_pdlgGdbConsole != 0)
if (m_bGdbConsoleCreated)
m_pdlgGdbConsole->ClearConsole();
}
// --- put quotes around a file specification that has one or more spaces
// so the file specification can be used on a command line
CString CQuincyApp::Enquote(const CString& str) const
{
if (str[0] == '"' || str.Find(' ') == -1)
return str; // file spec is already quoted or has no spaces
CString qstr("\"" + str);
// if the spec ends with backslash, add another backslash
if (qstr[qstr.GetLength()-1] == '\\')
qstr += "\\";
qstr += "\"";
return qstr;
}
bool CQuincyApp::SelectFolder(const char* title, CString* strpath)
{
bool rtn = false;
std::string ttl("Select Folder for ");
ttl += title;
BROWSEINFO info = {
0,
0,
0,
ttl.c_str(),
BIF_EDITBOX,
0,
0
};
LPITEMIDLIST idlist;
idlist = SHBrowseForFolder(&info);
if (idlist != 0) {
char path[MAX_PATH];
if (SHGetPathFromIDList(idlist, path)) {
*strpath = path;
rtn = true;
}
}
IMalloc* im = 0;
if (SUCCEEDED(SHGetMalloc(&im))) {
im->Free(idlist);
im->Release();
}
return rtn;
}
void CQuincyApp::HtmlHelp(char* htmfile, int name)
{
CString help(theApp.QuincyHtmlPath() + htmfile+".htm");
char path[MAX_PATH];
int rtn = reinterpret_cast<int>(FindExecutable(help.GetBuffer(0), 0, path));
CString exe(path);
exe += " ";
exe += help;
CString exep;
if (name)
exep.Format("%s#%02d", exe.GetBuffer(0), name);
else
exep = exe;
if (rtn > 32) {
STARTUPINFO su = {sizeof(STARTUPINFO)};
PROCESS_INFORMATION pi;
CreateProcess(
0,
exep.GetBuffer(0),
0,
0,
FALSE,
CREATE_NEW_PROCESS_GROUP,
0,
0,
&su,
&pi);
}
else
ShellExecute(0, "open", help.GetBuffer(0), 0, 0, SW_SHOW);
}
void CQuincyApp::OnUpdateProperties(CCmdUI* pCmdUI)
{
pCmdUI->Enable(IsProjectFileLoaded());
}
void CQuincyApp::OnProperties()
{
CQuincyDoc* pDoc = GetProjectDocument();
if (pDoc != 0)
pDoc->DoOnProperties();
}
void CQuincyApp::CloseErrorLog()
{
if (m_pCompiler != 0)
m_pCompiler->CloseErrorLog();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -