From 44a1202682277a112588ab2c4b77ce8c31962590 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Tue, 10 Feb 2026 13:00:28 +0100 Subject: dolphinviewcontainer: let the user open a file that was a directory when trying to open a file as directory we run into a IsFile error and instead open the parent directory. this is a bit inconvenient when the user actually wants to open a file. allow them to redirect the request to the correct API instead. this ensures backwards compatible behavior but introduces new strings that require localization. ultimately being able to open files this way is a bit of any-feature though. CCBUG: 516830 --- src/dolphinviewcontainer.cpp | 21 +++++++++++++++++++++ src/dolphinviewcontainer.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 1126b992d..379c55649 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -731,6 +731,27 @@ void DolphinViewContainer::slotUrlIsFileError(const QUrl &url) const KFileItem item(url); setUrl(KIO::upUrl(item.url())); + + if (!m_openAsFile) { + m_openAsFile = [this, item] { + auto action = new QAction(i18nc("@action", "Open as File"), this); + connect(action, &QAction::triggered, this, [this, item]() { + m_messageWidget->animatedHide(); + + // Find out if the file can be opened in the view (for example, this is the + // case if the file is an archive). The mime type must be known for that. + item.determineMimeType(); + const QUrl &folderUrl = DolphinView::openItemAsFolderUrl(item, true); + if (!folderUrl.isEmpty()) { + setUrl(folderUrl); + } else { + slotItemActivated(item); + } + }); + return action; + }(); + } + showMessage(xi18nc("@info", "Trying to open a file as a folder: %1", item.url().toString()), KMessageWidget::Error, {m_openAsFile}); } void DolphinViewContainer::slotItemActivated(const KFileItem &item) diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 09413ba55..8ff1c59e0 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -497,6 +497,8 @@ private: QAction *m_authorizeToEnterFolderAction; /// An action to create new folder in case user enters a nonexistent URL in the location bar. QAction *m_createFolderAction; + /// An action to open the url as file instead of as directory. Lazily initialized. + QAction *m_openAsFile = nullptr; KMessageWidget *m_messageWidget; -- cgit v1.3