+ KParts::NavigationExtension::PopupFlags popupFlags =
+ KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
+
+ KFileItem item(_item);
+
+ if (item.isNull()) { // viewport context menu
+ item = m_view->rootItem();
+ if (item.isNull())
+ item = KFileItem(url());
+ else
+ item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
+ }
+
+ KFileItemList items;
+ if (selectedItems.isEmpty()) {
+ items.append(item);
+ } else {
+ items = selectedItems;
+ }
+
+ KFileItemListProperties capabilities(items);
+
+ KParts::NavigationExtension::ActionGroupMap actionGroups;
+ QList<QAction *> editActions;
+ editActions += m_view->versionControlActions(m_view->selectedItems());
+
+ if (!_item.isNull()) { // only for context menu on one or more items
+ const bool supportsMoving = capabilities.supportsMoving();
+
+ if (capabilities.supportsDeleting()) {
+ const bool showDeleteAction =
+ (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
+ const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
+
+ if (showDeleteAction && showMoveToTrashAction) {
+ delete m_removeAction;
+ m_removeAction = nullptr;
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
+ } else if (showDeleteAction && !showMoveToTrashAction) {
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
+ } else {
+ if (!m_removeAction)
+ m_removeAction = new DolphinRemoveAction(this, actionCollection());
+ editActions.append(m_removeAction);
+ m_removeAction->update();
+ }
+ } else {
+ popupFlags |= KParts::NavigationExtension::NoDeletion;
+ }
+
+ if (supportsMoving) {
+ editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
+ }
+
+ // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
+ // since otherwise the created file would not be visible.
+ // But in treeview mode we should allow it.
+ if (m_view->itemsExpandable())
+ popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
+ }
+
+ actionGroups.insert(QStringLiteral("editactions"), editActions);
+
+ Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), popupFlags, actionGroups);
+}
+
+void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
+{
+ qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
+ if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
+ KParts::ReadOnlyPart::setUrl(newUrl);
+ const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
+ Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
+ }
+}
+
+void DolphinPart::slotEditMimeType()
+{
+ const KFileItemList items = m_view->selectedItems();
+ if (!items.isEmpty()) {
+ KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
+ }
+}
+
+void DolphinPart::slotSelectItemsMatchingPattern()
+{
+ openSelectionDialog(i18nc("@title:window", "Select"), i18n("Select all items matching this pattern:"), true);
+}
+
+void DolphinPart::slotUnselectItemsMatchingPattern()
+{
+ openSelectionDialog(i18nc("@title:window", "Unselect"), i18n("Unselect all items matching this pattern:"), false);