]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Restore the tree state in Details View if a folder is re-expanded
authorFrank Reininghaus <frank78ac@googlemail.com>
Sat, 26 Oct 2013 07:36:40 +0000 (09:36 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sat, 26 Oct 2013 07:36:50 +0000 (09:36 +0200)
This patch actually does two things when collapsing an expanded folder
with expanded children:

(a) It removes all expanded children (which are removed from the model)
    from m_expandedDirs.

(b) It remembers the expanded children and restores them if the
    top-level folder is re-expanded.

BUG: 304363
FIXED-IN: 4.12.0
REVIEW: 113293

src/kitemviews/kfileitemmodel.cpp

index ea7ac2fc1bdf166a922de70f70c18b718d344c1d..f21edbf4a85d7d428bda2d75328697626afdc188 100644 (file)
@@ -440,6 +440,11 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
     if (expanded) {
         m_expandedDirs.insert(targetUrl, url);
         m_dirLister->openUrl(url, KDirLister::Keep);
+
+        const KUrl::List previouslyExpandedChildren = m_itemData.at(index)->values.value("previouslyExpandedChildren").value<KUrl::List>();
+        foreach (const KUrl& url, previouslyExpandedChildren) {
+            m_urlsToExpand.insert(url);
+        }
     } else {
         m_expandedDirs.remove(targetUrl);
         m_dirLister->stop(url);
@@ -448,14 +453,24 @@ bool KFileItemModel::setExpanded(int index, bool expanded)
         const int itemCount = m_itemData.count();
         const int firstChildIndex = index + 1;
 
+        KUrl::List expandedChildren;
+
         int childIndex = firstChildIndex;
         while (childIndex < itemCount && expandedParentsCount(childIndex) > parentLevel) {
+            ItemData* itemData = m_itemData.at(childIndex);
+            if (itemData->values.value("isExpanded").toBool()) {
+                const KUrl targetUrl = itemData->item.targetUrl();
+                m_expandedDirs.remove(targetUrl);
+                expandedChildren.append(targetUrl);
+            }
             ++childIndex;
         }
         const int childrenCount = childIndex - firstChildIndex;
 
         removeFilteredChildren(KItemRangeList() << KItemRange(index, 1 + childrenCount));
         removeItems(KItemRangeList() << KItemRange(firstChildIndex, childrenCount), DeleteItemData);
+
+        m_itemData.at(index)->values.insert("previouslyExpandedChildren", expandedChildren);
     }
 
     return true;