]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinpart.cpp
Don't trigger rubberband with back/foward mouse buttons
[dolphin.git] / src / dolphinpart.cpp
index dc083f1a5563e90a1067af282b3cae901da8e450..5d41881516af79ec9ebef551efe82dbd2638d97b 100644 (file)
@@ -1,20 +1,7 @@
 /* This file is part of the KDE project
-   Copyright (c) 2007 David Faure <faure@kde.org>
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public
-   License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public License
-   along with this library; see the file COPYING.LIB.  If not, write to
-   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.
+   SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
+
+   SPDX-License-Identifier: LGPL-2.0-or-later
 */
 
 #include "dolphinpart.h"
@@ -34,6 +21,7 @@
 #include <KActionCollection>
 #include <KAuthorized>
 #include <KConfigGroup>
+#include <KDialogJobUiDelegate>
 #include <KFileItemListProperties>
 #include <KIconLoader>
 #include <KJobWidgets>
@@ -42,7 +30,7 @@
 #include <KMimeTypeEditor>
 #include <KNS3/KMoreToolsMenuFactory>
 #include <KPluginFactory>
-#include <KRun>
+#include <KIO/CommandLauncherJob>
 #include <KSharedConfig>
 #include <KToolInvocation>
 
@@ -53,6 +41,7 @@
 #include <QInputDialog>
 #include <QKeyEvent>
 #include <QMenu>
+#include <QRegularExpression>
 #include <QStandardPaths>
 #include <QTextDocument>
 
@@ -502,13 +491,38 @@ void DolphinPart::slotUnselectItemsMatchingPattern()
 
 void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
 {
-    bool okClicked;
-    const QString pattern = QInputDialog::getText(m_view, title, text, QLineEdit::Normal, QStringLiteral("*"), &okClicked);
+    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);
+        }
+    });
 
-    if (okClicked && !pattern.isEmpty()) {
-        QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
-        m_view->selectItems(patternRegExp, selectItems);
-    }
+    dialog->open();
 }
 
 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
@@ -533,23 +547,7 @@ void DolphinPart::setNameFilter(const QString& nameFilter)
 
 void DolphinPart::slotOpenTerminal()
 {
-    QString dir(QDir::homePath());
-
-    QUrl u(url());
-
-    // If the given directory is not local, it can still be the URL of an
-    // ioslave using UDS_LOCAL_PATH which to be converted first.
-    KIO::StatJob* statJob = KIO::mostLocalUrl(u);
-    KJobWidgets::setWindow(statJob, widget());
-    statJob->exec();
-    u = statJob->mostLocalUrl();
-
-    //If the URL is local after the above conversion, set the directory.
-    if (u.isLocalFile()) {
-        dir = u.toLocalFile();
-    }
-
-    KToolInvocation::invokeTerminal(QString(), dir);
+    KToolInvocation::invokeTerminal(QString(), KParts::ReadOnlyPart::localFilePath());
 }
 
 void DolphinPart::slotFindFile()
@@ -562,7 +560,10 @@ void DolphinPart::slotFindFile()
     if (!(actions.isEmpty())) {
         actions.first()->trigger();
     } else {
-        KRun::run(QStringLiteral("kfind"), {url()}, widget());
+        KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
+        job->setDesktopName(QStringLiteral("org.kde.kfind"));
+        job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
+        job->start();
     }
 }
 
@@ -572,7 +573,7 @@ void DolphinPart::updateNewMenu()
     m_newFileMenu->checkUpToDate();
     m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
     // And set the files that the menu apply on :
-    m_newFileMenu->setPopupFiles(url());
+    m_newFileMenu->setPopupFiles(QList<QUrl>() << url());
 }
 
 void DolphinPart::updateStatusBar()
@@ -589,7 +590,7 @@ void DolphinPart::updateProgress(int percent)
 void DolphinPart::createDirectory()
 {
     m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
-    m_newFileMenu->setPopupFiles(url());
+    m_newFileMenu->setPopupFiles(QList<QUrl>() << url());
     m_newFileMenu->createDirectory();
 }