Commit c2c236c4 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

allow to ignore binary files for project based search, too

to simplify this, just delay the binary file detection until we do
the real on disk search

avoid an extra worker just to determine mime-type for projects
parent 5a8f57ba
......@@ -20,8 +20,6 @@
#include <QDebug>
#include <QDir>
#include <QFileInfoList>
#include <QMimeDatabase>
#include <QMimeType>
FolderFilesList::FolderFilesList(QObject *parent)
: QThread(parent)
......@@ -48,7 +46,7 @@ void FolderFilesList::run()
}
}
void FolderFilesList::generateList(const QString &folder, bool recursive, bool hidden, bool symlinks, bool binary, const QString &types, const QString &excludes)
void FolderFilesList::generateList(const QString &folder, bool recursive, bool hidden, bool symlinks, const QString &types, const QString &excludes)
{
m_cancelSearch = false;
m_folder = folder;
......@@ -58,7 +56,6 @@ void FolderFilesList::generateList(const QString &folder, bool recursive, bool h
m_recursive = recursive;
m_hidden = hidden;
m_symlinks = symlinks;
m_binary = binary;
m_types.clear();
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
......@@ -111,12 +108,6 @@ void FolderFilesList::checkNextItem(const QFileInfo &item)
emit searching(item.absoluteFilePath());
}
if (item.isFile()) {
if (!m_binary) {
QMimeType mimeType = QMimeDatabase().mimeTypeForFile(item);
if (!mimeType.inherits(QStringLiteral("text/plain"))) {
return;
}
}
m_files << item.canonicalFilePath();
} else {
QDir currentDir(item.absoluteFilePath());
......
......@@ -35,7 +35,7 @@ public:
void run() override;
void generateList(const QString &folder, bool recursive, bool hidden, bool symlinks, bool binary, const QString &types, const QString &excludes);
void generateList(const QString &folder, bool recursive, bool hidden, bool symlinks, const QString &types, const QString &excludes);
void terminateSearch();
......@@ -59,7 +59,6 @@ private:
bool m_recursive = false;
bool m_hidden = false;
bool m_symlinks = false;
bool m_binary = false;
QStringList m_types;
QVector<QRegExp> m_excludeList;
QElapsedTimer m_time;
......
......@@ -18,6 +18,7 @@
#include "SearchDiskFiles.h"
#include <QDir>
#include <QMimeDatabase>
#include <QTextStream>
#include <QUrl>
......@@ -32,12 +33,13 @@ SearchDiskFiles::~SearchDiskFiles()
wait();
}
void SearchDiskFiles::startSearch(const QStringList &files, const QRegularExpression &regexp)
void SearchDiskFiles::startSearch(const QStringList &files, const QRegularExpression &regexp, const bool includeBinaryFiles)
{
if (files.empty()) {
emit searchDone();
return;
}
m_includeBinaryFiles = includeBinaryFiles;
m_cancelSearch = false;
m_terminateSearch = false;
m_files = files;
......@@ -59,6 +61,14 @@ void SearchDiskFiles::run()
emit searching(fileName);
}
// exclude binary files?
if (!m_includeBinaryFiles) {
const auto mimeType = QMimeDatabase().mimeTypeForFile(fileName);
if (!mimeType.inherits(QStringLiteral("text/plain"))) {
continue;
}
}
if (m_regExp.pattern().contains(QLatin1String("\\n"))) {
searchMultiLineRegExp(fileName);
} else {
......
......@@ -34,7 +34,7 @@ public:
SearchDiskFiles(QObject *parent = nullptr);
~SearchDiskFiles() override;
void startSearch(const QStringList &iles, const QRegularExpression &regexp);
void startSearch(const QStringList &iles, const QRegularExpression &regexp, const bool includeBinaryFiles);
void run() override;
void terminateSearch();
......@@ -59,6 +59,7 @@ private:
bool m_terminateSearch = false;
int m_matchCount = 0;
QElapsedTimer m_statusTime;
bool m_includeBinaryFiles = false;
};
#endif
......@@ -769,13 +769,15 @@ void KatePluginSearchView::folderFileListChanged()
m_searchOpenFilesDone = true;
}
m_searchDiskFiles.startSearch(fileList, m_curResults->regExp);
m_searchDiskFiles.startSearch(fileList, m_curResults->regExp, m_ui.binaryCheckBox->isChecked());
}
void KatePluginSearchView::searchPlaceChanged()
{
int searchPlace = m_ui.searchPlaceCombo->currentIndex();
const bool inFolder = (searchPlace == Folder);
const bool inCurrentProject = searchPlace == Project;
const bool inAllOpenProjects = searchPlace == AllProjects;
m_ui.filterCombo->setEnabled(searchPlace >= Folder);
m_ui.excludeCombo->setEnabled(searchPlace >= Folder);
......@@ -785,7 +787,7 @@ void KatePluginSearchView::searchPlaceChanged()
m_ui.recursiveCheckBox->setEnabled(inFolder);
m_ui.hiddenCheckBox->setEnabled(inFolder);
m_ui.symLinkCheckBox->setEnabled(inFolder);
m_ui.binaryCheckBox->setEnabled(inFolder);
m_ui.binaryCheckBox->setEnabled(inFolder || inCurrentProject || inAllOpenProjects);
if (inFolder && sender() == m_ui.searchPlaceCombo) {
setCurrentFolder();
......@@ -1196,7 +1198,6 @@ void KatePluginSearchView::startSearch()
m_ui.recursiveCheckBox->isChecked(),
m_ui.hiddenCheckBox->isChecked(),
m_ui.symLinkCheckBox->isChecked(),
m_ui.binaryCheckBox->isChecked(),
m_ui.filterCombo->currentText(),
m_ui.excludeCombo->currentText());
// the file list will be ready when the thread returns (connected to folderFileListChanged)
......@@ -1245,7 +1246,7 @@ void KatePluginSearchView::startSearch()
} else {
m_searchOpenFilesDone = true;
}
m_searchDiskFiles.startSearch(files, reg);
m_searchDiskFiles.startSearch(files, reg, m_ui.binaryCheckBox->isChecked());
} else {
qDebug() << "Case not handled:" << m_ui.searchPlaceCombo->currentIndex();
Q_ASSERT_X(false, "KatePluginSearchView::startSearch", "case not handled");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment