+
+ // 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)
+{
+ QAction *action = actionCollection()->action(viewModeName);
+ Q_ASSERT(action);
+ action->trigger();
+}
+
+QString DolphinPart::currentViewMode() const
+{
+ return m_actionHandler->currentViewModeActionName();
+}
+
+void DolphinPart::setNameFilter(const QString &nameFilter)
+{
+ // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
+ // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
+ m_nameFilter = nameFilter;
+ // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
+}
+
+QString DolphinPart::localFilePathOrHome() const
+{
+ const QString localPath = localFilePath();
+ if (!localPath.isEmpty()) {
+ return localPath;
+ }
+ return QDir::homePath();
+}
+
+void DolphinPart::slotOpenTerminal()
+{
+ auto job = new KTerminalLauncherJob(QString());
+ job->setWorkingDirectory(localFilePathOrHome());
+ job->start();
+}
+
+void DolphinPart::slotFindFile()
+{
+ QMenu searchTools;
+ KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&searchTools, {"files-find"}, QUrl::fromLocalFile(localFilePathOrHome()));
+ QList<QAction *> actions = searchTools.actions();
+ if (!(actions.isEmpty())) {
+ actions.first()->trigger();