← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2353: file list searching collapses back nodes it has expanded

 

------------------------------------------------------------
revno: 2353
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2010-12-19 15:06:31 +0100
message:
  file list searching collapses back nodes it has expanded
modified:
  dwt/include/dwt/widgets/Tree.h
  win32/DirectoryListingFrame.cpp


--
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 'dwt/include/dwt/widgets/Tree.h'
--- dwt/include/dwt/widgets/Tree.h	2010-07-10 14:36:48 +0000
+++ dwt/include/dwt/widgets/Tree.h	2010-12-19 14:06:31 +0000
@@ -165,7 +165,9 @@
 
 	ScreenCoordinate getContextMenuPos();
 
+	bool isExpanded(HTREEITEM node);
 	void expand(HTREEITEM node);
+	void collapse(HTREEITEM node);
 
 	void select(const ScreenCoordinate& pt);
 
@@ -355,10 +357,18 @@
 	return TreeView_HitTest(handle(), &tvhti);
 }
 
+inline bool Tree::isExpanded(HTREEITEM node) {
+	return TreeView_GetItemState(handle(), node, TVIS_EXPANDED) & TVIS_EXPANDED;
+}
+
 inline void Tree::expand(HTREEITEM node) {
 	TreeView_Expand(handle(), node, TVE_EXPAND);
 }
 
+inline void Tree::collapse(HTREEITEM node) {
+	TreeView_Expand(handle(), node, TVE_COLLAPSE);
+}
+
 inline void Tree::clearImpl() {
 	TreeView_DeleteAllItems( handle() );
 }

=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp	2010-12-18 16:47:53 +0000
+++ win32/DirectoryListingFrame.cpp	2010-12-19 14:06:31 +0000
@@ -865,15 +865,22 @@
 	// flow to the next directory
 	HTREEITEM next = dirs->getNext(item, reverse ? TVGN_PREVIOUSVISIBLE : TVGN_NEXTVISIBLE);
 	if(next) {
-		if(dirs->getChild(next)) {
+		HTREEITEM collapse = nullptr;
+		if(dirs->getChild(next) && !dirs->isExpanded(next)) {
 			dirs->expand(next);
+			collapse = next;
 			next = dirs->getNext(item, reverse ? TVGN_PREVIOUSVISIBLE : TVGN_NEXTVISIBLE);
 		}
 
 		// refresh the list pane to respect sorting etc
 		changeDir(dirs->getData(next)->dir);
 
-		return findFile(str, reverse, next, -1);
+		auto ret = findFile(str, reverse, next, -1);
+
+		if(collapse)
+			dirs->collapse(collapse);
+
+		return ret;
 	}
 
 	return make_pair(nullptr, 0);
@@ -908,6 +915,15 @@
 
 	HTREEITEM const oldDir = dirs->getSelected();
 
+	auto selectDir = [this, oldDir](HTREEITEM newDir) {
+		// 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)
+			dirs->setSelected(nullptr);
+		dirs->setSelected(newDir);
+		dirs->ensureVisible(newDir);
+	};
+
 	if(mode == FIND_START) {
 		dirs->setSelected(treeRoot);
 		files->clearSelection();
@@ -916,13 +932,7 @@
 	auto search = findFile(StringSearch(findStr), mode == FIND_PREV, (mode == FIND_START) ? treeRoot : oldDir, files->getSelected());
 
 	if(search.first) {
-		// SelectItem won't update the list if SetRedraw was set to FALSE and then
-		// to TRUE and the item setSelecteded is the same as the last one... workaround:
-		if(oldDir == search.first)
-			dirs->setSelected(NULL);
-		// Highlight the directory in the tree
-		dirs->setSelected(search.first);
-		dirs->ensureVisible(search.first);
+		selectDir(search.first);
 
 		// Remove prev. selection from file list
 		files->clearSelection();
@@ -933,9 +943,7 @@
 		files->ensureVisible(search.second);
 
 	} else {
-		// same workaround as above (select NULL / select old dir) as dirs may have changed while searching
-		dirs->setSelected(NULL);
-		dirs->setSelected(oldDir);
+		selectDir(oldDir);
 		dwt::MessageBox(this).show(T_("No matches found for:") + _T("\n") + Text::toT(findStr), T_("Search for file"));
 	}
 }