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.
This commit is contained in:
Ahmad Samir
2021-08-20 21:51:17 +02:00
parent 8f60e2f8af
commit e3a5c10bb6
5 changed files with 27 additions and 13 deletions

View File

@@ -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.