📄 myview.cpp
字号:
{
CMyDoc* pDoc = GetDocument();
CConfigureDlg cOptions(pDoc->GetOptions());
if(cOptions.DoModal() == IDOK)
{
pDoc->SetModifiedFlag(TRUE);
}
}
//更改网站下载的配置信息
void CMyView::OnUpdateFileOptions(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CMyView::OnSnag()
{
CMyDoc *pDoc = GetDocument();
if(!TreeIsEmpty())
{
if(AfxMessageBox("当前项目中已经有一个网站,继续将会覆盖原来的下载.\nContinue?",MB_YESNO|MB_ICONQUESTION) != IDYES)
return;
CString strPath = CInternetDownload::SplitFileName(pDoc->GetPathName(),CInternetDownload::DRIVE|CInternetDownload::PATH|CInternetDownload::FNAME)+"\\";
ClearProject(strPath);
pDoc->SetModifiedFlag(TRUE);
}
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();
InitTree(strURL);
pDoc->SetModifiedFlag(TRUE);
pDoc->RecursiveDownload(strURL);
m_bSnagging = TRUE;
}
}
void CMyView::OnUpdateSnag(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CMyView::OnStop()
{
CMyDoc* pDoc = GetDocument();
pDoc->SetAutoMode(FALSE);
}
void CMyView::OnUpdateStop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bSnagging);
}
void CMyView::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 CMyView::OnShowPrompt(WPARAM wParam, LPARAM lParam)
{
return AfxMessageBox(wParam,lParam);
}
int CMyView::ShowPrompt(int nID, int nOptions)
{
return(SendMessage(UM_SHOW_PROMPT,nID,nOptions));
}
void CMyView::OnFileRemoveall()
{
if(AfxMessageBox("You have chosen to remove all the files for this project.\nAre you sure?",
MB_ICONQUESTION|MB_YESNOCANCEL) == IDYES)
{
CMyDoc* pDoc = GetDocument();
CString strPath = CInternetDownload::SplitFileName(pDoc->GetPathName(),
CInternetDownload::DRIVE|CInternetDownload::PATH|CInternetDownload::FNAME)+"\\";
ClearProject(strPath);
rmdir(strPath);
ClearTree();
strPath = CInternetDownload::SplitFileName(pDoc->GetPathName(),
CInternetDownload::DRIVE|CInternetDownload::PATH|CInternetDownload::FNAME|CInternetDownload::EXT);
pDoc->Reset();
remove(strPath);
// Remove the project's entry in the MRU list
CSiteDownloadApp *pApp = (CSiteDownloadApp *) AfxGetApp();
CRecentFileList *pMRUList = pApp->GetMRUList();
pMRUList->Remove(0);
}
}
void CMyView::OnUpdateFileRemoveall(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CMyView::OnUpdateAppExit(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(!m_bSnagging);
}
void CMyView::OnUpdateFileNew(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(!m_bSnagging);
}
void CMyView::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(!m_bSnagging);
}
void CMyView::OnUpdateFileSave(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CMyView::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CMyView::OnFileNew()
{
CMyDoc* pDoc = GetDocument();
// Display the Create Project dialogbox
CInputProjectDlg 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 CMyView::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)
{
CMyDoc* pDoc = GetDocument();
// Open the new document
pDoc->OnOpenDocument(fileOpen.GetPathName());
}
}
void CMyView::OnFileRename()
{
CMyDoc* pDoc = GetDocument();
// Display the Create Project dialogbox
CInputProjectDlg dlgProject;
CString strCurrProject = CInternetDownload::SplitFileName(pDoc->GetPathName(),
CInternetDownload::DRIVE|CInternetDownload::PATH|CInternetDownload::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
CSiteDownloadApp *pApp = (CSiteDownloadApp *) 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 CMyView::OnUpdateFileRename(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
void CMyView::OnUpdateFileMRU(CCmdUI* pCmdUI)
{
// Load the most recently used file list
CSiteDownloadApp *pApp = (CSiteDownloadApp *) 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 CMyView::OnFileClose()
{
CMyDoc* pDoc = GetDocument();
pDoc->SaveModified();
pDoc->Reset();
ClearTree();
}
void CMyView::OnUpdateFileClose(CCmdUI* pCmdUI)
{
CMyDoc* pDoc = GetDocument();
pCmdUI->Enable(pDoc->ProjectLoaded() && !m_bSnagging);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -