From f395a825a9c9be41cd60299db4996b633c2d5dc6 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sun, 28 May 2006 23:54:28 +0000
Subject: [PATCH] added CollapsePath() (patch 1494638)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt              |  1 +
 docs/latex/wx/dirctrl.tex     |  6 ++++++
 include/wx/generic/dirctrlg.h |  2 ++
 src/generic/dirctrlg.cpp      | 27 +++++++++++++++++++++++++++
 4 files changed, 36 insertions(+)

diff --git a/docs/changes.txt b/docs/changes.txt
index 5cb334e9f0..4f2e42d2cc 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -147,6 +147,7 @@ All (GUI):
 - Fixed bug with ignoring blank lines in multiline wxGrid cell labels
 - Added wxTextAttr::Merge() (Marcin Simonides)
 - Added wxTB_NO_TOOLTIPS style (Igor Korot)
+- Added wxGenericDirCtrl::CollapsePath() (Christian Buhtz)
 
 wxMSW:
 
diff --git a/docs/latex/wx/dirctrl.tex b/docs/latex/wx/dirctrl.tex
index 9bbd61e576..e08c31f40a 100644
--- a/docs/latex/wx/dirctrl.tex
+++ b/docs/latex/wx/dirctrl.tex
@@ -101,6 +101,12 @@ Collapses the entire tree.
 
 Tries to expand as much of the given path as possible, so that the filename or directory is visible in the tree control.
 
+\membersection{wxGenericDirCtrl::CollapsePath}\label{wxgenericdirctrlcollapsepath}
+
+\func{bool}{CollapsePath}{\param{const wxString\& }{path}}
+
+Collapse the given path.
+
 \membersection{wxGenericDirCtrl::GetDefaultPath}\label{wxgenericdirctrlgetdefaultpath}
 
 \constfunc{wxString}{GetDefaultPath}{\void}
diff --git a/include/wx/generic/dirctrlg.h b/include/wx/generic/dirctrlg.h
index 1d48d66c84..586d026f27 100644
--- a/include/wx/generic/dirctrlg.h
+++ b/include/wx/generic/dirctrlg.h
@@ -116,6 +116,8 @@ public:
 
     // Try to expand as much of the given path as possible.
     virtual bool ExpandPath(const wxString& path);
+    // collapse the path
+    virtual bool CollapsePath(const wxString& path);
 
     // Accessors
 
diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp
index 2af122dc8f..06deb834d5 100644
--- a/src/generic/dirctrlg.cpp
+++ b/src/generic/dirctrlg.cpp
@@ -1065,6 +1065,33 @@ bool wxGenericDirCtrl::ExpandPath(const wxString& path)
     return true;
 }
 
+
+bool wxGenericDirCtrl::CollapsePath(const wxString& path)
+{
+    bool done           = false;
+    wxTreeItemId id     = FindChild(m_rootId, path, done);
+    wxTreeItemId lastId = id; // The last non-zero id
+
+    while ( id.IsOk() && !done )
+    {
+        CollapseDir(id);
+
+        id = FindChild(id, path, done);
+
+        if ( id.IsOk() )
+            lastId = id;
+    }
+
+    if ( !lastId.IsOk() )
+        return false;
+
+    m_treeCtrl->SelectItem(lastId);
+    m_treeCtrl->EnsureVisible(lastId);
+
+    return true;
+}
+
+
 wxString wxGenericDirCtrl::GetPath() const
 {
     wxTreeItemId id = m_treeCtrl->GetSelection();
-- 
2.50.0

