Commit e3a5c10b authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Make HotSpot::setupMenu() return a list of the added actions

Useful when removing the open-with actions from the session menu before
adding new ones.
parent 8f60e2f8
......@@ -177,8 +177,10 @@ QList<QAction *> FileFilterHotSpot::actions()
return {action};
}
void FileFilterHotSpot::setupMenu(QMenu *menu)
QList<QAction *> FileFilterHotSpot::setupMenu(QMenu *menu)
{
const QList<QAction *> currentActions = menu->actions();
const KFileItem fileItem(QUrl::fromLocalFile(_filePath));
const KFileItemList itemList({fileItem});
const KFileItemListProperties itemProperties(itemList);
......@@ -204,6 +206,14 @@ void FileFilterHotSpot::setupMenu(QMenu *menu)
const QList<QAction *> actionList = menu->actions();
_menuActions.insertOpenWithActionsTo(!actionList.isEmpty() ? actionList.at(0) : nullptr, menu, QStringList());
#endif
QList<QAction *> addedActions = menu->actions();
// addedActions will only contain the open-with actions
for (auto *act : currentActions) {
addedActions.removeOne(act);
}
return addedActions;
}
// Static variables for the HotSpot
......
......@@ -43,7 +43,7 @@ public:
* Opens kate for editing the file.
*/
void activate(QObject *object = nullptr) override;
void setupMenu(QMenu *menu) override;
QList<QAction *> setupMenu(QMenu *menu) override;
KFileItem fileItem() const;
void requestThumbnail(Qt::KeyboardModifiers modifiers, const QPoint &pos);
......
......@@ -32,9 +32,9 @@ QList<QAction *> HotSpot::actions()
return {};
}
void HotSpot::setupMenu(QMenu *)
QList<QAction *> HotSpot::setupMenu(QMenu *)
{
return {};
}
int HotSpot::startLine() const
......
......@@ -96,9 +96,15 @@ public:
virtual void startDrag();
/**
* Setups a menu with actions for the hotspot.
*/
virtual void setupMenu(QMenu *menu);
* Sets a menu up with actions for the hotspot.
*
* Returns a list of the added actions (useful for removing e.g.
* the open-with actions before adding new ones to prevent duplicate
* open-with actions being shown in @p menu).
*
* The base implementation does nothing.
*/
virtual QList<QAction *> setupMenu(QMenu *menu);
QPair<QRegion, QRect> region(int fontWidth, int fontHeight, int columns, QRect terminalDisplayRect) const;
......
......@@ -1790,12 +1790,13 @@ void SessionController::showDisplayContextMenu(const QPoint& position)
copy->setShortcut(Konsole::ACCEL | Qt::SHIFT | Qt::Key_C);
#endif
QList<QAction *> toRemove;
// prepend content-specific actions such as "Open Link", "Copy Email Address" etc
QSharedPointer<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());
toRemove = hotSpot->setupMenu(popup.data());
}
// always update this submenu before showing the context menu,
......@@ -1821,11 +1822,8 @@ void SessionController::showDisplayContextMenu(const QPoint& position)
if (!popup.isNull()) {
delete contentSeparator;
// Remove the 'Open with' actions from it.
const auto actList = popup->actions();
for (auto *action : actList) {
if (action->text().toLower().remove(QLatin1Char('&')).contains(i18n("open with"))) {
popup->removeAction(action);
}
for (auto *act : toRemove) {
popup->removeAction(act);
}
// Remove the Accelerator for the copy shortcut so we don't have two actions with same shortcut.
......
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