Commit 894f1821 authored by Christoph Cullmann's avatar Christoph Cullmann

allow search plugin to search in project :)

parent 841f7b50
......@@ -14,6 +14,7 @@ set(katesearchplugin_PART_SRCS
plugin_search.cpp
search_open_files.cpp
search_folder.cpp
search_project.cpp
replace_matches.cpp
htmldelegate.cpp
)
......
......@@ -221,6 +221,7 @@ m_projectPluginView(0)
connect(m_ui.searchCombo, SIGNAL(editTextChanged(QString)), this, SLOT(searchPatternChanged()));
connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchOpenFiles, SLOT(cancelSearch()));
connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchFolder, SLOT(cancelSearch()));
connect(m_ui.stopButton, SIGNAL(clicked()), &m_searchProject, SLOT(cancelSearch()));
m_ui.displayOptions->setChecked(true);
......@@ -232,6 +233,10 @@ m_projectPluginView(0)
this, SLOT(matchFound(QString,int,int,QString,int)));
connect(&m_searchFolder, SIGNAL(searchDone()), this, SLOT(searchDone()));
connect(&m_searchProject, SIGNAL(matchFound(QString,int,int,QString,int)),
this, SLOT(matchFound(QString,int,int,QString,int)));
connect(&m_searchProject, SIGNAL(searchDone()), this, SLOT(searchDone()));
connect(m_kateApp->documentManager(), SIGNAL(documentWillBeDeleted(KTextEditor::Document*)),
&m_searchOpenFiles, SLOT(cancelSearch()));
......@@ -390,7 +395,7 @@ void KatePluginSearchView::startSearch()
if (m_ui.searchPlaceCombo->currentIndex() == 0) {
m_searchOpenFiles.startSearch(m_kateApp->documentManager()->documents(), reg);
}
else {
else if (m_ui.searchPlaceCombo->currentIndex() == 1) {
m_searchFolder.startSearch(m_ui.folderRequester->text(),
m_ui.recursiveCheckBox->isChecked(),
m_ui.hiddenCheckBox->isChecked(),
......@@ -398,6 +403,14 @@ void KatePluginSearchView::startSearch()
m_ui.binaryCheckBox->isChecked(),
m_ui.filterCombo->currentText(),
reg);
} else {
/**
* init search with file list from current project, if any
*/
QStringList files;
if (m_projectPluginView)
files = m_projectPluginView->property ("projectFiles").toStringList();
m_searchProject.startSearch(files, reg);
}
m_toolView->setCursor(Qt::WaitCursor);
......@@ -805,6 +818,7 @@ void KatePluginSearchView::closeTab(QWidget *widget)
if (m_curResults == tmp) {
m_searchOpenFiles.cancelSearch();
m_searchFolder.cancelSearch();
m_searchProject.cancelSearch();
}
if (m_ui.resultTabWidget->count() > 1) {
delete tmp; // remove the tab
......
......@@ -33,6 +33,7 @@
#include "search_open_files.h"
#include "search_folder.h"
#include "search_project.h"
#include "replace_matches.h"
class KateSearchCommand;
......@@ -138,6 +139,7 @@ private:
Kate::Application *m_kateApp;
SearchOpenFiles m_searchOpenFiles;
SearchFolder m_searchFolder;
SearchProject m_searchProject;
ReplaceMatches m_replacer;
KAction *m_matchCase;
KAction *m_useRegExp;
......
/* Kate search plugin
*
* Copyright (C) 2011 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file called COPYING; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "search_project.h"
#include "search_project.moc"
#include <kmimetype.h>
#include <QDir>
SearchProject::SearchProject(QObject *parent) : QThread(parent)
{
}
void SearchProject::startSearch(const QStringList &files,
const QRegExp &regexp)
{
m_cancelSearch = false;
m_files = files;
m_regExp = regexp;
start();
}
void SearchProject::run()
{
foreach (QString fileName, m_files) {
if (m_cancelSearch)
break;
QFile file (fileName);
if (!file.open(QFile::ReadOnly))
continue;
QTextStream stream (&file);
QString line;
int i = 0;
int column;
while (!(line=stream.readLine()).isNull()) {
if (m_cancelSearch) break;
column = m_regExp.indexIn(line);
while (column != -1) {
// limit line length
if (line.length() > 512) line = line.left(512);
emit matchFound(fileName, i, column, line, m_regExp.matchedLength());
column = m_regExp.indexIn(line, column + 1);
}
i++;
}
}
emit searchDone();
}
void SearchProject::cancelSearch()
{
m_cancelSearch = true;
}
/* Kate search plugin
*
* Copyright (C) 2011 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file called COPYING; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef _SEARCH_PROJECT_H_
#define _SEARCH_PROJECT_H_
#include <QThread>
#include <QRegExp>
#include <QFileInfo>
#include <ktexteditor/document.h>
class SearchProject: public QThread
{
Q_OBJECT
public:
SearchProject(QObject *parent = 0);
void startSearch(const QStringList &files,
const QRegExp &regexp);
void run();
public Q_SLOTS:
void cancelSearch();
Q_SIGNALS:
void matchFound(const QString &url, int line, int column,
const QString &lineContent, int matchLen);
void searchDone();
private:
QRegExp m_regExp;
bool m_cancelSearch;
QStringList m_files;
};
#endif
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