📄 directorylistingfrm.cpp
字号:
bHandled = FALSE;
return FALSE;
}
HRESULT DirectoryListingFrame::onXButtonUp(UINT /*uMsg*/, WPARAM wParam, LPARAM /* lParam */, BOOL& /* bHandled */) {
if(GET_XBUTTON_WPARAM(wParam) & XBUTTON1) {
back();
return TRUE;
} else if(GET_XBUTTON_WPARAM(wParam) & XBUTTON2) {
forward();
return TRUE;
}
return FALSE;
}
LRESULT DirectoryListingFrame::onDownloadTarget(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
int newId = wID - IDC_DOWNLOAD_TARGET - 1;
dcassert(newId >= 0);
if(ctrlList.GetSelectedCount() == 1) {
ItemInfo* ii = (ItemInfo*)ctrlList.GetItemData(ctrlList.GetNextItem(-1, LVNI_SELECTED));
if(ii->type == ItemInfo::FILE) {
if(newId < (int)targets.size()) {
try {
dl->download(ii->file, targets[newId], false, WinUtil::isShift());
} catch(const Exception& e) {
ctrlStatus.SetText(STATUS_TEXT, Text::toT(e.getError()).c_str());
}
} else {
newId -= (int)targets.size();
dcassert(newId < (int)WinUtil::lastDirs.size());
downloadList(WinUtil::lastDirs[newId]);
}
} 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 - 1;
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, Text::fromT(WinUtil::lastDirs[newId]), WinUtil::isShift());
} catch(const Exception& e) {
ctrlStatus.SetText(STATUS_TEXT, Text::toT(e.getError()).c_str());
}
}
return 0;
}
LRESULT DirectoryListingFrame::onDownloadFavoriteDirs(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
int newId = wID - IDC_DOWNLOAD_FAVORITE_DIRS;
dcassert(newId >= 0);
StringPairList spl = FavoriteManager::getInstance()->getFavoriteDirs();
if(ctrlList.GetSelectedCount() == 1) {
ItemInfo* ii = (ItemInfo*)ctrlList.GetItemData(ctrlList.GetNextItem(-1, LVNI_SELECTED));
if(ii->type == ItemInfo::FILE) {
if(newId < (int)targets.size()) {
try {
dl->download(ii->file, targets[newId], false, WinUtil::isShift());
} catch(const Exception& e) {
ctrlStatus.SetText(STATUS_TEXT, Text::toT(e.getError()).c_str());
}
} else {
newId -= (int)targets.size();
dcassert(newId < (int)spl.size());
downloadList(Text::toT(spl[newId].first));
}
} else {
dcassert(newId < (int)spl.size());
downloadList(Text::toT(spl[newId].first));
}
} else if(ctrlList.GetSelectedCount() > 1) {
dcassert(newId < (int)spl.size());
downloadList(Text::toT(spl[newId].first));
}
return 0;
}
LRESULT DirectoryListingFrame::onDownloadWholeFavoriteDirs(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
int newId = wID - IDC_DOWNLOAD_WHOLE_FAVORITE_DIRS;
dcassert(newId >= 0);
HTREEITEM t = ctrlTree.GetSelectedItem();
if(t != NULL) {
DirectoryListing::Directory* dir = (DirectoryListing::Directory*)ctrlTree.GetItemData(t);
string target = SETTING(DOWNLOAD_DIRECTORY);
try {
StringPairList spl = FavoriteManager::getInstance()->getFavoriteDirs();
dcassert(newId < (int)spl.size());
dl->download(dir, spl[newId].first, WinUtil::isShift());
} catch(const Exception& e) {
ctrlStatus.SetText(STATUS_TEXT, Text::toT(e.getError()).c_str());
}
}
return 0;
}
LRESULT DirectoryListingFrame::onKeyDown(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) {
NMLVKEYDOWN* kd = (NMLVKEYDOWN*) pnmh;
if(kd->wVKey == VK_BACK) {
up();
} else if(kd->wVKey == VK_TAB) {
onTab();
} else if(kd->wVKey == VK_LEFT && WinUtil::isAlt()) {
back();
} else if(kd->wVKey == VK_RIGHT && WinUtil::isAlt()) {
forward();
} 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(Text::toT(SETTING(DOWNLOAD_DIRECTORY)));
}
} else {
downloadList(Text::toT(SETTING(DOWNLOAD_DIRECTORY)));
}
}
return 0;
}
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[STATUS_LAST];
ctrlStatus.GetClientRect(sr);
w[STATUS_DUMMY-1] = sr.right - 16;
for(int i = STATUS_DUMMY - 2; i >= 0; --i) {
w[i] = max(w[i+1] - statusSizes[i+1], 0);
}
ctrlStatus.SetParts(STATUS_LAST, w);
ctrlStatus.GetRect(0, sr);
sr.left = w[STATUS_FILE_LIST_DIFF - 1];
sr.right = w[STATUS_FILE_LIST_DIFF];
ctrlListDiff.MoveWindow(sr);
sr.left = w[STATUS_MATCH_QUEUE - 1];
sr.right = w[STATUS_MATCH_QUEUE];
ctrlMatchQueue.MoveWindow(sr);
sr.left = w[STATUS_FIND - 1];
sr.right = w[STATUS_FIND];
ctrlFind.MoveWindow(sr);
sr.left = w[STATUS_NEXT - 1];
sr.right = w[STATUS_NEXT];
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 = TSTRING(SEARCH_FOR_FILE);
dlg.description = TSTRING(ENTER_SEARCH_STRING);
dlg.line = Util::emptyStringT;
if(dlg.DoModal() != IDOK)
return;
findStr = Text::fromT(dlg.line);
if(!dl->getUtf8())
findStr = Text::utf8ToAcp(findStr);
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.findItem(Text::toT(dir->getName()), -1, false);
} 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(CTSTRING(NO_MATCHES), CTSTRING(SEARCH_FOR_FILE));
}
}
void DirectoryListingFrame::runUserCommand(UserCommand& uc) {
if(!WinUtil::getUCParams(m_hWnd, uc, ucLineParams))
return;
StringMap ucParams = ucLineParams;
set<User::Ptr> nicks;
int sel = -1;
while((sel = ctrlList.GetNextItem(sel, LVNI_SELECTED)) != -1) {
ItemInfo* ii = (ItemInfo*)ctrlList.getItemData(sel);
if(uc.getType() == UserCommand::TYPE_RAW_ONCE) {
if(nicks.find(dl->getUser()) != nicks.end())
continue;
nicks.insert(dl->getUser());
}
if(!dl->getUser()->isOnline())
return;
ucParams["fileTR"] = "NONE";
if(ii->type == ItemInfo::FILE) {
ucParams["type"] = "File";
ucParams["fileFN"] = dl->getPath(ii->file) + ii->file->getName();
ucParams["fileSI"] = Util::toString(ii->file->getSize());
ucParams["fileSIshort"] = Util::formatBytes(ii->file->getSize());
TTHValue *hash = ii->file->getTTH();
if(hash != NULL) {
ucParams["fileTR"] = hash->toBase32();
}
} else {
ucParams["type"] = "Directory";
ucParams["fileFN"] = dl->getPath(ii->dir) + ii->dir->getName();
ucParams["fileSI"] = Util::toString(ii->dir->getTotalSize());
ucParams["fileSIshort"] = Util::formatBytes(ii->dir->getTotalSize());
}
// compatibility with 0.674 and earlier
ucParams["file"] = ucParams["fileFN"];
ucParams["filesize"] = ucParams["fileSI"];
ucParams["filesizeshort"] = ucParams["fileSIshort"];
ucParams["tth"] = ucParams["fileTR"];
StringMap tmp = ucParams;
User::Ptr tmpPtr = dl->getUser();
ClientManager::getInstance()->userCommand(dl->getUser(), uc, tmp, true);
}
}
void DirectoryListingFrame::closeAll(){
for(FrameIter i = frames.begin(); i != frames.end(); ++i)
i->second->PostMessage(WM_CLOSE, 0, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -