From 93a6978655fc1ce9e0fd8ea08029859f71c32db9 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Sun, 16 Nov 2025 13:53:58 +0100 Subject: dolphinview: when creating a subfolder expand to it if in details mode So the new folder is in view. --- src/kitemviews/kfileitemmodel.cpp | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src/kitemviews') 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 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); } } } -- cgit v1.3