From 60e109632fd63b335ca1cc037c5d5c3e291349f5 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Sun, 2 Nov 2025 15:49:47 +0100 Subject: context menu: use selected item as containing folder for New file menu Use current view url as fallback. Don't update the selection after a directory is created, except if there was no selection. CCBUG: 508196 BUG: 512020 --- src/dolphinmainwindow.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/dolphinmainwindow.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index dd11b67f7..72ed98f77 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -830,7 +830,14 @@ void DolphinMainWindow::createDirectory() // just check if we are already running one. This prevents opening multiple // dialogs. BUG:481401 if (!m_newFileMenu->isCreateDirectoryRunning()) { - m_newFileMenu->setWorkingDirectory(activeViewContainer()->url()); + QUrl targetDirectory = activeViewContainer()->view()->url(); + if (const auto itemOpt = activeViewContainer()->view()->firstSelectedItem()) { + if (itemOpt->isDir()) { + targetDirectory = itemOpt->url(); + } + } + + m_newFileMenu->setWorkingDirectory(targetDirectory); m_newFileMenu->createDirectory(); } } @@ -839,7 +846,14 @@ void DolphinMainWindow::createFile() { // Use the same logic as in createDirectory() if (!m_newFileMenu->isCreateFileRunning()) { - m_newFileMenu->setWorkingDirectory(activeViewContainer()->url()); + QUrl targetDirectory = activeViewContainer()->view()->url(); + if (const auto itemOpt = activeViewContainer()->view()->firstSelectedItem()) { + if (itemOpt->isDir()) { + targetDirectory = itemOpt->url(); + } + } + + m_newFileMenu->setWorkingDirectory(targetDirectory); m_newFileMenu->createFile(); } } -- cgit v1.3