📄 directorylistingfrm.cpp
字号:
return; // unexpected
// Check on tree children
HTREEITEM hChild = ctrlTree.GetChildItem(hItem);
char itemText[256];
while(hChild != NULL)
{
if(!ctrlTree.GetItemText(hChild, itemText, 255))
return; // unexpected
if(Util::stricmp(*iPath, (string)itemText) == 0)
{
++iPath;
if(iPath == iPathEnd)
{
ctrlTree.SelectItem(hChild);
ctrlTree.EnsureVisible(hChild);
return;
}
GoToDirectory(hChild, iPath, iPathEnd);
return;
}
hChild = ctrlTree.GetNextItem(hChild, TVGN_NEXT);
}
}
LRESULT DirectoryListingFrame::onContextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) {
RECT rc; // client area of window
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; // location of mouse click
fileMenu.RemoveMenu(IDC_GO_TO_DIRECTORY, MF_BYCOMMAND);
// Get the bounding rectangle of the client area.
ctrlList.GetClientRect(&rc);
ctrlList.ScreenToClient(&pt);
if (PtInRect(&rc, pt) && ctrlList.GetSelectedCount() > 0) {
int n = 0;
ctrlList.ClientToScreen(&pt);
ItemInfo* ii = (ItemInfo*)ctrlList.GetItemData(ctrlList.GetNextItem(-1, LVNI_SELECTED));
while(targetMenu.GetMenuItemCount() > 0) {
targetMenu.DeleteMenu(0, MF_BYPOSITION);
}
if(ctrlList.GetSelectedCount() == 1 && ii->type == ItemInfo::FILE) {
targetMenu.AppendMenu(MF_STRING, IDC_DOWNLOADTO, CSTRING(BROWSE));
targets = QueueManager::getInstance()->getTargetsBySize(ii->file->getSize(), Util::getExtension(ii->file->getName()));
if(targets.size() > 0) {
targetMenu.AppendMenu(MF_SEPARATOR, 0, (LPCTSTR)NULL);
for(StringIter i = targets.begin(); i != targets.end(); ++i) {
targetMenu.AppendMenu(MF_STRING, IDC_DOWNLOAD_TARGET + (n++), i->c_str());
}
}
if(ii->file->getAdls())
{
fileMenu.AppendMenu(MF_STRING, IDC_GO_TO_DIRECTORY, CSTRING(GO_TO_DIRECTORY));
}
fileMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_hWnd);
} else {
targetMenu.AppendMenu(MF_STRING, IDC_DOWNLOADTO, CSTRING(BROWSE));
if(WinUtil::lastDirs.size() > 0) {
targetMenu.AppendMenu(MF_SEPARATOR, 0, (LPCTSTR)NULL);
for(StringIter i = WinUtil::lastDirs.begin(); i != WinUtil::lastDirs.end(); ++i) {
targetMenu.AppendMenu(MF_STRING, IDC_DOWNLOAD_TARGET + (n++), i->c_str());
}
}
if(ii->dir->getAdls() && ii->dir->getParent() != dl->getRoot())
{
fileMenu.AppendMenu(MF_STRING, IDC_GO_TO_DIRECTORY, CSTRING(GO_TO_DIRECTORY));
}
fileMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_hWnd);
}
return TRUE;
} else {
ctrlList.ClientToScreen(&pt);
ctrlTree.GetClientRect(&rc);
ctrlTree.ScreenToClient(&pt);
if (PtInRect(&rc, pt) && ctrlTree.GetSelectedItem() != NULL)
{
// Strange, windows doesn't change the selection on right-click... (!)
UINT a = 0;
HTREEITEM ht = ctrlTree.HitTest(pt, &a);
if(ht != NULL && ht != ctrlTree.GetSelectedItem())
ctrlTree.SelectItem(ht);
while(targetDirMenu.GetMenuItemCount() > 0) {
targetDirMenu.DeleteMenu(0, MF_BYPOSITION);
}
targetDirMenu.AppendMenu(MF_STRING, IDC_DOWNLOADDIRTO, CSTRING(BROWSE));
if(WinUtil::lastDirs.size() > 0) {
targetDirMenu.AppendMenu(MF_SEPARATOR, 0, (LPCTSTR)NULL);
int n = 0;
for(StringIter i = WinUtil::lastDirs.begin(); i != WinUtil::lastDirs.end(); ++i) {
targetDirMenu.AppendMenu(MF_STRING, IDC_DOWNLOAD_TARGET_DIR + (n++), i->c_str());
}
}
ctrlTree.ClientToScreen(&pt);
directoryMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, m_hWnd);
return TRUE;
}
}
return FALSE;
}
LRESULT DirectoryListingFrame::onDownloadTarget(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
int newId = wID - IDC_DOWNLOAD_TARGET;
dcassert(newId >= 0);
if(ctrlList.GetSelectedCount() == 1) {
ItemInfo* ii = (ItemInfo*)ctrlList.GetItemData(ctrlList.GetNextItem(-1, LVNI_SELECTED));
if(ii->type == ItemInfo::FILE) {
dcassert(newId < (int)targets.size());
try {
dl->download(ii->file, targets[newId]);
} catch(const Exception& e) {
ctrlStatus.SetText(0, e.getError().c_str());
}
} else {
dcassert(newId < (int)WinUtil::lastDirs.size());
downloadList(WinUtil::lastDirs[newId]);
}
} else if(ctrlList.GetSelectedCount() > 1) {
dcassert(newId < (int)WinUtil::lastDirs.size());
downloadList(WinUtil::lastDirs[newId]);
}
return 0;
}
LRESULT DirectoryListingFrame::onDownloadTargetDir(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
int newId = wID - IDC_DOWNLOAD_TARGET_DIR;
dcassert(newId >= 0);
HTREEITEM t = ctrlTree.GetSelectedItem();
if(t != NULL) {
DirectoryListing::Directory* dir = (DirectoryListing::Directory*)ctrlTree.GetItemData(t);
string target = SETTING(DOWNLOAD_DIRECTORY);
try {
dcassert(newId < (int)WinUtil::lastDirs.size());
dl->download(dir, WinUtil::lastDirs[newId]);
} catch(const Exception& e) {
ctrlStatus.SetText(0, e.getError().c_str());
}
}
return 0;
}
LRESULT DirectoryListingFrame::onKeyDown(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) {
NMLVKEYDOWN* kd = (NMLVKEYDOWN*) pnmh;
if(kd->wVKey == VK_BACK) {
HTREEITEM cur = ctrlTree.GetSelectedItem();
if(cur != NULL)
{
HTREEITEM parent = ctrlTree.GetParentItem(cur);
if(parent != NULL)
ctrlTree.SelectItem(parent);
}
} else if(kd->wVKey == VK_TAB) {
onTab();
} else if(kd->wVKey == VK_RETURN) {
if(ctrlList.GetSelectedCount() == 1) {
ItemInfo* ii = (ItemInfo*)ctrlList.GetItemData(ctrlList.GetNextItem(-1, LVNI_SELECTED));
if(ii->type == ItemInfo::DIRECTORY) {
HTREEITEM ht = ctrlTree.GetChildItem(ctrlTree.GetSelectedItem());
while(ht != NULL) {
if((DirectoryListing::Directory*)ctrlTree.GetItemData(ht) == ii->dir) {
ctrlTree.SelectItem(ht);
break;
}
ht = ctrlTree.GetNextSiblingItem(ht);
}
} else {
downloadList(SETTING(DOWNLOAD_DIRECTORY));
}
} else {
downloadList(SETTING(DOWNLOAD_DIRECTORY));
}
}
return 0;
}
int DirectoryListingFrame::sortFile(LPARAM a, LPARAM b) {
ItemInfo* c = (ItemInfo*)a;
ItemInfo* d = (ItemInfo*)b;
if(c->type == ItemInfo::DIRECTORY) {
if(d->type == ItemInfo::FILE) {
return -1;
}
return Util::stricmp(c->dir->getName().c_str(), d->dir->getName().c_str());
} else {
if(d->type == ItemInfo::DIRECTORY) {
return 1;
}
return Util::stricmp(c->file->getName().c_str(), d->file->getName().c_str());
}
}
int DirectoryListingFrame::sortType(LPARAM a, LPARAM b) {
ItemInfo* c = (ItemInfo*)a;
ItemInfo* d = (ItemInfo*)b;
if(c->type == ItemInfo::DIRECTORY) {
if(d->type == ItemInfo::FILE) {
return -1;
}
return Util::stricmp(c->dir->getName().c_str(), d->dir->getName().c_str());
} else {
if(d->type == ItemInfo::DIRECTORY) {
return 1;
}
string::size_type k = c->file->getName().rfind('.');
string suffix1 = (k != string::npos) ? c->file->getName().substr(k + 1) : Util::emptyString;
k = d->file->getName().rfind('.');
string suffix2 = (k != string::npos) ? d->file->getName().substr(k + 1) : Util::emptyString;
return Util::stricmp(suffix1.c_str(), suffix2.c_str());
}
}
int DirectoryListingFrame::sortSize(LPARAM a, LPARAM b) {
ItemInfo* c = (ItemInfo*)a;
ItemInfo* d = (ItemInfo*)b;
if(c->type == ItemInfo::DIRECTORY) {
if(d->type == ItemInfo::FILE) {
return -1;
}
return compare(c->dir->getTotalSize(), d->dir->getTotalSize());
} else {
if(d->type == ItemInfo::DIRECTORY) {
return 1;
}
return compare(c->file->getSize(), d->file->getSize());
}
}
void DirectoryListingFrame::UpdateLayout(BOOL bResizeBars /* = TRUE */) {
RECT rect;
GetClientRect(&rect);
// position bars and offset their dimensions
UpdateBarsPosition(rect, bResizeBars);
if(ctrlStatus.IsWindow()) {
CRect sr;
int w[8];
ctrlStatus.GetClientRect(sr);
w[7] = sr.right - 16;
#define setw(x) w[x] = max(w[x+1] - statusSizes[x], 0)
setw(6); setw(5); setw(4); setw(3); setw(2); setw(1); setw(0);
ctrlStatus.SetParts(8, w);
ctrlStatus.GetRect(6, sr);
sr.left = w[4];
sr.right = w[5];
ctrlMatchQueue.MoveWindow(sr);
sr.left = w[5];
sr.right = w[6];
ctrlFind.MoveWindow(sr);
sr.left = w[6];
sr.right = w[7];
ctrlFindNext.MoveWindow(sr);
}
SetSplitterRect(&rect);
}
HTREEITEM DirectoryListingFrame::findFile(const StringSearch& str, HTREEITEM root,
int &foundFile, int &skipHits)
{
// Check dir name for match
DirectoryListing::Directory* dir = (DirectoryListing::Directory*)ctrlTree.GetItemData(root);
if(str.match(dir->getName()))
{
if(skipHits == 0)
{
foundFile = -1;
return root;
}
else
skipHits--;
}
// Force list pane to contain files of current dir
changeDir(dir, FALSE);
// Check file names in list pane
for(int i=0; i<ctrlList.GetItemCount(); i++)
{
ItemInfo* ii = (ItemInfo*)ctrlList.GetItemData(i);
if(ii->type == ItemInfo::FILE)
{
if(str.match(ii->file->getName()))
{
if(skipHits == 0)
{
foundFile = i;
return root;
}
else
skipHits--;
}
}
}
dcdebug("looking for directories...\n");
// Check subdirs recursively
HTREEITEM item = ctrlTree.GetChildItem(root);
while(item != NULL)
{
HTREEITEM srch = findFile(str, item, foundFile, skipHits);
if(srch)
return srch;
else
item = ctrlTree.GetNextSiblingItem(item);
}
return 0;
}
void DirectoryListingFrame::findFile(bool findNext)
{
if(!findNext)
{
// Prompt for substring to find
LineDlg dlg;
dlg.title = STRING(SEARCH_FOR_FILE);
dlg.description = STRING(ENTER_SEARCH_STRING);
dlg.line = Util::emptyString;
if(dlg.DoModal() != IDOK)
return;
findStr = dlg.line;
skipHits = 0;
}
else
skipHits++;
if(findStr.empty())
return;
// Do a search
int foundFile = -1, skipHitsTmp = skipHits;
HTREEITEM const oldDir = ctrlTree.GetSelectedItem();
HTREEITEM const foundDir = findFile(StringSearch(findStr), ctrlTree.GetRootItem(), foundFile, skipHitsTmp);
ctrlTree.SetRedraw(TRUE);
if(foundDir)
{
// Highlight the directory tree and list if the parent dir/a matched dir was found
if(foundFile >= 0)
{
// SelectItem won't update the list if SetRedraw was set to FALSE and then
// to TRUE and the item selected is the same as the last one... workaround:
if(oldDir == foundDir)
ctrlTree.SelectItem(NULL);
ctrlTree.SelectItem(foundDir);
}
else
{
// Got a dir; select its parent directory in the tree if there is one
HTREEITEM parentItem = ctrlTree.GetParentItem(foundDir);
if(parentItem)
{
// Go to parent file list
ctrlTree.SelectItem(parentItem);
// Locate the dir in the file list
DirectoryListing::Directory* dir = (DirectoryListing::Directory*)ctrlTree.GetItemData(foundDir);
foundFile = ctrlList.find(dir->getName(), -1, true);
}
else
{
// If no parent exists, just the dir tree item and skip the list highlighting
ctrlTree.SelectItem(foundDir);
}
}
// Remove prev. selection from file list
if(ctrlList.GetSelectedCount() > 0)
{
for(int i=0; i<ctrlList.GetItemCount(); i++)
ctrlList.SetItemState(i, 0, LVIS_SELECTED);
}
// Highlight and focus the dir/file if possible
if(foundFile >= 0)
{
ctrlList.SetFocus();
ctrlList.EnsureVisible(foundFile, FALSE);
ctrlList.SetItemState(foundFile, LVIS_SELECTED | LVIS_FOCUSED, (UINT)-1);
}
else
ctrlTree.SetFocus();
}
else
{
ctrlTree.SelectItem(oldDir);
MessageBox(CSTRING(NO_MATCHES), CSTRING(SEARCH_FOR_FILE));
}
}
/**
* @file
* $Id: DirectoryListingFrm.cpp,v 1.19 2003/07/15 14:53:12 arnetheduck Exp $
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -