┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorMéven Car <[email protected]>2025-11-16 13:53:58 +0100
committerMéven Car <[email protected]>2026-01-20 10:45:34 +0100
commit93a6978655fc1ce9e0fd8ea08029859f71c32db9 (patch)
treea65c505d9b951317dcc4a5d5bfc16cf7f5992995 /src/kitemviews
parent38fb26518a14f68ce66a14a1197866fed865c430 (diff)
dolphinview: when creating a subfolder expand to it if in details mode
So the new folder is in view.
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index eb1d4e72a..383f45e9f 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -750,15 +750,41 @@ void KFileItemModel::expandParentDirectories(const QUrl &url)
m_urlsToExpand.insert(urlToExpand);
}
+ auto expandUrlAfterInserted = [this](const QUrl &url) {
+ // need to wait for the item to be added to the model
+ QMetaObject::Connection *connection = new QMetaObject::Connection;
+ *connection = connect(this, &KFileItemModel::itemsInserted, this, [this, url, connection](const KItemRangeList &ranges) {
+ int idx = -1;
+ for (const KItemRange &it : ranges) {
+ for (int i = 0; i < it.count; ++i) {
+ if (fileItem(it.index + i).url() == url) {
+ idx = it.index + i;
+ break;
+ }
+ }
+ if (idx != -1) {
+ break;
+ }
+ }
+
+ if (idx != -1) {
+ setExpanded(idx, true);
+ disconnect(*connection);
+ delete connection;
+ }
+ });
+ };
+
// KDirLister::open() must called at least once to trigger an initial
// loading. The pending URLs that must be restored are handled
// in slotCompleted().
- QSetIterator<QUrl> it2(m_urlsToExpand);
- while (it2.hasNext()) {
- const int idx = index(it2.next());
- if (idx >= 0 && !isExpanded(idx)) {
+ for (const auto &url : std::as_const(m_urlsToExpand)) {
+ const int idx = index(url);
+ if (idx >= 0) {
setExpanded(idx, true);
- break;
+ } else {
+ // expand to url asynchronously
+ expandUrlAfterInserted(url);
}
}
}