📄 ftplistctrl.cpp
字号:
file = TRUE;
}
if (count == 1)
{
if (pMainFrame->m_pCommandQueue->IsBusy())
{
MessageBeep(MB_ICONEXCLAMATION);
return;
}
POSITION selpos = GetFirstSelectedItemPosition();
ASSERT(selpos);
int nItem = GetNextSelectedItem(selpos);
int index = m_IndexMapping[nItem];
if (index == m_pDirectory->num)
{
ASSERT(selpos);
nItem = GetNextSelectedItem(selpos);
index = m_IndexMapping[nItem];
}
if (index < 0 || index >= m_pDirectory->num)
{
MessageBeep(MB_ICONEXCLAMATION);
return;
}
if (!bDontAsk)
{
CString str;
str.Format(IDS_QUESTION_DELETEFILE, m_pDirectory->direntry[index].name);
int res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
if (res == IDYES)
{
bDontAsk = TRUE;
// Jump back to the start of the function
goto ondelete_recheck;
}
}
else
{
if (m_pDirectory->direntry[index].dir)
{
t_folder folder;
folder.path = m_pDirectory->path;
folder.subdir = m_pDirectory->direntry[index].name;
m_PathsToVisit.push_back(folder);
pMainFrame->m_pCommandQueue->SetLock(TRUE);
}
else
pMainFrame->m_pCommandQueue->Delete(m_pDirectory->direntry[index].name, m_pDirectory->path);
}
}
else if (count>1)
{
if (pMainFrame->m_pCommandQueue->IsBusy())
{
MessageBeep(MB_ICONEXCLAMATION);
return;
}
if (!bDontAsk)
{
int res = IDNO;
CString str;
if (dir&&(!file))
{
str.Format(IDS_QUESTION_DELETEDIRS, count);
res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
}
else if (dir&&file)
{
str.Format(IDS_QUESTION_DELETEFILESANDDIRS, count);
res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
}
else
{
str.Format(IDS_QUESTION_DELETEFILES, count);
res = AfxMessageBox(str, MB_YESNO|MB_ICONQUESTION);
}
if (res == IDYES)
{
bDontAsk = TRUE;
// Jump back to the start of the function
goto ondelete_recheck;
}
}
else
{
selpos = GetFirstSelectedItemPosition();
ASSERT(selpos);
while (selpos)
{
count++;
int nItem = GetNextSelectedItem(selpos);
int index = m_IndexMapping[nItem];
if (index==m_pDirectory->num)
continue;
if (m_pDirectory->direntry[index].dir)
{
t_folder folder;
folder.path = m_pDirectory->path;
folder.subdir = m_pDirectory->direntry[index].name;
m_PathsToVisit.push_back(folder);
pMainFrame->m_pCommandQueue->SetLock(TRUE);
}
else
pMainFrame->m_pCommandQueue->Delete(m_pDirectory->direntry[index].name,m_pDirectory->path);
}
}
}
if (!m_PathsToVisit.empty())
{
m_PathsVisited.push_front(m_pDirectory->path);
m_nBatchAction = 2;
DoNextStep();
}
}
void CFtpListCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar==46)
OnFtpcontextDelete();
else if (nChar==VK_F2)
{
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
if (pMainFrame->m_pCommandQueue->IsLocked())
return;
// To Use F2 as hot Key to get EditCtrl on the ListView it must have
// the Style LVS_EDITLABELS
ASSERT( GetStyle() & LVS_EDITLABELS );
// don't do an Edit Label when the multiple Items are selected
if( GetSelectedCount( ) == 1 )
{
UINT nListSelectedItem = GetSelectedItem();
VERIFY( EditLabel( nListSelectedItem ) != NULL );
}
else
CListCtrl::OnKeyDown( nChar, nRepCnt, nFlags );
}
CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CFtpListCtrl::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
if (pMainFrame->m_pCommandQueue->IsBusy())
{
POSITION selpos = GetFirstSelectedItemPosition();
while (selpos)
{
int nItem = GetNextSelectedItem(selpos);
int index = m_IndexMapping[nItem];
ASSERT(index!=m_pDirectory->num);
if (m_pDirectory->direntry[index].dir)
return;
}
}
if (pMainFrame->m_pCommandQueue->IsLocked())
return;
POSITION selpos = GetFirstSelectedItemPosition();
while (selpos)
{
int nItem = GetNextSelectedItem(selpos);
if (!nItem)
return;
}
EnsureVisible(((LPNMLISTVIEW)pNMHDR)->iItem, FALSE);
//Let the main window handle the rest
pMainFrame->OnBegindrag(this, ((LPNMLISTVIEW)pNMHDR)->ptAction);
}
void CFtpListCtrl::OnDragEnd(int target, CPoint point)
{
DragLeave(NULL);
m_transferuser = m_transferpass = "";
if (target == 1)
OnFtpcontextAddtoqueue();
else if (!target)
OnFtpcontextDownload();
else if (target == 2 || target == 3)
{
if (!m_pDirectory)
return;
CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
if (pMainFrame->m_pCommandQueue->IsLocked())
return;
if (m_nBatchAction || !m_PathsToVisit.empty() || !m_PathsVisited.empty())
return;
if (pMainFrame->m_pCommandQueue->IsBusy())
{
MessageBeep(MB_ICONEXCLAMATION);
return;
}
CServerPath path = m_pDirectory->path;
CServerPath newPath = path;
if (target == 2)
{
ScreenToClient(&point);
int index = HitTest(point);
if (index == -1)
return;
if (index > 0 && !m_pDirectory->direntry[m_IndexMapping[index]].dir)
return;
POSITION selpos = GetFirstSelectedItemPosition();
while (selpos)
{
int nItem = GetNextSelectedItem(selpos);
if (nItem == index)
return;
}
if (!index)
{
if (!path.HasParent())
return;
newPath = path.GetParent();
}
else
newPath.AddSubdir(m_pDirectory->direntry[m_IndexMapping[index]].name);
}
else
{
newPath = reinterpret_cast<CFtpTreeCtrl *>(pMainFrame->GetFtpTreePane()->GetTreeCtrl())->GetDropTarget();
if (newPath.IsEmpty())
return;
}
POSITION selpos = GetFirstSelectedItemPosition();
while (selpos)
{
int nItem = GetNextSelectedItem(selpos);
pMainFrame->m_pCommandQueue->Rename(m_pDirectory->direntry[m_IndexMapping[nItem]].name, m_pDirectory->direntry[m_IndexMapping[nItem]].name, path, newPath);
}
}
}
void CFtpListCtrl::OnDropFiles(HDROP hDropInfo)
{
//End of a file drag&drop operation
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
if (!GetItemCount())
{
DragFinish(hDropInfo);
return;
}
int dropcount=DragQueryFile(hDropInfo,0xFFFFFFFF,0,0);
for (int i=0;i<dropcount;i++)
{
int len=DragQueryFile(hDropInfo,i,0,0)+1;
LPTSTR name=new TCHAR[len];
DragQueryFile(hDropInfo,i,name,len);
CFileStatus64 status;
GetStatus64(name, status);
CString name2=name;
if (status.m_attribute&0x10)
{
CString filename=name;
if (filename.ReverseFind('\\')!=-1)
filename=filename.Right(filename.GetLength()-filename.ReverseFind('\\')-1);
UploadDir(name2+_T("\\*.*"),filename+_T("\\"),TRUE);
}
else
{
ASSERT(name2.ReverseFind('\\')!=-1);
CString filename=name2.Mid(name2.ReverseFind('\\')+1);
CString path=name2.Left(name2.ReverseFind('\\'));
pMainFrame->AddQueueItem(FALSE,filename,"",path,m_pDirectory->path,TRUE);
}
delete [] name;
}
pMainFrame->TransferQueue(2);
DragFinish(hDropInfo);
}
void CFtpListCtrl::UploadDir(CString dir,CString subdir,BOOL upload)
{
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
CFileFind find;
BOOL res=find.FindFile(dir);
while (res)
{
res=find.FindNextFile();
if (find.IsDirectory())
{
if (!find.IsDots())
UploadDir(find.GetFilePath()+"\\*.*",subdir+find.GetFileName()+"\\",upload);
}
else
{
CString sdir="";
CString path=subdir;
path.TrimLeft( _T("\\") );
path.TrimRight( _T("\\") );
while (path!=_T("") )
{
CString tmp;
int pos=path.Find(_T("\\") );
if (pos==-1)
{
tmp.Format(_T(" %d %s"),path.GetLength(),path);
path=_T("");
}
else
{
tmp.Format(_T(" %d %s"),path.Left(pos).GetLength(),path.Left(pos));
path=path.Mid(pos+1);
}
sdir+=tmp;
}
sdir.TrimLeft( _T(" ") );
CServerPath sPath=m_pDirectory->path;
sPath.AddSubdirs(sdir);
CString lPath=find.GetFilePath();
int pos=lPath.ReverseFind('\\');
ASSERT(pos!=-1);
lPath=lPath.Left(pos+1);
pMainFrame->AddQueueItem(FALSE,find.GetFileName(),"",lPath,sPath,upload);
}
}
}
void CFtpListCtrl::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
*pResult=TRUE;
if (pMainFrame->m_pCommandQueue->IsLocked())
return;
if (pMainFrame->m_pCommandQueue->IsBusy())
return;
if (!pDispInfo->item.iItem)
return;
*pResult = 0;
CEdit *pEdit=GetEditControl();
if (pEdit)
pEdit->LimitText( 255 );
}
void CFtpListCtrl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
if (pDispInfo->item.pszText)
{
CString newname = pDispInfo->item.pszText;
newname = newname.Left(255);
if ((newname.Find('/')!=-1)||(newname.Find('\\')!=-1)||
(newname.Find(':')!=-1)||(newname.Find('*')!=-1)||
(newname.Find('?')!=-1)||(newname.Find('"')!=-1)||
(newname.Find('<')!=-1)||(newname.Find('>')!=-1)||
(newname.Find('|')!=-1))
{
AfxMessageBox(IDS_ERRORMSG_FILENAMEINVALID, MB_ICONEXCLAMATION);
*pResult = FALSE;
return;
}
CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, GetParentFrame());
pMainFrame->m_pCommandQueue->Rename(m_pDirectory->direntry[m_IndexMapping[pDispInfo->item.iItem]].name, newname, m_pDirectory->path);
}
*pResult = FALSE;
}
#define VK_A 65
BOOL CFtpListCtrl::PreTranslateMessage(MSG* pMsg)
{
// If edit control is visible in tree view control, sending a
// WM_KEYDOWN message to the edit control will dismiss the edit
// control. When ENTER key was sent to the edit control, the parent
// window of the tree view control is responsible for updating the
// item's label in TVN_ENDLABELEDIT notification code.
if ( pMsg->message == WM_KEYDOWN )
{
CEdit* edit = GetEditControl();
if (edit)
{
if( GetKeyState( VK_CONTROL )&128 && pMsg->wParam == VK_A )
{
edit->SetSel(0, -1);
return TRUE;
}
if( pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_CONTROL || pMsg->wParam == VK_INSERT || pMsg->wParam == VK_SHIFT )
{
edit->SendMessage(WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
return TRUE;
}
}
else
{
if( GetKeyState( VK_CONTROL )&128 && pMsg->wParam == VK_A )
{
m_bUpdating = TRUE;
if (GetItemCount())
SetItemState(0,GetItemCount()==1?LVIS_SELECTED:0,LVIS_SELECTED);
for (int i=1;i<GetItemCount();i++)
SetItemState(i,LVIS_SELECTED,LVIS_SELECTED);
m_bUpdating = FALSE;
UpdateStatusBar();
return TRUE;
}
else if (pMsg->wParam==VK_RETURN)
{
CMainFrame *pMainFrame=DYNAMIC_DOWNCAST(CMainFrame,GetParentFrame());
if (pMainFrame->m_pCommandQueue->IsLocked())
return TRUE;
if (m_nBatchAction || !m_PathsToVisit.empty() || !m_PathsVisited.empty())
return TRUE;
POSITION selpos = GetFirstSelectedItemPosition();
BOOL bOpen=TRUE;
int openindex=-1;
if (selpos)
{
int nItem = GetNextSelectedItem(selpos);
int index=openindex=m_IndexMapping[nItem];
if (index!=m_pDirectory->num && !m_pDirectory->direntry[index].dir)
{
bOpen=FALSE;
pMainFrame->AddQueueItem(TRUE,m_pDirectory->direntry[index].name,"","",m_pDirectory->path,TRUE);
openindex=-1;
}
}
else
return TRUE;
while (selpos)
{
bOpen=FALSE;
int nItem = GetNextSelectedItem(selpos);
int index=m_IndexMapping[nItem];
if (index==m_pDirectory->num)
continue;
if (m_pDirectory->direntry[index].dir)
{
t_folder folder;
folder.path = m_pDirectory->path;
folder.subdir = m_pDirectory->direntry[index].name;
m_PathsToVisit.push_back(folder);
pMainFrame->m_pCommandQueue->SetLock(TRUE);
}
else
pMainFrame->AddQueueItem(TRUE,m_pDirectory->direntry[index].name,"","",m_pDirectory->path,TRUE,m_transferuser,m_transferpass);
}
if (bOpen)
{
if (openindex==m_pDirectory->num)
ChangeDir(m_pDirectory->path,"..",FALSE,FZ_LIST_USECACHE|FZ_LIST_EXACT);
else if (m_pDirectory->direntry[openindex].dir)
ChangeDir(m_pDirectory->path,m_pDirectory->direntry[openindex].name,FALSE,FZ_LIST_USECACHE|FZ_LIST_EXACT);
}
else
{
if (openindex!=-1 && m_pDirectory->direntry[openindex].dir)
{
t_folder folder;
folder.path = m_pDirectory->path;
folder.subdir = m_pDirectory->direntry[openindex].name;
m_PathsToVisit.push_back(folder);
pMainFrame->m_pCommandQueue->SetLock(TRUE);
}
if (!m_PathsToVisit.empty())
{
m_nFolderDownloadStart = TRUE;
m_PathsVisited.push_front(m_pDirectory->path);
m_nBatchAction = 1;
DoNextStep();
}
else
pMainFrame->TransferQueue(2);
}
}
else if (pMsg->wParam == VK_BACK)
{
if (m_pDirectory)
ChangeDir(m_pDirectory->path, "..", FALSE, FZ_LIST_USECACHE|FZ_LIST_EXACT);
else
MessageBeep(MB_ICONEXCLAMATION);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -