linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #03380
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2435: Continue from the beginning after reaching the end of a file list when searching
------------------------------------------------------------
revno: 2435
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2011-02-21 20:48:45 +0100
message:
Continue from the beginning after reaching the end of a file list when searching
modified:
changelog.txt
dwt/src/widgets/StatusBar.cpp
help/window_file_list.html
win32/DirectoryListingFrame.cpp
win32/DirectoryListingFrame.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2011-02-19 17:02:21 +0000
+++ changelog.txt 2011-02-21 19:48:45 +0000
@@ -11,6 +11,8 @@
* Add NAT-PMP for port mappings as an alternative to UPnP (poy)
* [L#654483] Don't duplicate file list entries when re-downloading it (poy)
* Highlight window splitters on mouse hover (poy)
+* Continue from the beginning after reaching the end of a file list when searching (poy)
+* Report the progress of file list searches in the status bar (poy)
-- 0.781 2011-01-12 --
* Add a dummy serial number to TLS certs to satisfy some parsers (poy)
=== modified file 'dwt/src/widgets/StatusBar.cpp'
--- dwt/src/widgets/StatusBar.cpp 2011-01-02 17:12:02 +0000
+++ dwt/src/widgets/StatusBar.cpp 2011-02-21 19:48:45 +0000
@@ -86,7 +86,7 @@
info.text = text;
if(part != fill) {
info.updateSize(this, alwaysResize);
- } else {
+ } else if(!text.empty()) {
lastLines.push_back(text);
while(lastLines.size() > MAX_LINES) {
lastLines.erase(lastLines.begin());
=== modified file 'help/window_file_list.html'
--- help/window_file_list.html 2011-01-10 21:49:08 +0000
+++ help/window_file_list.html 2011-02-21 19:48:45 +0000
@@ -59,9 +59,6 @@
<dt>Text-box (left)</dt>
<dd cshelp="IDH_FILE_LIST_SEARCH_BOX">Enter your search terms here. The most recent searches can
be accessed by unfolding the list contained within this box.</dd>
- <dt>Find from the beginning</dt>
- <dd cshelp="IDH_FILE_LIST_FIND_START">Find items that match the search strings specified in the
- text-box. The search starts from the root of the file list.</dd>
<dt>Previous</dt>
<dd cshelp="IDH_FILE_LIST_FIND_PREV">Find items that match the search strings specified in the
text-box. The search starts from the current selection and goes backwards.</dd>
=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp 2011-02-19 17:03:15 +0000
+++ win32/DirectoryListingFrame.cpp 2011-02-21 19:48:45 +0000
@@ -27,12 +27,13 @@
#include "resource.h"
#include <dcpp/ADLSearch.h>
+#include <dcpp/ClientManager.h>
#include <dcpp/FavoriteManager.h>
#include <dcpp/File.h>
#include <dcpp/QueueManager.h>
+#include <dcpp/ShareManager.h>
+#include <dcpp/ScopedFunctor.h>
#include <dcpp/StringSearch.h>
-#include <dcpp/ClientManager.h>
-#include <dcpp/ShareManager.h>
#include <dcpp/WindowInfo.h>
#include <dwt/widgets/FolderDialog.h>
@@ -246,7 +247,7 @@
{
Button::Seed cs = WinUtil::Seeds::button;
- searchGrid = grid->addChild(Grid::Seed(1, 4));
+ searchGrid = grid->addChild(Grid::Seed(1, 3));
grid->setWidget(searchGrid, 1, 0);
searchGrid->column(0).mode = GridInfo::FILL;
@@ -256,25 +257,20 @@
searchBox->getTextBox()->onKeyDown(std::bind(&DirectoryListingFrame::handleSearchKeyDown, this, _1));
searchBox->getTextBox()->onChar(std::bind(&DirectoryListingFrame::handleSearchChar, this, _1));
- cs.caption = T_("Find from the beginning");
+ cs.caption = T_("Find previous");
ButtonPtr button = searchGrid->addChild(cs);
- button->setHelpId(IDH_FILE_LIST_FIND_START);
- button->setImage(WinUtil::buttonIcon(IDI_SEARCH));
- button->onClicked(std::bind(&DirectoryListingFrame::handleFind, this, FIND_START));
- addWidget(button);
-
- cs.caption = T_("Previous");
- button = searchGrid->addChild(cs);
button->setHelpId(IDH_FILE_LIST_FIND_PREV);
button->setImage(WinUtil::buttonIcon(IDI_LEFT));
- button->onClicked(std::bind(&DirectoryListingFrame::handleFind, this, FIND_PREV));
+ button->onClicked(std::bind(&DirectoryListingFrame::handleFind, this, true));
addWidget(button);
- cs.caption = T_("Next");
+ cs.caption = T_("Find next");
+ cs.style |= BS_DEFPUSHBUTTON;
button = searchGrid->addChild(cs);
+ cs.style &= ~BS_DEFPUSHBUTTON;
button->setHelpId(IDH_FILE_LIST_FIND_NEXT);
button->setImage(WinUtil::buttonIcon(IDI_RIGHT));
- button->onClicked(std::bind(&DirectoryListingFrame::handleFind, this, FIND_NEXT));
+ button->onClicked(std::bind(&DirectoryListingFrame::handleFind, this, false));
addWidget(button);
cs.caption = T_("Subtract list");
@@ -406,9 +402,9 @@
SettingsManager::getInstance()->set(SettingsManager::DIRECTORYLISTINGFRAME_WIDTHS, WinUtil::toString(files->getColumnWidths()));
}
-void DirectoryListingFrame::handleFind(FindMode mode) {
+void DirectoryListingFrame::handleFind(bool reverse) {
searching = true;
- findFile(mode);
+ findFile(reverse);
searching = false;
updateStatus();
}
@@ -961,7 +957,9 @@
}
}
-pair<HTREEITEM, int> DirectoryListingFrame::findFile(const StringSearch& str, bool reverse, HTREEITEM item, int pos, vector<HTREEITEM>& collapse) {
+pair<HTREEITEM, int> DirectoryListingFrame::findFile(const StringSearch& str, bool reverse, HTREEITEM item, int pos,
+ HTREEITEM const start, vector<HTREEITEM>& collapse, bool& cycle)
+{
// try to match the names currently in the list pane
const int n = files->size();
if(reverse && pos == -1)
@@ -979,23 +977,28 @@
collapse.push_back(item);
}
HTREEITEM next = dirs->getNext(item, reverse ? TVGN_PREVIOUSVISIBLE : TVGN_NEXTVISIBLE);
- if(next) {
+ if(!next) {
+ next = reverse ? dirs->getLast() : treeRoot;
+ cycle = true;
+ }
+ if(next && next != start) {
if(reverse && dirs->getChild(next) && !dirs->isExpanded(next)) {
dirs->expand(next);
collapse.push_back(next);
- next = dirs->getNext(item, TVGN_PREVIOUSVISIBLE);
+ if(!(next = dirs->getNext(item, TVGN_PREVIOUSVISIBLE)))
+ next = dirs->getLast();
}
// refresh the list pane to respect sorting etc
changeDir(dirs->getData(next)->dir);
- return findFile(str, reverse, next, -1, collapse);
+ return findFile(str, reverse, next, -1, start, collapse, cycle);
}
return make_pair(nullptr, 0);
}
-void DirectoryListingFrame::findFile(FindMode mode) {
+void DirectoryListingFrame::findFile(bool reverse) {
const tstring findStr = searchBox->getText();
if(findStr.empty())
return;
@@ -1017,37 +1020,41 @@
searchBox->insertValue(0, findStr);
}
+ status->setText(STATUS_STATUS, str(TF_("Searching for: %1%") % findStr));
+
+ // to make sure we set the status only after redrawing has been enabled back on the bar.
+ tstring finalStatus;
+ ScopedFunctor(([this, &finalStatus] { status->setText(STATUS_STATUS, finalStatus); }));
+
HoldRedraw hold(files);
HoldRedraw hold2(dirs);
HoldRedraw hold3(status);
- HTREEITEM const oldDir = dirs->getSelected();
+ HTREEITEM const start = dirs->getSelected();
auto prevHistory = history;
auto prevHistoryIndex = historyIndex;
- auto selectDir = [this, oldDir, &prevHistory, prevHistoryIndex](HTREEITEM newDir) {
+ auto selectDir = [this, start, &prevHistory, prevHistoryIndex](HTREEITEM dir) {
// SelectItem won't update the list if SetRedraw was set to FALSE and then
// to TRUE and the selected item is the same as the last one... workaround:
- if(newDir == oldDir)
+ if(dir == start)
dirs->setSelected(nullptr);
- dirs->setSelected(newDir);
- dirs->ensureVisible(newDir);
+ dirs->setSelected(dir);
+ dirs->ensureVisible(dir);
- if(newDir == oldDir) {
+ if(dir == start) {
history = prevHistory;
historyIndex = prevHistoryIndex;
}
};
- if(mode == FIND_START) {
- dirs->setSelected(treeRoot);
- files->clearSelection();
- }
-
vector<HTREEITEM> collapse;
- auto search = findFile(StringSearch(Text::fromT(findStr)), mode == FIND_PREV,
- (mode == FIND_START) ? treeRoot : oldDir, files->getSelected(), collapse);
+ bool cycle = false;
+ const auto fileSel = files->getSelected();
+
+ auto search = findFile(StringSearch(Text::fromT(findStr)), reverse, start, fileSel, start, collapse, cycle);
+
for(auto i = collapse.cbegin(), iend = collapse.cend(); i != iend; ++i)
dirs->collapse(*i);
@@ -1061,9 +1068,19 @@
files->setSelected(search.second);
files->ensureVisible(search.second);
+ if(cycle) {
+ auto s_b(T_("beginning")), s_e(T_("end"));
+ finalStatus = str(TF_("Reached the %1% of the file list, continuing from the %2%")
+ % (reverse ? s_b : s_e) % (reverse ? s_e : s_b));
+ }
+
} else {
- selectDir(oldDir);
- dwt::MessageBox(this).show(T_("No matches found for:") + _T("\n") + findStr, T_("Search for file"));
+ // restore the previous view.
+ selectDir(start);
+ files->setSelected(fileSel);
+ files->ensureVisible(fileSel);
+
+ finalStatus = str(TF_("No matches found for: %1%") % findStr);
}
}
@@ -1197,7 +1214,7 @@
bool DirectoryListingFrame::handleSearchKeyDown(int c) {
if(c == VK_RETURN && !(WinUtil::isShift() || WinUtil::isCtrl() || WinUtil::isAlt())) {
- handleFind(FIND_START);
+ handleFind(false);
return true;
}
return false;
=== modified file 'win32/DirectoryListingFrame.h'
--- win32/DirectoryListingFrame.h 2011-01-30 13:28:11 +0000
+++ win32/DirectoryListingFrame.h 2011-02-21 19:48:45 +0000
@@ -91,12 +91,6 @@
COLUMN_LAST
};
- enum FindMode {
- FIND_START,
- FIND_NEXT,
- FIND_PREV
- };
-
class ItemInfo : public FastAlloc<ItemInfo> {
public:
enum ItemType {
@@ -224,7 +218,7 @@
void addShellPaths(const ShellMenuPtr& menu, const vector<ItemInfo*>& sel);
void addUserMenu(const MenuPtr& menu);
- void handleFind(FindMode mode);
+ void handleFind(bool reverse);
void handleListDiff();
void handleMatchQueue();
void handleFindToggle();
@@ -271,8 +265,9 @@
void initStatusText();
void updateStatus();
- void findFile(FindMode mode);
- pair<HTREEITEM, int> findFile(const StringSearch& str, bool reverse, HTREEITEM item, int pos, vector<HTREEITEM>& collapse);
+ void findFile(bool reverse);
+ pair<HTREEITEM, int> findFile(const StringSearch& str, bool reverse, HTREEITEM item, int pos,
+ HTREEITEM const start, vector<HTREEITEM>& collapse, bool& cycle);
// MDIChildFrame
void tabMenuImpl(dwt::MenuPtr& menu);