- if (!selectedItems.isEmpty()) {
- // We are going to add the actions from the right-click context menu for the selected items.
- auto *dolphinMainWindow = qobject_cast<DolphinMainWindow *>(window());
- Q_CHECK_PTR(dolphinMainWindow);
- if (!m_fileItemActions) {
- m_fileItemActions = new KFileItemActions(this);
- m_fileItemActions->setParentWidget(dolphinMainWindow);
- connect(m_fileItemActions, &KFileItemActions::error, this, &SelectionModeBottomBar::error);
+ // We are going to add the actions from the right-click context menu for the selected items.
+ auto *dolphinMainWindow = qobject_cast<DolphinMainWindow *>(window());
+ Q_CHECK_PTR(dolphinMainWindow);
+ if (!m_fileItemActions) {
+ m_fileItemActions = new KFileItemActions(this);
+ m_fileItemActions->setParentWidget(dolphinMainWindow);
+ connect(m_fileItemActions, &KFileItemActions::error, this, &SelectionModeBottomBar::error);
+ }
+ m_internalContextMenu = std::make_unique<DolphinContextMenu>(dolphinMainWindow, selectedItems.constFirst(), selectedItems, baseUrl, m_fileItemActions);
+ auto internalContextMenuActions = m_internalContextMenu->actions();
+
+ // There are some actions which we wouldn't want to add. We remember them in the actionsThatShouldntBeAdded set.
+ // We don't want to add the four basic actions again which were already added to the top.
+ std::unordered_set<QAction *> actionsThatShouldntBeAdded{contextActions.begin(), contextActions.end()};
+ // "Delete" isn't really necessary to add because we have "Move to Trash" already. It is also more dangerous so let's exclude it.
+ actionsThatShouldntBeAdded.insert(m_actionCollection->action(KStandardAction::name(KStandardAction::DeleteFile)));
+
+ // KHamburgerMenu would only be visible if there is no menu available anywhere on the user interface. This might be useful for recovery from
+ // such a situation in theory but a bar with context dependent actions doesn't really seem like the right place for it.
+ Q_ASSERT(internalContextMenuActions.first()->icon().name() == m_actionCollection->action(KStandardAction::name(KStandardAction::HamburgerMenu))->icon().name());
+ internalContextMenuActions.removeFirst();
+
+ for (auto it = internalContextMenuActions.constBegin(); it != internalContextMenuActions.constEnd(); ++it) {
+ if (actionsThatShouldntBeAdded.count(*it)) {
+ continue; // Skip this action.