Commit 62ebef90 authored by Tomaz  Canabrava's avatar Tomaz Canabrava Committed by Tomaz Canabrava
Browse files

Allow "open with" menu to open displayed files in konsole

parent 9c9cde04
......@@ -37,6 +37,9 @@
// KDE
#include <KLocalizedString>
#include <KRun>
#include <KFileItem>
#include <KFileItemListProperties>
#include <KFileItemActions>
// Konsole
#include "Session.h"
......@@ -544,13 +547,26 @@ FileFilter::HotSpot::~HotSpot() = default;
QList<QAction *> FileFilter::HotSpot::actions()
{
auto openAction = new QAction(this);
openAction->setText(i18n("Open File"));
QObject::connect(openAction, &QAction::triggered, this, [this ]{ activate(); });
return {openAction};
return {};
}
void FileFilter::HotSpot::setupMenu(QMenu *menu)
{
menu->addAction(QStringLiteral("Teste"));
// We are reusing the QMenu, but we need to update the actions anyhow.
// Remove the 'Open with' actions from it, then add the new ones.
QList<QAction*> toDelete;
for (auto *action : menu->actions()) {
qDebug() << "Action:" << action->text();
if (action->text().toLower().remove(QLatin1Char('&')).contains(i18n("open with"))) {
toDelete.append(action);
}
}
qDeleteAll(toDelete);
const KFileItem fileItem(QUrl::fromLocalFile(_filePath));
const KFileItemList itemList({fileItem});
const KFileItemListProperties itemProperties(itemList);
_menuActions.setParent(this);
_menuActions.setItemListProperties(itemProperties);
_menuActions.addOpenWithActionsTo(menu);
}
......@@ -29,6 +29,9 @@
#include <QRegularExpression>
#include <QMultiHash>
// KDE
#include <KFileItemActions>
#include <memory>
// Konsole
......@@ -315,6 +318,7 @@ public:
void setupMenu(QMenu *menu) override;
private:
QString _filePath;
KFileItemActions _menuActions;
};
explicit FileFilter(Session *session);
......
......@@ -1721,6 +1721,7 @@ void SessionController::showDisplayContextMenu(const QPoint& position)
QSharedPointer<Filter::HotSpot> hotSpot = _view->filterActions(position);
if (hotSpot != nullptr) {
popup->insertActions(popup->actions().value(0, nullptr), hotSpot->actions() << contentSeparator );
popup->addAction(contentSeparator);
hotSpot->setupMenu(popup.data());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment