Commit 5765bc90 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Introduce private class for BaseFileFind.



Remove circular dependency between ITextEditor and ITextMark.

Change-Id: I2ab17a46e08ef7dd2d112320c8ab6f5d5bd91952
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent c42fa280
......@@ -35,6 +35,7 @@
#include "editorconfiguration.h"
#include <texteditor/itexteditor.h>
#include <utils/filesearch.h>
#include <QSettings>
#include <QRegExp>
......
......@@ -35,6 +35,7 @@
#include <coreplugin/idocument.h>
#include <utils/qtcassert.h>
#include <utils/filesearch.h>
#include <QDebug>
#include <QSettings>
......
......@@ -44,33 +44,55 @@
#include <utils/stylehelper.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <utils/filesearch.h>
#include <QDebug>
#include <QDirIterator>
#include <QSettings>
#include <QHash>
#include <QPair>
#include <QStringListModel>
#include <QFutureWatcher>
#include <QPointer>
#include <QFileDialog>
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QTextBlock>
namespace TextEditor {
namespace Internal {
class BaseFileFindPrivate {
public:
BaseFileFindPrivate() : m_resultLabel(0), m_filterCombo(0) {}
QMap<QFutureWatcher<Utils::FileSearchResultList> *, QPointer<Find::SearchResult> > m_watchers;
QPointer<Find::IFindSupport> m_currentFindSupport;
QLabel *m_resultLabel;
QStringListModel m_filterStrings;
QString m_filterSetting;
QPointer<QComboBox> m_filterCombo;
};
} // namespace Internal
} // namespace TextEditor
using namespace Utils;
using namespace Find;
using namespace TextEditor;
using namespace TextEditor::Internal;
BaseFileFind::BaseFileFind()
: m_resultLabel(0),
m_filterCombo(0)
BaseFileFind::BaseFileFind() : d(new BaseFileFindPrivate)
{
}
BaseFileFind::~BaseFileFind()
{
delete d;
}
bool BaseFileFind::isEnabled() const
......@@ -82,7 +104,7 @@ void BaseFileFind::cancel()
{
SearchResult *search = qobject_cast<SearchResult *>(sender());
QTC_ASSERT(search, return);
QFutureWatcher<FileSearchResultList> *watcher = m_watchers.key(search);
QFutureWatcher<FileSearchResultList> *watcher = d->m_watchers.key(search);
QTC_ASSERT(watcher, return);
watcher->cancel();
}
......@@ -91,7 +113,7 @@ void BaseFileFind::setPaused(bool paused)
{
SearchResult *search = qobject_cast<SearchResult *>(sender());
QTC_ASSERT(search, return);
QFutureWatcher<FileSearchResultList> *watcher = m_watchers.key(search);
QFutureWatcher<FileSearchResultList> *watcher = d->m_watchers.key(search);
QTC_ASSERT(watcher, return);
if (!paused || watcher->isRunning()) // guard against pausing when the search is finished
watcher->setPaused(paused);
......@@ -100,8 +122,8 @@ void BaseFileFind::setPaused(bool paused)
QStringList BaseFileFind::fileNameFilters() const
{
QStringList filters;
if (m_filterCombo && !m_filterCombo->currentText().isEmpty()) {
const QStringList parts = m_filterCombo->currentText().split(QLatin1Char(','));
if (d->m_filterCombo && !d->m_filterCombo->currentText().isEmpty()) {
const QStringList parts = d->m_filterCombo->currentText().split(QLatin1Char(','));
foreach (const QString &part, parts) {
const QString filter = part.trimmed();
if (!filter.isEmpty())
......@@ -114,9 +136,9 @@ QStringList BaseFileFind::fileNameFilters() const
void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags,
SearchResultWindow::SearchMode searchMode)
{
m_currentFindSupport = 0;
if (m_filterCombo)
updateComboEntries(m_filterCombo, true);
d->m_currentFindSupport = 0;
if (d->m_filterCombo)
updateComboEntries(d->m_filterCombo, true);
SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(label(),
toolTip().arg(Find::IFindFilter::descriptionForFindFlags(findFlags)),
txt, searchMode, QString::fromLatin1("TextEditor"));
......@@ -150,7 +172,7 @@ void BaseFileFind::runSearch(Find::SearchResult *search)
connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int)));
Find::SearchResultWindow::instance()->popup(Core::IOutputPane::Flags(Core::IOutputPane::ModeSwitch | Core::IOutputPane::WithFocus));
QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>();
m_watchers.insert(watcher, search);
d->m_watchers.insert(watcher, search);
watcher->setPendingResultsLimit(1);
connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
......@@ -197,7 +219,7 @@ void BaseFileFind::doReplace(const QString &text,
void BaseFileFind::displayResult(int index) {
QFutureWatcher<FileSearchResultList> *watcher =
static_cast<QFutureWatcher<FileSearchResultList> *>(sender());
SearchResult *search = m_watchers.value(watcher);
SearchResult *search = d->m_watchers.value(watcher);
if (!search) {
// search was removed from search history while the search is running
watcher->cancel();
......@@ -223,47 +245,47 @@ void BaseFileFind::searchFinished()
{
QFutureWatcher<FileSearchResultList> *watcher =
static_cast<QFutureWatcher<FileSearchResultList> *>(sender());
SearchResult *search = m_watchers.value(watcher);
SearchResult *search = d->m_watchers.value(watcher);
if (search)
search->finishSearch(watcher->isCanceled());
m_watchers.remove(watcher);
d->m_watchers.remove(watcher);
watcher->deleteLater();
}
QWidget *BaseFileFind::createPatternWidget()
{
QString filterToolTip = tr("List of comma separated wildcard filters");
m_filterCombo = new QComboBox;
m_filterCombo->setEditable(true);
m_filterCombo->setModel(&m_filterStrings);
m_filterCombo->setMaxCount(10);
m_filterCombo->setMinimumContentsLength(10);
m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
m_filterCombo->setInsertPolicy(QComboBox::InsertAtBottom);
m_filterCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_filterCombo->setToolTip(filterToolTip);
syncComboWithSettings(m_filterCombo, m_filterSetting);
return m_filterCombo;
d->m_filterCombo = new QComboBox;
d->m_filterCombo->setEditable(true);
d->m_filterCombo->setModel(&d->m_filterStrings);
d->m_filterCombo->setMaxCount(10);
d->m_filterCombo->setMinimumContentsLength(10);
d->m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
d->m_filterCombo->setInsertPolicy(QComboBox::InsertAtBottom);
d->m_filterCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
d->m_filterCombo->setToolTip(filterToolTip);
syncComboWithSettings(d->m_filterCombo, d->m_filterSetting);
return d->m_filterCombo;
}
void BaseFileFind::writeCommonSettings(QSettings *settings)
{
settings->setValue(QLatin1String("filters"), m_filterStrings.stringList());
if (m_filterCombo)
settings->setValue(QLatin1String("currentFilter"), m_filterCombo->currentText());
settings->setValue(QLatin1String("filters"), d->m_filterStrings.stringList());
if (d->m_filterCombo)
settings->setValue(QLatin1String("currentFilter"), d->m_filterCombo->currentText());
}
void BaseFileFind::readCommonSettings(QSettings *settings, const QString &defaultFilter)
{
QStringList filters = settings->value(QLatin1String("filters")).toStringList();
m_filterSetting = settings->value(QLatin1String("currentFilter")).toString();
d->m_filterSetting = settings->value(QLatin1String("currentFilter")).toString();
if (filters.isEmpty())
filters << defaultFilter;
if (m_filterSetting.isEmpty())
m_filterSetting = filters.first();
m_filterStrings.setStringList(filters);
if (m_filterCombo)
syncComboWithSettings(m_filterCombo, m_filterSetting);
if (d->m_filterSetting.isEmpty())
d->m_filterSetting = filters.first();
d->m_filterStrings.setStringList(filters);
if (d->m_filterCombo)
syncComboWithSettings(d->m_filterCombo, d->m_filterSetting);
}
void BaseFileFind::syncComboWithSettings(QComboBox *combo, const QString &setting)
......@@ -303,25 +325,25 @@ void BaseFileFind::openEditor(const Find::SearchResultItem &item)
openedEditor = Core::EditorManager::openEditor(QDir::fromNativeSeparators(item.text),
Core::Id(), Core::EditorManager::ModeSwitch);
}
if (m_currentFindSupport)
m_currentFindSupport->clearResults();
m_currentFindSupport = 0;
if (d->m_currentFindSupport)
d->m_currentFindSupport->clearResults();
d->m_currentFindSupport = 0;
if (!openedEditor)
return;
// highlight results
if (IFindSupport *findSupport = Aggregation::query<IFindSupport>(openedEditor->widget())) {
if (result) {
FileFindParameters parameters = result->userData().value<FileFindParameters>();
m_currentFindSupport = findSupport;
m_currentFindSupport->highlightAll(parameters.text, parameters.flags);
d->m_currentFindSupport = findSupport;
d->m_currentFindSupport->highlightAll(parameters.text, parameters.flags);
}
}
}
void BaseFileFind::hideHighlightAll(bool visible)
{
if (!visible && m_currentFindSupport)
m_currentFindSupport->clearResults();
if (!visible && d->m_currentFindSupport)
d->m_currentFindSupport->clearResults();
}
void BaseFileFind::searchAgain()
......
......@@ -34,12 +34,6 @@
#include <find/ifindfilter.h>
#include <find/searchresultwindow.h>
#include <utils/filesearch.h>
#include <QStringListModel>
#include <QFutureWatcher>
#include <QPointer>
QT_BEGIN_NAMESPACE
class QLabel;
......@@ -50,11 +44,15 @@ namespace Utils {
class FileIterator;
}
namespace Find {
class SearchResult;
struct SearchResultItem;
class IFindSupport;
}
namespace TextEditor {
namespace Internal {
class BaseFileFindPrivate;
} // namespace Internal
class TEXTEDITOR_EXPORT BaseFileFind : public Find::IFindFilter
{
......@@ -108,13 +106,7 @@ private:
Find::SearchResultWindow::SearchMode searchMode);
void runSearch(Find::SearchResult *search);
QMap<QFutureWatcher<Utils::FileSearchResultList> *, QPointer<Find::SearchResult> > m_watchers;
QPointer<Find::IFindSupport> m_currentFindSupport;
QLabel *m_resultLabel;
QStringListModel m_filterStrings;
QString m_filterSetting;
QPointer<QComboBox> m_filterCombo;
Internal::BaseFileFindPrivate *d;
};
} // namespace TextEditor
......
......@@ -30,6 +30,7 @@
#include "findincurrentfile.h"
#include "itexteditor.h"
#include <utils/filesearch.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
......
......@@ -29,6 +29,7 @@
#include "findinfiles.h"
#include <utils/filesearch.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QDebug>
......@@ -37,6 +38,8 @@
#include <QDirIterator>
#include <QPushButton>
#include <QFileDialog>
#include <QLabel>
#include <QComboBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
......@@ -49,6 +52,10 @@ FindInFiles::FindInFiles()
{
}
FindInFiles::~FindInFiles()
{
}
QString FindInFiles::id() const
{
return QLatin1String("Files on Disk");
......
......@@ -32,13 +32,11 @@
#include "basefilefind.h"
#include <find/ifindfilter.h>
#include <QPointer>
#include <QLabel>
#include <QComboBox>
#include <QStringListModel>
QT_FORWARD_DECLARE_CLASS(QLabel)
QT_FORWARD_DECLARE_CLASS(QComboBox)
namespace TextEditor {
......@@ -48,6 +46,7 @@ class TEXTEDITOR_EXPORT FindInFiles : public BaseFileFind
public:
FindInFiles();
~FindInFiles();
QString id() const;
QString displayName() const;
......
......@@ -30,6 +30,7 @@
#include "findinopenfiles.h"
#include "itexteditor.h"
#include <utils/filesearch.h>
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/openeditorsmodel.h>
......
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