📄 quincy.cpp
字号:
{
if (m_bBypassChangeTest)
return false;
POSITION tpos = GetFirstDocTemplatePosition();
while (tpos != 0) {
CDocTemplate* pTem = GetNextDocTemplate(tpos);
ASSERT(pTem != 0);
POSITION dpos = pTem->GetFirstDocPosition();
while (dpos != 0) {
CTextDocument* pDoc = static_cast<CTextDocument*>(pTem->GetNextDoc(dpos));
ASSERT(pDoc != 0);
CString strDocFile = GetFileName(pDoc->GetPathName());
if (strDocFile.Right(4).CompareNoCase(".prj") != 0) {
if (pDoc->IsModified()) {
if (AfxMessageBox("Program has changed. Continue?", MB_ICONQUESTION | MB_YESNO) == IDNO) {
OnStop();
return true;
}
m_bBypassChangeTest = true;
break;
}
}
}
}
return false;
}
bool CQuincyApp::IsProjectFileLoaded()
{
POSITION tpos = GetFirstDocTemplatePosition();
while (tpos != 0) {
CDocTemplate* pTem = GetNextDocTemplate(tpos);
ASSERT(pTem != 0);
POSITION dpos = pTem->GetFirstDocPosition();
while (dpos != 0) {
CQuincyDoc* pDoc = dynamic_cast<CQuincyDoc*>(pTem->GetNextDoc(dpos));
if (pDoc != 0)
return true;
/*
CTextDocument* pDoc = static_cast<CTextDocument*>(pTem->GetNextDoc(dpos));
ASSERT(pDoc != 0);
CString strDocFile = GetFileName(pDoc->GetPathName());
if (strDocFile.Right(4).CompareNoCase(".prj") == 0)
return true;
*/
}
}
return false;
}
void CQuincyApp::OnStop()
{
if (m_pCompiler && m_pCompiler->CompileRunning())
m_pCompiler->Stop();
else if (m_pDebugger != 0)
m_pDebugger->Stop();
else if (m_pGrep != 0)
m_pGrep->Stop();
}
void CQuincyApp::OnGrep()
{
if (m_pGrep == 0)
m_pGrep = new Grep;
m_pGrep->OnGrep();
}
#define markup(x,y) \
{ \
if (x!=y) { \
x=y; \
if (pDoc) \
pDoc->SetModifiedFlag(); \
} \
}
static bool TestChanged(const CStringArray& a1, const CStringArray& a2)
{
if (a1.GetSize() != a2.GetSize())
return true;
for (int i = 0; i < a1.GetSize(); i++)
if (a1.GetAt(i) != a2.GetAt(i))
return true;
return false;
}
void CQuincyApp::OnOptions()
{
CBuildDialog dlgBuild;
GetArray(dlgBuild.m_strDefine, m_Defines);
GetArray(dlgBuild.m_strInclude, m_Includes);
dlgBuild.m_bDebugging = m_bDebugging;
dlgBuild.m_bExceptions = m_bExceptions;
dlgBuild.m_bRTTI = m_bRTTI;
dlgBuild.m_bStrict = m_bStrict;
dlgBuild.m_nOptimize = m_nOptimize;
GetArray(dlgBuild.m_strLib, m_Libs);
dlgBuild.m_strCmdLineOptions = m_strCmdLineOptions;
dlgBuild.m_strCompiler = m_strCompiler;
CRunOptions dlgRun;
dlgRun.m_CommandLinePromptOption = m_CommandLinePromptOption;
dlgRun.m_strCommandLine = m_strCommandLine;
dlgRun.m_strRuntimeDirectory = m_strRuntimeDirectory;
CEditorOptions dlgEditor;
dlgEditor.m_nTabstops = m_tabstops;
dlgEditor.m_taboption = m_taboption;
dlgEditor.m_nMaxundos = m_maxundos;
dlgEditor.m_AutoIndent = m_bAutoindent;
dlgEditor.m_SyntaxColors = m_bSyntaxColors;
dlgEditor.m_backgroundcolor = m_backgroundcolor;
dlgEditor.m_normalcolor = m_normalcolor;
dlgEditor.m_commentcolor = m_commentcolor;
dlgEditor.m_stringcolor = m_stringcolor;
dlgEditor.m_keywordcolor = m_keywordcolor;
static int activeindex = 0;
COptionsSheet dlgOptions("Options", 0, activeindex);
dlgOptions.m_psh.dwFlags |= PSH_NOAPPLYNOW;
dlgOptions.AddPage(&dlgBuild);
dlgOptions.AddPage(&dlgRun);
dlgOptions.AddPage(&dlgEditor);
if (dlgOptions.DoModal() == IDOK) {
bool modifydoc = false;
if (m_tabstops != dlgEditor.m_nTabstops) {
RetabAllTextDocuments(dlgEditor.m_nTabstops);
m_tabstops = dlgEditor.m_nTabstops;
InvalidateAllViews();
}
m_maxundos = dlgEditor.m_nMaxundos;
if (m_bSyntaxColors != (bool) dlgEditor.m_SyntaxColors ||
m_backgroundcolor != dlgEditor.m_backgroundcolor ||
m_normalcolor != dlgEditor.m_normalcolor ||
m_commentcolor != dlgEditor.m_commentcolor ||
m_stringcolor != dlgEditor.m_stringcolor ||
m_keywordcolor != dlgEditor.m_keywordcolor) {
m_bSyntaxColors = dlgEditor.m_SyntaxColors;
m_backgroundcolor = dlgEditor.m_backgroundcolor;
m_normalcolor = dlgEditor.m_normalcolor;
m_commentcolor = dlgEditor.m_commentcolor;
m_stringcolor = dlgEditor.m_stringcolor;
m_keywordcolor = dlgEditor.m_keywordcolor;
InvalidateAllViews();
}
if (m_fontheight |= dlgEditor.m_SampleCode.m_fontheight) {
m_fontheight = dlgEditor.m_SampleCode.m_fontheight;
m_fontwidth = dlgEditor.m_SampleCode.m_fontwidth;
InvalidateAllViews(true);
}
if (m_fontweight |= dlgEditor.m_SampleCode.m_fontweight) {
m_fontweight = dlgEditor.m_SampleCode.m_fontweight;
InvalidateAllViews(true);
}
m_bAutoindent = dlgEditor.m_AutoIndent;
m_taboption = dlgEditor.m_taboption;
// ---- these are items serialized with the project document
CQuincyDoc* pDoc = GetProjectDocument();
markup(m_nOptimize,dlgBuild.m_nOptimize);
markup(m_strCmdLineOptions,dlgBuild.m_strCmdLineOptions);
markup(m_CommandLinePromptOption,dlgRun.m_CommandLinePromptOption);
markup(m_strCommandLine,dlgRun.m_strCommandLine);
markup(m_strRuntimeDirectory,dlgRun.m_strRuntimeDirectory);
if (!m_strRuntimeDirectory.IsEmpty() && m_strRuntimeDirectory[m_strRuntimeDirectory.GetLength()-1] != '\\')
m_strRuntimeDirectory += '\\';
markup(m_bDebugging,dlgBuild.m_bDebugging);
markup(m_bExceptions,dlgBuild.m_bExceptions);
markup(m_bRTTI,dlgBuild.m_bRTTI);
markup(m_bStrict,dlgBuild.m_bStrict);
CStringArray array;
LoadArray(array, dlgBuild.m_strDefine);
modifydoc |= TestChanged(array, m_Defines);
LoadArray(array, dlgBuild.m_strInclude);
modifydoc |= TestChanged(array, m_Includes);
LoadArray(array, dlgBuild.m_strLib);
modifydoc |= TestChanged(array, m_Libs);
LoadArray(m_Defines, dlgBuild.m_strDefine);
LoadArray(m_Includes, dlgBuild.m_strInclude);
LoadArray(m_Libs, dlgBuild.m_strLib);
if (modifydoc && pDoc)
pDoc->SetModifiedFlag();
if (m_strCompiler != dlgBuild.m_strCompiler) {
m_strCompiler = dlgBuild.m_strCompiler;
int len = m_strCompiler.GetLength();
if (len && m_strCompiler[len-1] != '\\')
m_strCompiler += '\\';
SetCompilerPaths();
}
/*
if (m_strDebugger != dlgBuild.m_strDebugger) {
m_strDebugger = dlgBuild.m_strDebugger;
int len = m_strDebugger.GetLength();
if (len && m_strDebugger[len-1] != '\\')
m_strDebugger += '\\';
TestDebuggerPath();
}
*/
}
activeindex = dlgOptions.m_activeindex;
}
// load an array of option strings from an option string ("option1;option2;...)
void CQuincyApp::LoadArray(CStringArray& array, const CString& rstr)
{
int len = rstr.GetLength();
char ch = ' ';
CString str;
array.RemoveAll(); // start with an empty array
for (int i = 0; i < len; i++) { // skip leading spaces
if (rstr[i] == ' ')
continue;
while (i < len) { // iterate the input string
ch = rstr[i]; // one char at a time
// --- option terminates with ';' or at end of string
if (ch == ';' || i == len-1) {
if (ch != ';')
str += ch;
if (!str.IsEmpty()) {
array.Add(str);
str.Empty();
}
break;
}
else
str += ch; // build option string
i++;
}
}
}
// make an options string ("option1;option2;...) from an array of option strings
void CQuincyApp::GetArray(CString& atr, const CStringArray& array) const
{
int len = array.GetSize();
atr = "";
for (int i = 0; i < len; i++) {
atr += array[i];
if (i < len-1)
atr += ";";
}
}
BOOL CQuincyApp::FirstInstance()
{
CWnd *pWndPrev, *pWndChild;
// Determine if another window with our class name exists...
if (pWndPrev = CWnd::FindWindow(_T("QuincyAppClass"),NULL))
{
// if so, does it have any popups?
pWndChild = pWndPrev->GetLastActivePopup();
// If iconic, restore the main window
if (pWndPrev->IsIconic())
pWndPrev->ShowWindow(SW_RESTORE);
// Bring the main window or its popup to
// the foreground
pWndChild->SetForegroundWindow();
// and we are done activating the previous one.
return FALSE;
}
// First instance. Proceed as normal.
else
return TRUE;
}
int CQuincyApp::ExitInstance()
{
m_bWatchCreated = false;
WriteProfileInt("Options", "AutoIndent", m_bAutoindent);
WriteProfileInt("Options", "Syntax Colors", m_bSyntaxColors);
WriteProfileInt("Options", "Background Color", m_backgroundcolor);
WriteProfileInt("Options", "Normal Color", m_normalcolor);
WriteProfileInt("Options", "Keyword Color", m_keywordcolor);
WriteProfileInt("Options", "Comment Color", m_commentcolor);
WriteProfileInt("Options", "String Color", m_stringcolor);
WriteProfileInt("Options", "Font Height", m_fontheight);
WriteProfileInt("Options", "Font Width", m_fontwidth);
// WriteProfileString("Options", "Font Face", m_fontface);
WriteProfileInt("Options", "Font Weight", m_fontweight);
WriteProfileInt("Options", "Print Line Numbers", m_bPrintLineNos);
WriteProfileInt("Options", "Tab Stops", m_tabstops);
WriteProfileInt("Options", "Tabs", m_taboption);
WriteProfileInt("Options", "Max Undos", m_maxundos);
WriteProfileInt("Options", "Debugging", m_bDebugging);
WriteProfileInt("Options", "Exceptions", m_bExceptions);
WriteProfileInt("Options", "RTTI", m_bRTTI);
WriteProfileInt("Options", "Strict", m_bStrict);
WriteProfileInt("Options", "Command Line Prompt", m_CommandLinePromptOption);
WriteProfileInt("Options", "Optimize", m_nOptimize);
WriteProfileString("Options", "Command Line", m_strCommandLine);
WriteProfileString("Options", "Compiler Command Line Options", m_strCmdLineOptions);
WriteProfileInt("Options", "Style", m_style);
WriteProfileString("Options", "Command", m_command);
#ifdef TYCPP
WriteProfileInt("Tutorial", "Displayed", m_bTutorialDisplayed );
WriteProfileString("Tutorial", "Current", m_strTutorial);
#endif
WriteProfileString("Directories", "Runtime", m_strRuntimeDirectory);
WriteProfileString("Directories", "Compiler", m_strCompiler);
WriteProfileString("Directories", "Debugger", m_strDebugger);
CString strBuffer;
strBuffer.Format ("%i:%i:%i:%i",
m_ConsoleRect.left,
m_ConsoleRect.top,
m_ConsoleRect.right,
m_ConsoleRect.bottom);
AfxGetApp ()->WriteProfileString ("Settings", "Console Position", strBuffer);
char path[MAX_PATH];
_getcwd(path, MAX_PATH);
WriteProfileString("Directories", "Current", path);
if(bClassRegistered)
::UnregisterClass(_T("QuincyAppClass"),AfxGetInstanceHandle());
return CWinApp::ExitInstance();
}
bool CQuincyApp::SelectFileAndLine(const CString& strFile, int nline)
{
if (!strFile.IsEmpty()) {
CDocument* pDoc = OpenDocumentFile(strFile);
if (pDoc != 0) { // (user could delete the source code file before reading it)
// ---- change focus to the selected document file
POSITION dpos = pDoc->GetFirstViewPosition();
ASSERT(dpos != 0);
CEditorView* pView = static_cast<CEditorView*>(pDoc->GetNextView(dpos));
ASSERT(pView != 0);
pView->SetFocus();
pView->UpdateWindow();
pView->Invalidate();
if (nline != 0) {
// ---- position text so that the specified line is current
pView->SetLineColumn(nline, 1);
ShowLineColumn(nline, 1);
}
return true;
}
}
return false;
}
void CQuincyApp::SelectErrorLine(int nsel)
{
if (nsel != -1 && m_pCompiler != 0) {
CString strFile;
int line;
if (m_pCompiler->GetMessageData(nsel, strFile, line))
SelectFileAndLine(strFile, line);
}
}
void CQuincyApp::SelectGrepLine(int nsel)
{
if (m_pGrep != 0)
m_pGrep->SelectGrepLine(nsel);
}
void CQuincyApp::OnUpdateStop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(
CompileRunning() ||
(m_pGrep != 0 && m_pGrep->IsRunning()) ||
(m_pDebugger != 0) // && m_pDebugger->CanStop())
);
}
void CQuincyApp::SaveAllDocuments(bool prompt)
{
POSITION tpos = GetFirstDocTemplatePosition();
while (tpos != 0) {
CDocTemplate* pTem = GetNextDocTemplate(tpos);
ASSERT(pTem != 0);
POSITION dpos = pTem->GetFirstDocPosition();
while (dpos != 0) {
CDocument* pDoc = pTem->GetNextDoc(dpos);
ASSERT(pDoc != 0);
if (pDoc->IsModified()) {
const CString& strPath = pDoc->GetPathName();
if (!strPath.IsEmpty()) {
if (prompt) {
CString msg("Save ");
msg += GetFileName(strPath) + "?";
if (AfxMessageBox(msg, MB_YESNO | MB_ICONQUESTION) != IDYES)
continue;
}
pDoc->OnSaveDocument(strPath);
pDoc->SetModifiedFlag(false);
}
}
}
}
}
void CQuincyApp::SaveOpenDocuments()
{
POSITION tpos = GetFirstDocTemplatePosition();
int nDocno = 0;
CString strProfile;
while (tpos != 0 && nDocno < maxsaveddocuments) {
CDocTemplate* pTem = GetNextDocTemplate(tpos);
ASSERT(pTem != 0);
POSITION dpos = pTem->GetFirstDocPosition();
while (dpos != 0) {
CQuincyDoc* pDoc = static_cast<CQuincyDoc*>(pTem->GetNextDoc(dpos));
ASSERT(pDoc != 0);
CString strPath = pDoc->GetPathName();
strProfile.Format("Document%d", ++nDocno);
WriteProfileString("Documents", strProfile, strPath);
CTextView* pView = GetTextView(strPath);
ASSERT(pView != 0);
CWnd* pWnd = pView->GetParent();
ASSERT(pWnd != 0);
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
if (pWnd->GetWindowPlacement(&wndpl)) {
strProfile.Format("Document%d Maximized", nDocno);
WriteProfileInt("Documents", strProfile,
wndpl.showCmd == SW_SHOWMAXIMIZED);
}
}
}
while (nDocno < maxsaveddocuments) {
strProfile.Format("Document%d", ++nDocno);
WriteProfileString("Documents", strProfile, 0);
strProfile.Format("Document%d Maximized", nDocno);
WriteProfileString("Documents", strProfile, 0);
}
}
void CQuincyApp::SaveDialogWindowPosition(const CString& strWindow, CWnd* pWnd)
{
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
if (pWnd->m_hWnd != 0 && pWnd->GetWindowPlacement(&wndpl)) {
RECT rc = wndpl.rcNormalPosition;
WriteProfileInt(strWindow, "Left", rc.left);
WriteProfileInt(strWindow, "Top", rc.top);
}
}
void CQuincyApp::RestoreDialogWindowPosition(const CString& strWindow, CWnd* pWnd)
{
WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
if (pWnd->m_hWnd != 0) {
pWnd->GetWindowPlacement(&wndpl);
int wd = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left;
int ht = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top;
wndpl.rcNormalPosition.left =
GetProfileInt(strWindow, "Left", wndpl.rcNormalPosition.left);
wndpl.rcNormalPosition.top =
GetProfileInt(strWindow, "Top", wndpl.rcNormalPosition.top);
wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + wd;
wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + ht;
pWnd->SetWindowPlacement(&wndpl);
}
}
// ------- permit clearing all the breakpoints
void CQuincyApp::OnUpdateDebugClearbreakpoints(CCmdUI* pCmdUI)
{
pCmdUI->Enable(breakpoints.size() > 0);
}
// ------- clear all the breakpoints
void CQuincyApp::OnDebugClearbreakpoints()
{
breakpoints.clear();
InvalidateAllViews();
}
void CQuincyApp::BringToTop()
{
ASSERT(m_pMainWnd != 0);
m_pMainWnd->SetForegroundWindow();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -