Commit 3fc2ae7a authored by Eike Ziller's avatar Eike Ziller
Browse files

Allow multiple file searches at the same time.



I.e. All Projects, Current Project, Files on File System, Current File.

Task-number: QTCREATORBUG-6101
Change-Id: Ib2ee95c5eca1ecc3ef3bf707705651471db6324a
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent 5f634990
......@@ -582,6 +582,11 @@ QString SearchResult::textToReplace() const
return m_widget->textToReplace();
}
int SearchResult::count() const
{
return m_widget->count();
}
/*!
\fn void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart, int searchTermLength, const QVariant &userData)
\brief Adds a single result line to the search results.
......@@ -599,6 +604,7 @@ void SearchResult::addResult(const QString &fileName, int lineNumber, const QStr
{
m_widget->addResult(fileName, lineNumber, lineText,
searchTermStart, searchTermLength, userData);
emit countChanged(m_widget->count());
}
/*!
......@@ -611,6 +617,7 @@ void SearchResult::addResult(const QString &fileName, int lineNumber, const QStr
void SearchResult::addResults(const QList<SearchResultItem> &items, AddMode mode)
{
m_widget->addResults(items, mode);
emit countChanged(m_widget->count());
}
/*!
......
......@@ -98,6 +98,7 @@ public:
void setUserData(const QVariant &data);
QVariant userData() const;
QString textToReplace() const;
int count() const;
public slots:
void addResult(const QString &fileName, int lineNumber, const QString &lineText,
......@@ -111,6 +112,7 @@ signals:
void replaceButtonClicked(const QString &replaceText, const QList<Find::SearchResultItem> &checkedItems);
void cancelled();
void visibilityChanged(bool visible);
void countChanged(int count);
private:
SearchResult(Internal::SearchResultWidget *widget);
......
......@@ -31,6 +31,7 @@
**************************************************************************/
#include "basefilefind.h"
#include "basefilefind_p.h"
#include <aggregation/aggregate.h>
#include <coreplugin/icore.h>
......@@ -64,13 +65,10 @@
using namespace Utils;
using namespace Find;
using namespace TextEditor;
using namespace TextEditor::Internal;
BaseFileFind::BaseFileFind()
: m_currentSearch(0),
m_currentSearchCount(0),
m_watcher(0),
m_isSearching(false),
m_resultLabel(0),
: m_resultLabel(0),
m_filterCombo(0)
{
}
......@@ -81,13 +79,16 @@ BaseFileFind::~BaseFileFind()
bool BaseFileFind::isEnabled() const
{
return !m_isSearching;
return true;
}
void BaseFileFind::cancel()
{
QTC_ASSERT(m_watcher, return);
m_watcher->cancel();
SearchResult *search = qobject_cast<SearchResult *>(sender());
QTC_ASSERT(search, return);
QFutureWatcher<FileSearchResultList> *watcher = watcherForSearch(search);
QTC_ASSERT(watcher, return);
watcher->cancel();
}
QStringList BaseFileFind::fileNameFilters() const
......@@ -108,47 +109,60 @@ QStringList BaseFileFind::fileNameFilters() const
void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags,
SearchResultWindow::SearchMode searchMode)
{
m_isSearching = true;
m_currentFindSupport = 0;
emit changed();
if (m_filterCombo)
updateComboEntries(m_filterCombo, true);
delete m_watcher;
m_watcher = new QFutureWatcher<FileSearchResultList>();
m_watcher->setPendingResultsLimit(1);
connect(m_watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
connect(m_watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
m_currentSearchCount = 0;
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(label(),
QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>();
watcher->setPendingResultsLimit(1);
connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(label(),
toolTip().arg(Find::IFindFilter::descriptionForFindFlags(findFlags)),
txt, searchMode, QString::fromLatin1("TextEditor"));
m_currentSearch->setTextToReplace(txt);
m_watchers.insert(watcher, search);
search->setTextToReplace(txt);
QVariantList searchParameters;
searchParameters << qVariantFromValue(txt) << qVariantFromValue(findFlags);
m_currentSearch->setUserData(searchParameters);
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
search->setUserData(searchParameters);
connect(search, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
if (searchMode == SearchResultWindow::SearchAndReplace) {
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
this, SLOT(doReplace(QString,QList<Find::SearchResultItem>)));
}
connect(m_currentSearch, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool)));
connect(search, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool)));
CountingLabel *label = new CountingLabel;
connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int)));
Find::SearchResultWindow::instance()->popup(true);
if (findFlags & Find::FindRegularExpression) {
m_watcher->setFuture(Utils::findInFilesRegExp(txt, files(),
watcher->setFuture(Utils::findInFilesRegExp(txt, files(),
textDocumentFlagsForFindFlags(findFlags), ITextEditor::openedTextEditorsContents()));
} else {
m_watcher->setFuture(Utils::findInFiles(txt, files(),
watcher->setFuture(Utils::findInFiles(txt, files(),
textDocumentFlagsForFindFlags(findFlags), ITextEditor::openedTextEditorsContents()));
}
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
Core::FutureProgress *progress =
Core::ICore::instance()->progressManager()->addTask(m_watcher->future(),
Core::ICore::instance()->progressManager()->addTask(watcher->future(),
tr("Search"),
Constants::TASK_SEARCH);
progress->setWidget(createProgressWidget());
progress->setWidget(label);
connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
}
QFutureWatcher<FileSearchResultList> *BaseFileFind::watcherForSearch(SearchResult *search)
{
if (!search)
return 0;
QMapIterator<QFutureWatcher<Utils::FileSearchResultList> *, QPointer<Find::SearchResult> > it(m_watchers);
while (it.hasNext()) {
it.next();
if (it.value() == search)
return it.key();
}
return 0;
}
void BaseFileFind::findAll(const QString &txt, Find::FindFlags findFlags)
{
runNewSearch(txt, findFlags, SearchResultWindow::SearchOnly);
......@@ -171,11 +185,15 @@ void BaseFileFind::doReplace(const QString &text,
}
void BaseFileFind::displayResult(int index) {
if (!m_currentSearch) {
m_watcher->cancel();
QFutureWatcher<FileSearchResultList> *watcher =
static_cast<QFutureWatcher<FileSearchResultList> *>(sender());
SearchResult *search = m_watchers.value(watcher);
if (!search) {
// search was removed from search history while the search is running
watcher->cancel();
return;
}
Utils::FileSearchResultList results = m_watcher->resultAt(index);
Utils::FileSearchResultList results = watcher->resultAt(index);
QList<Find::SearchResultItem> items;
foreach (const Utils::FileSearchResult &result, results) {
Find::SearchResultItem item;
......@@ -188,36 +206,18 @@ void BaseFileFind::displayResult(int index) {
item.userData = result.regexpCapturedTexts;
items << item;
}
m_currentSearch->addResults(items, Find::SearchResult::AddOrdered);
m_currentSearchCount += items.count();
if (m_resultLabel)
m_resultLabel->setText(tr("%1 found").arg(m_currentSearchCount));
search->addResults(items, Find::SearchResult::AddOrdered);
}
void BaseFileFind::searchFinished()
{
if (m_currentSearch)
m_currentSearch->finishSearch();
m_currentSearch = 0;
m_isSearching = false;
m_resultLabel = 0;
m_watcher->deleteLater();
m_watcher = 0;
emit changed();
}
QWidget *BaseFileFind::createProgressWidget()
{
m_resultLabel = new QLabel;
m_resultLabel->setAlignment(Qt::AlignCenter);
// ### TODO this setup should be done by style
QFont f = m_resultLabel->font();
f.setBold(true);
f.setPointSizeF(StyleHelper::sidebarFontSize());
m_resultLabel->setFont(f);
m_resultLabel->setPalette(StyleHelper::sidebarFontPalette(m_resultLabel->palette()));
m_resultLabel->setText(tr("%1 found").arg(m_currentSearchCount));
return m_resultLabel;
QFutureWatcher<FileSearchResultList> *watcher =
static_cast<QFutureWatcher<FileSearchResultList> *>(sender());
SearchResult *search = m_watchers.value(watcher);
if (search)
search->finishSearch();
m_watchers.remove(watcher);
watcher->deleteLater();
}
QWidget *BaseFileFind::createPatternWidget()
......@@ -360,3 +360,20 @@ QStringList BaseFileFind::replaceAll(const QString &text,
return changes.keys();
}
CountingLabel::CountingLabel()
{
setAlignment(Qt::AlignCenter);
// ### TODO this setup should be done by style
QFont f = font();
f.setBold(true);
f.setPointSizeF(StyleHelper::sidebarFontSize());
setFont(f);
setPalette(StyleHelper::sidebarFontPalette(palette()));
updateCount(0);
}
void CountingLabel::updateCount(int count)
{
setText(tr("%1 found").arg(count));
}
......@@ -99,15 +99,11 @@ private slots:
void hideHighlightAll(bool visible);
private:
QWidget *createProgressWidget();
void runNewSearch(const QString &txt, Find::FindFlags findFlags,
Find::SearchResultWindow::SearchMode searchMode);
QFutureWatcher<Utils::FileSearchResultList> *watcherForSearch(Find::SearchResult *search);
QPointer<Find::SearchResult> m_currentSearch;
int m_currentSearchCount;
QFutureWatcher<Utils::FileSearchResultList> *m_watcher;
bool m_isSearching;
QMap<QFutureWatcher<Utils::FileSearchResultList> *, QPointer<Find::SearchResult> > m_watchers;
QPointer<Find::IFindSupport> m_currentFindSupport;
QLabel *m_resultLabel;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef BASEFILEFIND_P_H
#define BASEFILEFIND_P_H
#include <QtGui/QLabel>
namespace TextEditor {
namespace Internal {
class CountingLabel : public QLabel
{
Q_OBJECT
public:
CountingLabel();
public slots:
void updateCount(int count);
};
} // namespace Internal
} // namespace TextEditor
#endif // BASEFILEFIND_P_H
......@@ -224,7 +224,8 @@ HEADERS += texteditorplugin.h \
typingsettings.h \
icodestylepreferences.h \
codestylepool.h \
codestyleeditor.h
codestyleeditor.h \
basefilefind_p.h
FORMS += \
displaysettingspage.ui \
......
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