📄 resorgapp.cpp
字号:
// Check again later...
bResult = TRUE;
}
}
return bResult;
}
/******************************************************************************
* Destroy the splash window if a keypress or mouse button event is detected
*
******************************************************************************/
BOOL CResOrgApp::PreTranslateMessage(MSG* pMsg)
{
BOOL bResult = CResOrgApp_BASE::PreTranslateMessage(pMsg);
if ( (NULL != m_pwndSplash) &&
(NULL != m_pwndSplash->GetSafeHwnd()) &&
(WM_KEYDOWN == pMsg->message ||
WM_SYSKEYDOWN == pMsg->message ||
WM_LBUTTONDOWN == pMsg->message ||
WM_RBUTTONDOWN == pMsg->message ||
WM_MBUTTONDOWN == pMsg->message ||
WM_NCLBUTTONDOWN == pMsg->message ||
WM_NCRBUTTONDOWN == pMsg->message ||
WM_NCMBUTTONDOWN == pMsg->message ))
{
KillSplashWnd();
}
return bResult;
}
void CResOrgApp::WinHelp(DWORD dwData, UINT nCmd)
{
if (m_bHelpMode)
{
CWnd* pMainWnd = AfxGetMainWnd();
ASSERT_VALID(pMainWnd);
// return global app help mode state to FALSE (backward compatibility)
m_bHelpMode = FALSE;
pMainWnd->PostMessage(WM_KICKIDLE); // trigger idle update
pMainWnd->WinHelp(dwData, HELP_CONTEXTPOPUP);
}
else
{
CResOrgApp_BASE::WinHelp(dwData, nCmd);
}
}
int CResOrgApp::ExitInstance(void)
{
// If a version check is running, Wait until it finishes
// before exiting (by now the main window has gone)
Options.OnExit();
int nResult = CResOrgApp_BASE::ExitInstance();
if (NULL != m_plistRecentWorkspaces)
{
// Write the workspace MRU list back to the registry
m_plistRecentWorkspaces->WriteList();
}
return nResult;
}
/////////////////////////////////////////////////////////////////////////////
// CResOrgApp operations
BOOL CResOrgApp::OpenWorkspace(const CString& sPathName)
{
if (DoCloseAllWindowsQuery() && m_pProjectsDoc->OnOpenDocument(sPathName) )
{
AddToRecentWorkspacesList(sPathName);
CMainFrame* pMainFrame = (CMainFrame*)m_pMainWnd;
pMainFrame->ShowWorkspace(TRUE);
m_pProjectsDoc->UpdateAllViews(NULL, SHOW_WORKSPACE);
return TRUE;
}
return FALSE;
}
BOOL CResOrgApp::CloseWorkspace(void)
{
if (DoCloseAllWindowsQuery() )
{
CMainFrame* pMainFrame = (CMainFrame*)m_pMainWnd;
pMainFrame->ShowWorkspace(FALSE);
m_pProjectsDoc->UpdateAllViews(NULL, CLEAR_WORKSPACE);
m_pProjectsDoc->DeleteContents();
}
return TRUE;
}
BOOL CResOrgApp::CloseOpenDocuments(void)
{
BOOL bResult = TRUE;
CNGDocEnumerator docs;
CDocument* pDoc = NULL;
do
{
pDoc = docs.GetNextDoc();
if (NULL != pDoc)
{
if (pDoc->SaveModified() )
{
pDoc->OnCloseDocument();
}
else
{
bResult = FALSE;
break;
}
}
} while (NULL != pDoc);
if (NULL != m_pHtmlDocTemplate)
{
POSITION pos = m_pHtmlDocTemplate->GetFirstDocPosition();
while (NULL != pos)
{
CDocument* pDoc = m_pHtmlDocTemplate->GetNextDoc(pos);
if (NULL != pDoc)
{
pDoc->OnCloseDocument();
}
}
}
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
// CResOrgApp implementation
void CResOrgApp::AddToRecentWorkspacesList(LPCTSTR lpszPathName)
{
ASSERT_VALID(this);
ASSERT(lpszPathName != NULL);
ASSERT(AfxIsValidString(lpszPathName));
if (NULL != m_plistRecentWorkspaces)
{
m_plistRecentWorkspaces->Add(lpszPathName);
}
}
int CResOrgApp::DoCloseAllWindowsQuery(void)
{
BOOL bResult = FALSE;
int nOpenDocs = m_pDocManager->GetOpenDocumentCount();
if (nOpenDocs > 0)
{
CString sMsg = _T("Do you want to close all open windows?");
int eResult = ::AfxMessageBox( sMsg,
MB_ICONEXCLAMATION | MB_YESNOCANCEL | MB_DEFBUTTON1);
switch (eResult)
{
case IDYES:
CloseOpenDocuments();
bResult = TRUE;
break;
case IDNO:
bResult = TRUE;
break;
case IDCANCEL:
break;
}
}
else
{
bResult = TRUE;
}
return bResult;
}
/******************************************************************************
* Destroy the splash window
*
******************************************************************************/
void CResOrgApp::KillSplashWnd(void)
{
if ( (NULL != m_pwndSplash) && (NULL != m_pwndSplash->GetSafeHwnd()) )
{
m_pwndSplash->DestroyWindow();
delete m_pwndSplash;
m_pwndSplash = NULL;
m_pMainWnd->UpdateWindow();
}
}
/******************************************************************************
* Create the splash screen
*
******************************************************************************/
void CResOrgApp::ShowSplashScreen(void)
{
m_pwndSplash = new CResOrgSplashWnd;
if (!m_pMainWnd->IsIconic() && m_pwndSplash->Create(m_pMainWnd))
{
m_pwndSplash->ShowWindow(SW_SHOW);
m_pwndSplash->UpdateWindow();
}
m_dwSplashTime = ::GetTickCount();
m_pMainWnd->UpdateWindow();
}
void CResOrgApp::OpenHtmlView( const CString& sTitle,
const CString& sURL)
{
ASSERT(NULL != m_pHtmlDocTemplate);
if (NULL != m_pHtmlDocTemplate)
{
CDocument* pDoc = m_pHtmlDocTemplate->CreateNewDocument();
if (pDoc != NULL)
{
pDoc->SetTitle(sTitle);
CFrameWnd* pFrame = m_pHtmlDocTemplate->CreateNewFrame(pDoc, NULL);
if (pFrame == NULL)
{
TRACE0("Warning: failed to create new frame.\n");
AfxMessageBox(AFX_IDP_COMMAND_FAILURE, MB_OK | MB_ICONSTOP);
return; // command failed
}
m_pHtmlDocTemplate->InitialUpdateFrame(pFrame, pDoc);
CView* pView = pFrame->GetActiveView();
if (NULL != pView)
{
((CHtmlView*)pView)->Navigate2(sURL, 0);
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CResOrgApp message handlers
void CResOrgApp::OnCmdOpenWorkspace(void)
{
// Browse for the workspace (.dsw) file
BXFileDialog dlg( TRUE, // Open
FALSE, // No preview
TRUE, // Resizeable
_T(".dsw"), // Default extension
NULL, // Default filename
OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST, // Flags
_T("Project workspaces (*.dsw)|*.dsw||"), // File filter
AfxGetMainWnd() ); // Parent window
if (IDOK == dlg.DoModal() )
{
// Open and parse it (via the document)
CString sPathName = dlg.GetPathName();
OpenWorkspace(sPathName);
}
}
void CResOrgApp::OnCmdCloseWorkspace(void)
{
CloseWorkspace();
}
void CResOrgApp::OnUpdateCloseWorkspace(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_pProjectsDoc->IsWorkspaceOpen() );
}
BOOL CResOrgApp::OnCmdOpenRecentWorkspace(UINT nID)
{
ASSERT_VALID(this);
ASSERT(m_plistRecentWorkspaces != NULL);
ASSERT(nID >= ID_WORKSPACE_MRU_FILE1);
ASSERT(nID < ID_WORKSPACE_MRU_FILE1 + (UINT)m_plistRecentWorkspaces->GetSize());
int nIndex = nID - ID_WORKSPACE_MRU_FILE1;
if (!(*m_plistRecentWorkspaces)[nIndex].IsEmpty() )
{
TRACE2("MRU: open workspace (%d) '%s'.\n", (nIndex) + 1,
(LPCTSTR)(*m_plistRecentWorkspaces)[nIndex]);
if (!OpenWorkspace( (*m_plistRecentWorkspaces)[nIndex]) )
{
m_plistRecentWorkspaces->Remove(nIndex);
}
}
return TRUE;
}
void CResOrgApp::OnUpdateRecentWorkspaceMenu(CCmdUI* pCmdUI)
{
ASSERT_VALID(this);
BOOL bEnable = FALSE;
// The code below adds the workspaces MRU list to the
// "Recent Workspaces" popup menu. Because the CMenu
// pointer in the CCmdUI object we've been passed is
// the root of the submenu, we need to replace it with
// the first entry in the submenu, or the entries will
// be added to the file menu itself (which causes a
// conflict in the accelerator keys assigned to the two
// MRU lists...)
if (NULL != pCmdUI->m_pMenu)
{
CMenu* pSubMenu = NULL;
pSubMenu = pCmdUI->m_pSubMenu;
/* for (UINT n = 0; n < pCmdUI->m_pMenu->GetMenuItemCount(); n++)
{
CMenu* pMenu = pCmdUI->m_pMenu->GetSubMenu(n);
if ( (NULL != pMenu) && (ID_WORKSPACE_MRU_FILE1 == pMenu->GetMenuItemID(0) ) )
{
pSubMenu = pMenu;
break;
}
}
*/
if (NULL != pSubMenu)
{
if (NULL != m_plistRecentWorkspaces)
{
int nSize = m_plistRecentWorkspaces->GetSize();
if (nSize > 0)
{
for (int i = 0; i < nSize; i++)
{
if ((*m_plistRecentWorkspaces)[i].GetLength() > 0)
{
pCmdUI->m_pMenu = pSubMenu;
m_plistRecentWorkspaces->UpdateMenu(pCmdUI);
bEnable = TRUE;
break;
}
}
}
}
if (!bEnable)
{
// No MRU workspaces - so disable entry
pSubMenu->EnableMenuItem( ID_WORKSPACE_MRU_FILE1,
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
// pCmdUI->m_pMenu->EnableMenuItem( 0,
// MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
}
}
}
void CResOrgApp::OnCmdOptions(void)
{
Options.Configure();
}
void CResOrgApp::OnCmdWindowCloseAll(void)
{
CloseOpenDocuments();
}
void CResOrgApp::OnUpdateWindowCloseAll(CCmdUI* pCmdUI)
{
int nOpenDocs = m_pDocManager->GetOpenDocumentCount();
if (0 == nOpenDocs)
{
POSITION pos = m_pHtmlDocTemplate->GetFirstDocPosition();
if (NULL != pos)
{
if (NULL != m_pHtmlDocTemplate->GetNextDoc(pos) )
{
nOpenDocs++; // Force command to be available
}
}
}
pCmdUI->Enable(nOpenDocs > 0);
}
void CResOrgApp::OnCmdResOrgWebsite(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_WEB_TITLE);
OpenHtmlView(sTitle, Options.GetWebURL() );
}
void CResOrgApp::OnCmdResOrgFAQ(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_FAQ_TITLE);
OpenHtmlView(sTitle, Options.GetFaqURL() );
}
void CResOrgApp::OnUpdateResOrgFAQ(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetFaqURL().IsEmpty() );
}
void CResOrgApp::OnCmdResOrgDiscussionBoard(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_DISCUSSIONS_TITLE);
OpenHtmlView(sTitle, Options.GetDiscussionBoardURL() );
}
void CResOrgApp::OnUpdateResOrgDiscussionBoard(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetDiscussionBoardURL().IsEmpty() );
}
void CResOrgApp::OnCmdResOrgKnownBugs(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_KNOWN_BUGS_TITLE);
OpenHtmlView(sTitle, Options.GetKnownBugsURL() );
}
void CResOrgApp::OnUpdateResOrgKnownBugs(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetKnownBugsURL().IsEmpty() );
}
void CResOrgApp::OnCmdResOrgMailingList(void)
{
CString sTitle;
sTitle.LoadString(IDP_RESORG_MAILING_LIST);
OpenHtmlView(sTitle, Options.GetMailingListURL() );
}
void CResOrgApp::OnUpdateResOrgMailingList(CCmdUI* pCmdUI)
{
pCmdUI->Enable( !Options.GetMailingListURL().IsEmpty() );
}
void CResOrgApp::OnCmdResOrgUpdateCheckCompleted(void)
{
Options.OnVersionCheckCompleted();
}
// App command to run the dialog
void CResOrgApp::OnCmdAbout(void)
{
CResOrgAboutBox aboutDlg;
aboutDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -