]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 1174270 ] small fixes to wxGenericDirCtrl
authorJulian Smart <julian@anthemion.co.uk>
Thu, 31 Mar 2005 19:04:03 +0000 (19:04 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 31 Mar 2005 19:04:03 +0000 (19:04 +0000)
Stas Sergeev:

1. CollapseDir() was forgetting to... hrmm, to collapse
the dir...
It was only removing the child elements, leaving the dir
expanded. Missing code added.

2. ReCreateTree(), which, according to the comments, must
collapse and re-open the tree, was not re-opening it.
Fixed.

3. For those who used the bogus ReCreateTree() behaviour
to collapse the tree, I added CollapseTree(). This does
visually what the ReCreateTree() wrongly did before the
patch.

4. Documentation is updated accordingly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33223 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/dirctrl.tex
include/wx/generic/dirctrlg.h
src/generic/dirctrlg.cpp

index 950b5c3ef958516c28bec0fda8476c9e1560bae7..9bbd61e5765feb960aa79f509174bbbeda19be9c 100644 (file)
@@ -89,6 +89,12 @@ Create function for two-step construction. See \helpref{wxGenericDirCtrl::wxGene
 
 Initializes variables.
 
+\membersection{wxGenericDirCtrl::CollapseTree}\label{wxgenericdirctrlcollapsetree}
+
+\func{void}{CollapseTree}{\void}
+
+Collapses the entire tree.
+
 \membersection{wxGenericDirCtrl::ExpandPath}\label{wxgenericdirctrlexpandpath}
 
 \func{bool}{ExpandPath}{\param{const wxString\& }{path}}
@@ -145,6 +151,13 @@ Returns the root id for the tree control.
 
 Returns a pointer to the tree control.
 
+\membersection{wxGenericDirCtrl::ReCreateTree}\label{wxgenericdirctrlrecreatetree}
+
+\func{void}{ReCreateTree}{\void}
+
+Collapse and expand the tree, thus re-creating it from scratch.
+May be used to update the displayed directory content.
+
 \membersection{wxGenericDirCtrl::SetDefaultPath}\label{wxgenericdirctrlsetdefaultpath}
 
 \func{void}{SetDefaultPath}{\param{const wxString\& }{path}}
index 66cd52bc6292b1008f71f5f3dde767c98d6fe36b..e554f381827bd8cab0d2a4a01547db682423df8f 100644 (file)
@@ -168,7 +168,11 @@ public:
     // Collapse & expand the tree, thus re-creating it from scratch:
     virtual void ReCreateTree();
 
+    // Collapse the entire tree
+    virtual void CollapseTree();
+
 protected:
+    virtual void ExpandRoot();
     virtual void ExpandDir(wxTreeItemId parentId);
     virtual void CollapseDir(wxTreeItemId parentId);
     virtual const wxTreeItemId AddSection(const wxString& path, const wxString& name, int imageId = 0);
index ff84d56790969285c4979de2d057cb3f8c50e83e..d792d8e4d20a72f1d8210e944c5b9c3d1975a809 100644 (file)
@@ -487,6 +487,26 @@ wxGenericDirCtrl::wxGenericDirCtrl(void)
     Init();
 }
 
+void wxGenericDirCtrl::ExpandRoot()
+{
+    ExpandDir(m_rootId); // automatically expand first level
+
+    // Expand and select the default path
+    if (!m_defaultPath.empty())
+    {
+        ExpandPath(m_defaultPath);
+    }
+#ifdef __UNIX__
+    else
+    {
+        // On Unix, there's only one node under the (hidden) root node. It
+        // represents the / path, so the user would always have to expand it;
+        // let's do it ourselves
+        ExpandPath( wxT("/") );
+    }
+#endif
+}
+
 bool wxGenericDirCtrl::Create(wxWindow *parent,
                               const wxWindowID id,
                               const wxString& dir,
@@ -560,22 +580,8 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
 
     m_rootId = m_treeCtrl->AddRoot( rootName, 3, -1, rootData);
     m_treeCtrl->SetItemHasChildren(m_rootId);
-    ExpandDir(m_rootId); // automatically expand first level
 
-    // Expand and select the default path
-    if (!m_defaultPath.empty())
-    {
-        ExpandPath(m_defaultPath);
-    }
-#ifdef __UNIX__
-    else
-    {
-        // On Unix, there's only one node under the (hidden) root node. It
-        // represents the / path, so the user would always have to expand it;
-        // let's do it ourselves
-        ExpandPath( wxT("/") );
-    }
-#endif
+    ExpandRoot();
 
     SetBestSize(size);
     DoResize();
@@ -740,6 +746,8 @@ void wxGenericDirCtrl::CollapseDir(wxTreeItemId parentId)
          * handle disappearing children! */
         child = m_treeCtrl->GetFirstChild(parentId, cookie);
     }
+    if (parentId != m_treeCtrl->GetRootItem())
+        m_treeCtrl->Collapse(parentId);
 }
 
 void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
@@ -894,7 +902,18 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
 void wxGenericDirCtrl::ReCreateTree()
 {
     CollapseDir(m_treeCtrl->GetRootItem());
-    ExpandDir(m_treeCtrl->GetRootItem());
+    ExpandRoot();
+}
+
+void wxGenericDirCtrl::CollapseTree()
+{
+    wxTreeItemIdValue cookie;
+    wxTreeItemId child = m_treeCtrl->GetFirstChild(m_rootId, cookie);
+    while (child.IsOk())
+    {
+        CollapseDir(child);
+        child = m_treeCtrl->GetNextChild(m_rootId, cookie);
+    }
 }
 
 // Find the child that matches the first part of 'path'.