diff options
| author | Harald Sitter <[email protected]> | 2026-02-10 13:00:28 +0100 |
|---|---|---|
| committer | Harald Sitter <[email protected]> | 2026-03-02 15:33:56 +0100 |
| commit | 44a1202682277a112588ab2c4b77ce8c31962590 (patch) | |
| tree | 4153d96fc0462dce91421c7c79b9c0022784740a | |
| parent | 4a4da5f73899cdd2a1ef111194e79a620eed7716 (diff) | |
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
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 21 | ||||
| -rw-r--r-- | src/dolphinviewcontainer.h | 2 |
2 files changed, 23 insertions, 0 deletions
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: <filename>%1</filename>", 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; |
