Commit 38d3090a authored by con's avatar con
Browse files

Share some code between all projects and current projects find.

Also some const correctness.
parent 4e7c07d9
......@@ -72,9 +72,14 @@ bool AllProjectsFind::isEnabled() const
&& m_plugin->session()->projects().count() > 0;
}
Utils::FileIterator *AllProjectsFind::files()
QList<Project *> AllProjectsFind::projects() const
{
Q_ASSERT(m_plugin->session());
return m_plugin->session()->projects();
}
Utils::FileIterator *AllProjectsFind::files() const
{
QList<QRegExp> filterRegs;
QStringList nameFilters = fileNameFilters();
foreach (const QString &filter, nameFilters) {
......@@ -82,7 +87,7 @@ Utils::FileIterator *AllProjectsFind::files()
}
QStringList files;
QStringList projectFiles;
foreach (const Project *project, m_plugin->session()->projects()) {
foreach (const Project *project, projects()) {
projectFiles = project->files(Project::AllFiles);
if (!filterRegs.isEmpty()) {
foreach (const QString &file, projectFiles) {
......
......@@ -40,6 +40,7 @@
namespace ProjectExplorer {
class ProjectExplorerPlugin;
class Project;
namespace Internal {
......@@ -60,7 +61,8 @@ public:
void readSettings(QSettings *settings);
protected:
Utils::FileIterator *files();
virtual QList<Project *> projects() const;
Utils::FileIterator *files() const;
private:
ProjectExplorerPlugin *m_plugin;
......
......@@ -47,9 +47,8 @@ using namespace ProjectExplorer::Internal;
using namespace TextEditor;
CurrentProjectFind::CurrentProjectFind(ProjectExplorerPlugin *plugin, SearchResultWindow *resultWindow)
: BaseFileFind(resultWindow),
m_plugin(plugin),
m_configWidget(0)
: AllProjectsFind(plugin, resultWindow),
m_plugin(plugin)
{
connect(m_plugin, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)),
this, SIGNAL(changed()));
......@@ -70,50 +69,9 @@ bool CurrentProjectFind::isEnabled() const
return m_plugin->currentProject() != 0 && BaseFileFind::isEnabled();
}
Utils::FileIterator *CurrentProjectFind::files()
QList<Project *> CurrentProjectFind::projects() const
{
Project *project = m_plugin->currentProject();
Q_ASSERT(project);
QList<QRegExp> filterRegs;
QStringList nameFilters = fileNameFilters();
foreach (const QString &filter, nameFilters) {
filterRegs << QRegExp(filter, Qt::CaseInsensitive, QRegExp::Wildcard);
}
QStringList files;
if (!filterRegs.isEmpty()) {
foreach (const QString &file, project->files(Project::AllFiles)) {
foreach (const QRegExp &reg, filterRegs) {
if (reg.exactMatch(file) || reg.exactMatch(QFileInfo(file).fileName())) {
files.append(file);
break;
}
}
}
} else {
files += project->files(Project::AllFiles);
}
files.removeDuplicates();
return new Utils::FileIterator(files);
}
QWidget *CurrentProjectFind::createConfigWidget()
{
if (!m_configWidget) {
m_configWidget = new QWidget;
QGridLayout * const layout = new QGridLayout(m_configWidget);
layout->setMargin(0);
m_configWidget->setLayout(layout);
QLabel * const filePatternLabel = new QLabel(tr("File &pattern:"));
filePatternLabel->setMinimumWidth(80);
filePatternLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
filePatternLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
QWidget *patternWidget = createPatternWidget();
filePatternLabel->setBuddy(patternWidget);
layout->addWidget(filePatternLabel, 0, 0, Qt::AlignRight);
layout->addWidget(patternWidget, 0, 1);
m_configWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
}
return m_configWidget;
return QList<Project *>() << m_plugin->currentProject();
}
void CurrentProjectFind::writeSettings(QSettings *settings)
......
......@@ -30,9 +30,10 @@
#ifndef CURRENTPROJECTFIND_H
#define CURRENTPROJECTFIND_H
#include "allprojectsfind.h"
#include <find/ifindfilter.h>
#include <find/searchresultwindow.h>
#include <texteditor/basefilefind.h>
#include <QtCore/QPointer>
......@@ -43,10 +44,11 @@ QT_END_NAMESPACE
namespace ProjectExplorer {
class ProjectExplorerPlugin;
class Project;
namespace Internal {
class CurrentProjectFind : public TextEditor::BaseFileFind
class CurrentProjectFind : public AllProjectsFind
{
Q_OBJECT
......@@ -58,16 +60,14 @@ public:
bool isEnabled() const;
QWidget *createConfigWidget();
void writeSettings(QSettings *settings);
void readSettings(QSettings *settings);
protected:
Utils::FileIterator *files();
QList<Project *> projects() const;
private:
ProjectExplorerPlugin *m_plugin;
QPointer<QWidget> m_configWidget;
};
} // namespace Internal
......
......@@ -73,7 +73,7 @@ public:
const QList<Find::SearchResultItem> &items);
protected:
virtual Utils::FileIterator *files() = 0;
virtual Utils::FileIterator *files() const = 0;
void writeCommonSettings(QSettings *settings);
void readCommonSettings(QSettings *settings, const QString &defaultFilter);
QWidget *createPatternWidget();
......
......@@ -62,7 +62,7 @@ QString FindInCurrentFile::displayName() const
return tr("Current File");
}
Utils::FileIterator *FindInCurrentFile::files()
Utils::FileIterator *FindInCurrentFile::files() const
{
QStringList fileList;
if (isEnabled())
......
......@@ -61,7 +61,7 @@ public:
void readSettings(QSettings *settings);
protected:
Utils::FileIterator *files();
Utils::FileIterator *files() const;
private slots:
void handleFileChange(Core::IEditor *editor);
......
......@@ -63,7 +63,7 @@ void FindInFiles::findAll(const QString &txt, Find::FindFlags findFlags)
BaseFileFind::findAll(txt, findFlags);
}
Utils::FileIterator *FindInFiles::files()
Utils::FileIterator *FindInFiles::files() const
{
return new Utils::SubDirFileIterator(QStringList() << m_directory->currentText(),
fileNameFilters());
......
......@@ -59,7 +59,7 @@ public:
void readSettings(QSettings *settings);
protected:
Utils::FileIterator *files();
Utils::FileIterator *files() const;
private slots:
void openFileBrowser();
......
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