Commit c00f2af3 authored by Kåre Särs's avatar Kåre Särs

S&R: Fix sorting of result files + add delay to allow stop clicks

parent c7faf7e5
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
#include <QDir> #include <QDir>
#include <QTextStream> #include <QTextStream>
SearchDiskFiles::SearchDiskFiles(QObject *parent) : QThread(parent), m_cancelSearch(true) {} SearchDiskFiles::SearchDiskFiles(QObject *parent) : QThread(parent)
,m_cancelSearch(true)
,m_matchCount(0)
{}
SearchDiskFiles::~SearchDiskFiles() SearchDiskFiles::~SearchDiskFiles()
{ {
...@@ -43,7 +46,7 @@ void SearchDiskFiles::startSearch(const QStringList &files, ...@@ -43,7 +46,7 @@ void SearchDiskFiles::startSearch(const QStringList &files,
m_cancelSearch = false; m_cancelSearch = false;
m_files = files; m_files = files;
m_regExp = regexp; m_regExp = regexp;
m_matchCount = 0;
start(); start();
} }
...@@ -96,6 +99,10 @@ void SearchDiskFiles::searchSingleLineRegExp(const QString &fileName) ...@@ -96,6 +99,10 @@ void SearchDiskFiles::searchSingleLineRegExp(const QString &fileName)
if (line.length() > 512) line = line.left(512); if (line.length() > 512) line = line.left(512);
emit matchFound(fileName, i, column, line, m_regExp.matchedLength()); emit matchFound(fileName, i, column, line, m_regExp.matchedLength());
column = m_regExp.indexIn(line, column + m_regExp.cap().size()); column = m_regExp.indexIn(line, column + m_regExp.cap().size());
m_matchCount++;
// NOTE: This sleep is here so that the main thread will get a chance to
// handle any stop button clicks if there are a lot of matches
if (m_matchCount%100) msleep(0);
} }
i++; i++;
} }
...@@ -154,6 +161,10 @@ void SearchDiskFiles::searchMultiLineRegExp(const QString &fileName) ...@@ -154,6 +161,10 @@ void SearchDiskFiles::searchMultiLineRegExp(const QString &fileName)
fullDoc.mid(lineStart[line], column - lineStart[line])+tmpRegExp.cap(), fullDoc.mid(lineStart[line], column - lineStart[line])+tmpRegExp.cap(),
tmpRegExp.matchedLength()); tmpRegExp.matchedLength());
column = tmpRegExp.indexIn(fullDoc, column + tmpRegExp.matchedLength()); column = tmpRegExp.indexIn(fullDoc, column + tmpRegExp.matchedLength());
m_matchCount++;
// NOTE: This sleep is here so that the main thread will get a chance to
// handle any stop button clicks if there are a lot of matches
if (m_matchCount%100) msleep(0);
} }
} }
...@@ -58,6 +58,7 @@ private: ...@@ -58,6 +58,7 @@ private:
QRegExp m_regExp; QRegExp m_regExp;
QStringList m_files; QStringList m_files;
bool m_cancelSearch; bool m_cancelSearch;
int m_matchCount;
}; };
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
TreeWidgetItem(QTreeWidgetItem* parent, const QStringList &list):QTreeWidgetItem(parent, list){} TreeWidgetItem(QTreeWidgetItem* parent, const QStringList &list):QTreeWidgetItem(parent, list){}
private: private:
bool operator<(const QTreeWidgetItem &other)const { bool operator<(const QTreeWidgetItem &other)const {
if (parent()) { if (childCount() == 0) {
int line = data(1, Qt::UserRole).toInt(); int line = data(1, Qt::UserRole).toInt();
int column = data(2, Qt::UserRole).toInt(); int column = data(2, Qt::UserRole).toInt();
int oLine = other.data(1, Qt::UserRole).toInt(); int oLine = other.data(1, Qt::UserRole).toInt();
...@@ -281,6 +281,7 @@ m_projectPluginView(0) ...@@ -281,6 +281,7 @@ m_projectPluginView(0)
connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchOpenFiles, SLOT(cancelSearch())); connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchOpenFiles, SLOT(cancelSearch()));
connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchDiskFiles, SLOT(cancelSearch())); connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchDiskFiles, SLOT(cancelSearch()));
connect(m_ui.stopButton, SIGNAL(clicked()), &m_folderFilesList, SLOT(cancelSearch())); connect(m_ui.stopButton, SIGNAL(clicked()), &m_folderFilesList, SLOT(cancelSearch()));
connect(m_ui.stopButton, SIGNAL(clicked()), &m_replacer, SLOT(cancelReplace()));
connect(m_ui.nextButton, SIGNAL(clicked()), this, SLOT(goToNextMatch())); connect(m_ui.nextButton, SIGNAL(clicked()), this, SLOT(goToNextMatch()));
...@@ -559,6 +560,7 @@ void KatePluginSearchView::addHeaderItem(const QString& text) ...@@ -559,6 +560,7 @@ void KatePluginSearchView::addHeaderItem(const QString& text)
QTreeWidgetItem *item = new QTreeWidgetItem(m_curResults->tree, QStringList(text)); QTreeWidgetItem *item = new QTreeWidgetItem(m_curResults->tree, QStringList(text));
item->setCheckState(0, Qt::Checked); item->setCheckState(0, Qt::Checked);
item->setFlags(item->flags() | Qt::ItemIsTristate); item->setFlags(item->flags() | Qt::ItemIsTristate);
m_curResults->tree->expandItem(item);
} }
...@@ -782,6 +784,7 @@ void KatePluginSearchView::startSearch() ...@@ -782,6 +784,7 @@ void KatePluginSearchView::startSearch()
m_ui.replaceCheckedBtn->setDisabled(true); m_ui.replaceCheckedBtn->setDisabled(true);
m_ui.replaceButton->setDisabled(true); m_ui.replaceButton->setDisabled(true);
m_ui.nextAndStop->setCurrentIndex(1); m_ui.nextAndStop->setCurrentIndex(1);
m_ui.replaceCombo->setDisabled(true);
QRegExp reg(m_ui.searchCombo->currentText(), QRegExp reg(m_ui.searchCombo->currentText(),
...@@ -926,6 +929,7 @@ void KatePluginSearchView::searchDone() ...@@ -926,6 +929,7 @@ void KatePluginSearchView::searchDone()
m_ui.searchButton->setDisabled(false); m_ui.searchButton->setDisabled(false);
m_ui.nextAndStop->setCurrentIndex(0); m_ui.nextAndStop->setCurrentIndex(0);
m_ui.displayOptions->setDisabled(false); m_ui.displayOptions->setDisabled(false);
m_ui.replaceCombo->setDisabled(false);
if (!m_curResults) { if (!m_curResults) {
return; return;
......
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