┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dolphincontextmenu.cpp5
-rw-r--r--src/dolphinmainwindow.cpp3
-rw-r--r--src/kitemviews/kfileitemmodel.cpp36
-rw-r--r--src/tests/kfileitemmodeltest.cpp3
-rw-r--r--src/views/dolphinview.cpp7
-rw-r--r--src/views/dolphinview.h5
6 files changed, 53 insertions, 6 deletions
diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp
index 53f155af4..577990e19 100644
--- a/src/dolphincontextmenu.cpp
+++ b/src/dolphincontextmenu.cpp
@@ -225,7 +225,10 @@ void DolphinContextMenu::addDirectoryItemContextMenu()
newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
connect(newFileMenu, &DolphinNewFileMenu::fileCreationRejected, newFileMenu, &DolphinNewFileMenu::deleteLater);
- connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
+ connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, [newFileMenu, mainWindow = m_mainWindow](const QUrl &newDirectory) {
+ mainWindow->activeViewContainer()->view()->expandToUrl(newDirectory);
+ newFileMenu->deleteLater();
+ });
connect(newFileMenu, &DolphinNewFileMenu::directoryCreationRejected, newFileMenu, &DolphinNewFileMenu::deleteLater);
QMenu *menu = newFileMenu->menu();
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 4d3fedbce..37f328e96 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -1821,6 +1821,9 @@ void DolphinMainWindow::setupActions()
menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
m_newFileMenu->setPopupMode(QToolButton::InstantPopup);
connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateNewMenu);
+ connect(m_newFileMenu, &KNewFileMenu::directoryCreated, this, [this](const QUrl &createdDirectory) {
+ activeViewContainer()->view()->expandToUrl(createdDirectory);
+ });
QAction *newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
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);
}
}
}
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index 4c6db590d..b8e0e9893 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -696,6 +696,9 @@ void KFileItemModelTest::testExpandParentItems()
// Expand the parents of "a2/b2/c2".
m_model->expandParentDirectories(QUrl::fromLocalFile(m_testDir->path() + "a2/b2/c2"));
+ // a first load is occuring for a2/b2/
+ QVERIFY(loadingCompletedSpy.wait());
+ // a second load for a2/b2/c2/ expansion
QVERIFY(loadingCompletedSpy.wait());
// The model should now contain "a 1/", "a2/", "a2/b2/", and "a2/b2/c2/".
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index bc6759d4a..e471c198d 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -2725,4 +2725,11 @@ void DolphinView::setPreferredSortOrder(const QByteArray &role, Qt::SortOrder or
m_rolesSortOrder[role] = order;
}
+void DolphinView::expandToUrl(const QUrl &directory)
+{
+ if (viewMode() == Mode::DetailsView && DetailsModeSettings::expandableFolders()) {
+ m_model->expandParentDirectories(directory);
+ }
+}
+
#include "moc_dolphinview.cpp"
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index 55b6b5829..4918a7539 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -393,6 +393,11 @@ public:
*/
void setStatusBarOffset(int offset);
+ /**
+ * Expands to directory if in detail mode
+ */
+ void expandToUrl(const QUrl &directory);
+
public Q_SLOTS:
void reload();