diff --git a/addons/project/kateprojecttreeviewcontextmenu.cpp b/addons/project/kateprojecttreeviewcontextmenu.cpp --- a/addons/project/kateprojecttreeviewcontextmenu.cpp +++ b/addons/project/kateprojecttreeviewcontextmenu.cpp @@ -21,21 +21,23 @@ #include "kateprojecttreeviewcontextmenu.h" #include +#include #include #include #include #include -#include -#include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include +#include #include +#include +#include +#include KateProjectTreeViewContextMenu::KateProjectTreeViewContextMenu() { @@ -65,46 +67,47 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint &pos, QWidget *parent) { /** - * create context menu + * Create context menu */ QMenu menu; + /** + * Copy Path + */ QAction *copyAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy File Path")); - + /** - * handle "open with" + * Handle "open with", * find correct mimetype to query for possible applications */ QMenu *openWithMenu = menu.addMenu(i18n("Open With")); QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename); KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("Application")); - - /** - * for each one, insert a menu item... - */ + // For each one, insert a menu item... for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) { KService::Ptr service = *it; if (service->name() == QStringLiteral("Kate")) { continue; // omit Kate } QAction *action = openWithMenu->addAction(QIcon::fromTheme(service->icon()), service->name()); action->setData(service->entryPath()); } + // Perhaps disable menu, if no entries + openWithMenu->setEnabled(!openWithMenu->isEmpty()); /** - * perhaps disable menu, if no entries! + * Open Containing folder */ - openWithMenu->setEnabled(!openWithMenu->isEmpty()); + auto openContaingFolderAction = menu.addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("&Open Containing Folder")); + /** + * Git menu + */ KMoreToolsMenuFactory menuFactory(QLatin1String("kate/addons/project/git-tools")); - QMenu gitMenu; // must live as long as the maybe filled menu items should live - if (isGit(filename)) { - menuFactory.fillMenuFromGroupingNames(&gitMenu, { QLatin1String("git-clients-and-actions") }, QUrl::fromLocalFile(filename)); - menu.addSection(i18n("Git:")); Q_FOREACH(auto action, gitMenu.actions()) { menu.addAction(action); @@ -114,19 +117,24 @@ /** * run menu and handle the triggered action */ - if (QAction *action = menu.exec(pos)) { - - // handle apps - if (copyAction == action) { + if (QAction* const action = menu.exec(pos)) { + if (action == copyAction) { QApplication::clipboard()->setText(filename); - } else { + } + else if (action->parentWidget() == openWithMenu) { // handle "open with" const QString openWith = action->data().toString(); if (KService::Ptr app = KService::serviceByDesktopPath(openWith)) { QList list; list << QUrl::fromLocalFile(filename); KRun::runService(*app, list, parent); } } + else if (action == openContaingFolderAction) { + KIO::highlightInFileManager({ QUrl::fromLocalFile(filename) }); + } + else { + // One of the git actions was triggered + } } } diff --git a/kate/kateviewspace.cpp b/kate/kateviewspace.cpp --- a/kate/kateviewspace.cpp +++ b/kate/kateviewspace.cpp @@ -32,15 +32,10 @@ #include #include #include -// remove #ifdef, once Kate depends on KF 5.24 -#include -#if KIO_VERSION >= QT_VERSION_CHECK(5, 24, 0) #include -#endif #include #include -#include #include #include #include @@ -613,11 +608,7 @@ } else if (choice == aCopyPath) { QApplication::clipboard()->setText(doc->url().toDisplayString(QUrl::PreferLocalFile)); } else if (choice == aOpenFolder) { -#if KIO_VERSION >= QT_VERSION_CHECK(5, 24, 0) KIO::highlightInFileManager({doc->url()}); -#else - QDesktopServices::openUrl(doc->url().adjusted(QUrl::RemoveFilename)); -#endif } }