#include "global.h"
#include "trash/dolphintrash.h"
#include "views/dolphinview.h"
-#include "views/viewmodecontroller.h"
#include <KActionCollection>
#include <KFileItemListProperties>
m_context |= SearchContext;
} else if (scheme.contains(QLatin1String("timeline"))) {
m_context |= TimelineContext;
+ } else if (scheme == QStringLiteral("recentlyused")) {
+ m_context |= RecentlyUsedContext;
}
if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) {
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
}
+ if (ContextMenuSettings::showOpenInSplitView()) {
+ addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_split_view")));
+ }
+
// Insert 'Open With' entries
addOpenWithActions();
addSeparator();
}
+void DolphinContextMenu::addOpenParentFolderActions()
+{
+ addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18nc("@action:inmenu", "Open Path"), [this]() {
+ const QUrl url = m_fileInfo.targetUrl();
+ const QUrl parentUrl = KIO::upUrl(url);
+ m_mainWindow->changeUrl(parentUrl);
+ m_mainWindow->activeViewContainer()->view()->markUrlsAsSelected({url});
+ m_mainWindow->activeViewContainer()->view()->markUrlAsCurrent(url);
+ });
+
+ addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@action:inmenu", "Open Path in New Tab"), [this]() {
+ m_mainWindow->openNewTab(KIO::upUrl(m_fileInfo.targetUrl()));
+ });
+
+ addAction(QIcon::fromTheme(QStringLiteral("window-new")), i18nc("@action:inmenu", "Open Path in New Window"), [this]() {
+ Dolphin::openNewWindow({m_fileInfo.targetUrl()}, m_mainWindow, Dolphin::OpenNewWindowFlag::Select);
+ });
+}
+
void DolphinContextMenu::addItemContextMenu()
{
Q_ASSERT(!m_fileInfo.isNull());
// single files
if (m_fileInfo.isDir()) {
addDirectoryItemContextMenu();
- } else if (m_context & TimelineContext || m_context & SearchContext) {
+ } else if (m_context & TimelineContext || m_context & SearchContext || m_context & RecentlyUsedContext) {
addOpenWithActions();
- addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18nc("@action:inmenu", "Open Path"), [this]() {
- m_mainWindow->changeUrl(KIO::upUrl(m_fileInfo.url()));
- m_mainWindow->activeViewContainer()->view()->markUrlsAsSelected({m_fileInfo.url()});
- m_mainWindow->activeViewContainer()->view()->markUrlAsCurrent(m_fileInfo.url());
- });
-
- addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@action:inmenu", "Open Path in New Tab"), [this]() {
- m_mainWindow->openNewTab(KIO::upUrl(m_fileInfo.url()));
- });
-
- addAction(QIcon::fromTheme(QStringLiteral("window-new")), i18nc("@action:inmenu", "Open Path in New Window"), [this]() {
- Dolphin::openNewWindow({m_fileInfo.url()}, m_mainWindow, Dolphin::OpenNewWindowFlag::Select);
- });
+ addOpenParentFolderActions();
addSeparator();
} else {
addSeparator();
// Insert 'Move to Trash' and/or 'Delete'
- const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) || !properties.isLocal());
+ const bool showDeleteAction = (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !properties.isLocal());
const bool showMoveToTrashAction = (properties.isLocal() && properties.supportsMoving());
if (showDeleteAction && showMoveToTrashAction) {
{
const KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
- const auto &matchedPlaces = placesModel->match(placesModel->index(0, 0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
-
- return !matchedPlaces.isEmpty();
+ QModelIndex url_index = placesModel->closestItem(url);
+ return url_index.isValid() && placesModel->url(url_index).matches(url, QUrl::StripTrailingSlash);
}
QAction *DolphinContextMenu::createPasteAction()
{
// insert 'Open With...' action or sub menu
m_fileItemActions->insertOpenWithActionsTo(nullptr, this, QStringList{qApp->desktopFileName()});
+
+ // For a single file, hint in "Open with" menu that middle-clicking would open it in the secondary app.
+ // (Unless middle-clicking would open it as a folder in a new tab (e.g. archives).)
+ const QUrl &url = DolphinView::openItemAsFolderUrl(m_fileInfo, GeneralSettings::browseThroughArchives());
+ if (m_selectedItems.count() == 1 && url.isEmpty()) {
+ if (QAction *openWithSubMenu = findChild<QAction *>(QStringLiteral("openWith_submenu"))) {
+ Q_ASSERT(openWithSubMenu->menu());
+ Q_ASSERT(!openWithSubMenu->menu()->isEmpty());
+
+ auto *secondaryApp = openWithSubMenu->menu()->actions().first();
+ // Add it like a keyboard shortcut, Qt uses \t as a separator.
+ if (!secondaryApp->text().contains(QLatin1Char('\t'))) {
+ secondaryApp->setText(secondaryApp->text() + QLatin1Char('\t')
+ + i18nc("@action:inmenu Shortcut, middle click to trigger menu item, keep short", "Middle Click"));
+ }
+ }
+ }
}
void DolphinContextMenu::addAdditionalActions(const KFileItemListProperties &props)
const DolphinView *view = m_mainWindow->activeViewContainer()->view();
const QList<QAction *> versionControlActions = view->versionControlActions(m_selectedItems);
if (!versionControlActions.isEmpty()) {
+ addSeparator();
addActions(versionControlActions);
addSeparator();
}