📄 view.cpp
字号:
// Get the URL and open it in the web browser
CPoint pt;
UINT uFlags = TVHT_ONITEMLABEL;
CString strText;
GetCursorPos(&pt);
m_Tree.ScreenToClient(&pt);
HTREEITEM htreeItem = m_Tree.HitTest(pt,&uFlags);
// Make sure it's not just a category entry that the user clicked on
if(htreeItem && htreeItem != m_htreeRoot && htreeItem != m_htreeContents &&
htreeItem != m_htreeMedia && htreeItem != m_htreePages)
{
// It's a valid file so get its name
strText = m_Tree.GetItemText(htreeItem);
int nIndex = strText.ReverseFind('(');
if(nIndex >= 0)
{
strText = strText.Mid(nIndex+1);
strText = strText.Left(strText.GetLength()-1);
}
CSnaggerDoc *pDoc = GetDocument();
// Don't pre-pend the path for an EMAIL entry
if(strText.Left(7) != "mailto:")
strText = pDoc->GetDirectory()+strText;
// Let the shell invoke the proper handler for this file
ShellExecute(NULL,"open",strText,NULL,NULL,SW_SHOWNORMAL);
*pResult = 1;
}
else *pResult = 0;
}
void CSnaggerView::OnFileOptions()
{
CSnaggerDoc* pDoc = GetDocument();
COptionsDlg cOptions(pDoc->GetOptions());
if(cOptions.DoModal() == IDOK)
{
pDoc->SetModifiedFlag(TRUE);
}
}
void CSnaggerView::OnUpdateFileOptions(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CSnaggerView::OnSnag()
{
CSnaggerDoc *pDoc = GetDocument();
if(!TreeIsEmpty())
{
if(AfxMessageBox("The current project already contains a site. If you continue it will be replaced.\nContinue?",
MB_YESNO|MB_ICONQUESTION) != IDYES)
return;
CString strPath = CInet::SplitFileName(pDoc->GetPathName(),
CInet::DRIVE|CInet::PATH|CInet::FNAME)+"\\";
ClearProject(strPath);
pDoc->SetModifiedFlag(TRUE);
}
// Get the URL associated with this document
CURLDlg dlgURL;
dlgURL.SetMaxLevels(pDoc->GetOptions()->nMaxDepth);
dlgURL.SetMaxPages(pDoc->GetOptions()->nMaxPages);
dlgURL.SetGetMultimedia(pDoc->GetOptions()->bMultimedia);
dlgURL.SetURL(pDoc->GetStartPage());
if(dlgURL.DoModal() == IDOK)
{
CString strURL = dlgURL.GetURL();
// validate the URL here!!!
InitTree(strURL);
pDoc->SetModifiedFlag(TRUE);
pDoc->RecursiveDownload(strURL);
m_bSnagging = TRUE;
}
}
void CSnaggerView::OnUpdateSnag(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CSnaggerView::OnStop()
{
CSnaggerDoc* pDoc = GetDocument();
pDoc->SetAutoMode(FALSE);
StartWait("Stopping, Please Wait (this may take a little time).");
m_pProgress->SetAborted(TRUE);
}
void CSnaggerView::OnUpdateStop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bSnagging);
}
void CSnaggerView::ClearProject(LPCTSTR lpszDir)
{
CString strTemp = lpszDir+CString("*.*");
WIN32_FIND_DATA findData;
HANDLE hFind = FindFirstFile(strTemp,&findData);
if(hFind)
{
while(TRUE)
{
strTemp = CString(lpszDir)+findData.cFileName;
remove(strTemp);
if(!FindNextFile(hFind,&findData))
break;
}
FindClose(hFind);
}
}
LRESULT CSnaggerView::OnShowPrompt(WPARAM wParam, LPARAM lParam)
{
return AfxMessageBox(wParam,lParam);
}
int CSnaggerView::ShowPrompt(int nID, int nOptions)
{
return(SendMessage(UM_SHOW_PROMPT,nID,nOptions));
}
void CSnaggerView::OnFileRemoveall()
{
if(AfxMessageBox("You have chosen to remove all the files for this project.\nAre you sure?",
MB_ICONQUESTION|MB_YESNOCANCEL) == IDYES)
{
CSnaggerDoc* pDoc = GetDocument();
CString strPath = CInet::SplitFileName(pDoc->GetPathName(),
CInet::DRIVE|CInet::PATH|CInet::FNAME)+"\\";
ClearProject(strPath);
rmdir(strPath);
ClearTree();
strPath = CInet::SplitFileName(pDoc->GetPathName(),
CInet::DRIVE|CInet::PATH|CInet::FNAME|CInet::EXT);
pDoc->Reset();
remove(strPath);
// Remove the project's entry in the MRU list
CSnaggerApp *pApp = (CSnaggerApp *) AfxGetApp();
CRecentFileList *pMRUList = pApp->GetMRUList();
pMRUList->Remove(0);
}
}
void CSnaggerView::OnUpdateFileRemoveall(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CSnaggerView::OnUpdateAppExit(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(!m_bSnagging);
}
void CSnaggerView::OnUpdateFileNew(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(!m_bSnagging);
}
void CSnaggerView::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(!m_bSnagging);
}
void CSnaggerView::OnUpdateFileSave(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CSnaggerView::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CSnaggerView::OnFileNew()
{
CSnaggerDoc* pDoc = GetDocument();
// Display the Create Project dialogbox
CProjectDlg dlgProject;
// Did the user press OK?
if(dlgProject.DoModal() == IDOK)
{
CString strTestName = g_strProjDir+dlgProject.GetProjectName()+CString(".sng");
// Does this project already exist?
if(access(strTestName,0) == 0)
{
// Yes, ask the user whether it's okay to replace it
if(AfxMessageBox("A project already exists with this name do you want to replace it?",
MB_ICONQUESTION|MB_YESNOCANCEL) != IDYES)
return;
}
// Make sure we save the current project
pDoc->SaveModified();
// Get the new project name and create the project file and the
// new subdirectory
CString strPathName = g_strProjDir+dlgProject.GetProjectName()+CString(".sng");
mkdir(g_strProjDir+dlgProject.GetProjectName());
// Initialize the tree
ClearTree();
// Create the new document
pDoc->OnNewDocument();
// Save the new document title
pDoc->SetPathName(strPathName);
pDoc->SetTitle(dlgProject.GetProjectName());
pDoc->SetModifiedFlag(TRUE);
pDoc->DoSave(strPathName);
pDoc->SetDirectory(g_strProjDir+dlgProject.GetProjectName()+
CString("\\"));
}
}
void CSnaggerView::OnFileOpen()
{
if(m_bSnagging) return;
CFileDialog fileOpen(TRUE,".sng",NULL,
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR|
OFN_NONETWORKBUTTON,"SiteSnagger projects (*.sng)|*.sng||",this);
fileOpen.m_ofn.lpstrInitialDir = g_strProjDir;
if(fileOpen.DoModal() == IDOK)
{
CSnaggerDoc* pDoc = GetDocument();
// Open the new document
pDoc->OnOpenDocument(fileOpen.GetPathName());
}
}
void CSnaggerView::OnFileRename()
{
CSnaggerDoc* pDoc = GetDocument();
// Display the Create Project dialogbox
CProjectDlg dlgProject;
CString strCurrProject = CInet::SplitFileName(pDoc->GetPathName(),
CInet::DRIVE|CInet::PATH|CInet::FNAME);
// Set the proper title
dlgProject.SetTitle("Renaming "+pDoc->GetTitle());
// Did the user press OK?
if(dlgProject.DoModal() == IDOK)
{
CString strNewProject = g_strProjDir+dlgProject.GetProjectName();
// Does this directory or project already exist?
if(access(strNewProject,0) == 0 || access(strNewProject+".sng",0) == 0)
{
// Yes, don't allow the rename
AfxMessageBox("Sorry, a project already exists with this name.",
MB_ICONWARNING|MB_OK);
}
else
{
// Remove the project's entry in the MRU list
CSnaggerApp *pApp = (CSnaggerApp *) AfxGetApp();
CRecentFileList *pMRUList = pApp->GetMRUList();
pMRUList->Remove(0);
// Rename the in-memory project
pDoc->SetTitle(dlgProject.GetProjectName()+".sng");
pDoc->SetPathName(strNewProject+".sng");
// Rename the old project on disk
rename(strCurrProject+".sng",strNewProject+".sng");
// Rename the directory
rename(strCurrProject,strNewProject);
// Make sure the new project gets saved
pDoc->SetModifiedFlag(TRUE);
}
}
}
void CSnaggerView::OnUpdateFileRename(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CSnaggerView::OnUpdateFileMRU(CCmdUI* pCmdUI)
{
// Load the most recently used file list
CSnaggerApp *pApp = (CSnaggerApp *) AfxGetApp();
pApp->UpdateMRU(pCmdUI);
// Disable the MRU entries if necessary
if(m_bSnagging)
{
for(int i = ID_FILE_MRU_FIRST; i <= ID_FILE_MRU_LAST; i++)
pCmdUI->m_pMenu->EnableMenuItem(i,
MF_DISABLED|MF_GRAYED|MF_BYCOMMAND);
}
}
void CSnaggerView::OnFileClose()
{
CSnaggerDoc* pDoc = GetDocument();
pDoc->SaveModified();
pDoc->Reset();
ClearTree();
}
void CSnaggerView::OnUpdateFileClose(CCmdUI* pCmdUI)
{
CSnaggerDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -