+void DolphinPart::slotItemsActivated(const KFileItemList& items)
+{
+ for (const KFileItem& item : items) {
+ slotItemActivated(item);
+ }
+}
+
+void DolphinPart::createNewWindow(const QUrl& url)
+{
+ // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
+ // should be moved into DolphinPart::slotItemActivated()
+ Q_EMIT m_extension->createNewWindow(url);
+}
+
+void DolphinPart::slotOpenContextMenu(const QPoint& pos,
+ const KFileItem& _item,
+ const QUrl &,
+ const QList<QAction*>& customActions)
+{
+ KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::DefaultPopupItems
+ | KParts::BrowserExtension::ShowProperties
+ | KParts::BrowserExtension::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)
+ }
+
+ // TODO: We should change the signature of the slots (and signals) for being able
+ // to tell for which items we want a popup.
+ KFileItemList items;
+ if (m_view->selectedItems().isEmpty()) {
+ items.append(item);
+ } else {
+ items = m_view->selectedItems();
+ }
+
+ KFileItemListProperties capabilities(items);
+
+ KParts::BrowserExtension::ActionGroupMap actionGroups;
+ QList<QAction *> editActions;
+ editActions += m_view->versionControlActions(m_view->selectedItems());
+ editActions += customActions;
+
+ 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("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::BrowserExtension::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::BrowserExtension::ShowCreateDirectory;
+
+ }
+
+ actionGroups.insert(QStringLiteral("editactions"), editActions);
+
+ Q_EMIT m_extension->popupMenu(pos,
+ items,
+ KParts::OpenUrlArguments(),
+ KParts::BrowserArguments(),
+ 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);
+}
+
+void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
+{
+ auto *dialog = new QInputDialog(m_view);
+ dialog->setAttribute(Qt::WA_DeleteOnClose, true);
+ dialog->setInputMode(QInputDialog::TextInput);
+ dialog->setWindowTitle(title);
+ dialog->setLabelText(text);
+
+ const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
+ dialog->setComboBoxEditable(true);
+ dialog->setComboBoxItems(group.readEntry("History", QStringList()));
+
+ dialog->setTextValue(QStringLiteral("*"));
+
+ connect(dialog, &QDialog::accepted, this, [=]() {
+ const QString pattern = dialog->textValue();
+ if (!pattern.isEmpty()) {
+ QStringList items = dialog->comboBoxItems();
+ items.removeAll(pattern);
+ items.prepend(pattern);
+
+ // Need to evaluate this again here, because the captured value is const
+ // (even if the const were removed from 'const KConfigGroup group =' above).
+ KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
+ // Limit the size of the saved history.
+ group.writeEntry("History", items.mid(0, 10));
+ group.sync();
+
+ const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern));
+ m_view->selectItems(patternRegExp, selectItems);
+ }
+ });
+
+ dialog->open();
+}
+
+void DolphinPart::setCurrentViewMode(const QString& viewModeName)