Commit fdeb7620 authored by Eike Ziller's avatar Eike Ziller

Keep multiple search results in history.

Change-Id: I7350c78479343e85b1ca4957e08bccefb5756d20
Reviewed-on: http://codereview.qt-project.org/4556Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent c5c94206
......@@ -161,8 +161,7 @@ public:
CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager)
: QObject(modelManager),
_modelManager(modelManager),
m_currentSearch(0)
_modelManager(modelManager)
{
m_watcher.setPendingResultsLimit(1);
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
......@@ -227,9 +226,11 @@ static void find_helper(QFutureInterface<Usage> &future,
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context)
{
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly);
Overview overview;
m_currentSearch->setInfo(tr("C++ Usages:"), QString(), overview(context.fullyQualifiedName(symbol)));
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(tr("C++ Usages:"),
QString(),
overview(context.fullyQualifiedName(symbol)),
Find::SearchResultWindow::SearchOnly);
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
......@@ -243,10 +244,12 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus:
const QString textToReplace = replacement.isEmpty()
? QString::fromUtf8(id->chars(), id->size()) : replacement;
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor"));
Overview overview;
m_currentSearch->setInfo(tr("C++ Usages:"), QString(), overview(context.fullyQualifiedName(symbol)));
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
tr("C++ Usages:"),
QString(),
overview(context.fullyQualifiedName(symbol)),
Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor"));
m_currentSearch->setTextToReplace(textToReplace);
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
......@@ -293,6 +296,10 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
void CppFindReferences::displayResults(int first, int last)
{
if (!m_currentSearch) {
m_watcher.cancel();
return;
}
for (int index = first; index != last; ++index) {
Usage result = m_watcher.future().resultAt(index);
m_currentSearch->addResult(result.path,
......@@ -305,7 +312,8 @@ void CppFindReferences::displayResults(int first, int last)
void CppFindReferences::searchFinished()
{
m_currentSearch->finishSearch();
if (m_currentSearch)
m_currentSearch->finishSearch();
m_currentSearch = 0;
emit changed();
}
......@@ -422,8 +430,11 @@ static void findMacroUses_helper(QFutureInterface<Usage> &future,
void CppFindReferences::findMacroUses(const Macro &macro)
{
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly);
m_currentSearch->setInfo(tr("C++ Macro Usages:"), QString(), QString::fromLocal8Bit(macro.name()));
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
tr("C++ Macro Usages:"),
QString(),
macro.name(),
Find::SearchResultWindow::SearchOnly);
Find::SearchResultWindow::instance()->popup(true);
......
......@@ -94,7 +94,7 @@ private:
private:
QPointer<CPlusPlus::CppModelManagerInterface> _modelManager;
Find::SearchResult *m_currentSearch;
QPointer<Find::SearchResult> m_currentSearch;
QFutureWatcher<CPlusPlus::Usage> m_watcher;
mutable QMutex m_depsLock;
......
......@@ -104,7 +104,6 @@ SymbolsFindFilter::SymbolsFindFilter(CppModelManager *manager)
: m_manager(manager),
m_isRunning(false),
m_enabled(true),
m_currentSearch(0),
m_symbolsToSearch(SearchSymbols::AllTypes),
m_scope(SearchProjectsOnly)
{
......@@ -150,8 +149,7 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
m_isRunning = true;
emit changed();
Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
m_currentSearch = window->startNewSearch();
m_currentSearch->setInfo(label(), toolTip(findFlags), txt);
m_currentSearch = window->startNewSearch(label(), toolTip(findFlags), txt);
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
window->popup(true);
......@@ -177,6 +175,10 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
void SymbolsFindFilter::addResults(int begin, int end)
{
if (!m_currentSearch) {
m_watcher.cancel();
return;
}
QList<Find::SearchResultItem> items;
for (int i = begin; i < end; ++i)
items << m_watcher.resultAt(i);
......@@ -185,7 +187,8 @@ void SymbolsFindFilter::addResults(int begin, int end)
void SymbolsFindFilter::finish()
{
m_currentSearch->finishSearch();
if (m_currentSearch)
m_currentSearch->finishSearch();
m_currentSearch = 0;
m_isRunning = false;
emit changed();
......
......@@ -40,6 +40,7 @@
#include <QtCore/QFutureInterface>
#include <QtCore/QFutureWatcher>
#include <QtCore/QPointer>
#include <QtGui/QWidget>
#include <QtGui/QCheckBox>
#include <QtGui/QRadioButton>
......@@ -97,7 +98,7 @@ private:
bool m_isRunning;
bool m_enabled;
QFutureWatcher<Find::SearchResultItem> m_watcher;
Find::SearchResult *m_currentSearch;
QPointer<Find::SearchResult> m_currentSearch;
SearchSymbols::SymbolTypes m_symbolsToSearch;
SearchSymbols m_search;
SearchScope m_scope;
......
......@@ -254,7 +254,6 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) :
m_cancelButton->setText(tr("Cancel"));
m_cancelButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
m_cancelButton->setVisible(false);
m_replaceLabel = new QLabel(tr("Replace with:"), topWidget);
m_replaceTextEdit = new WideEnoughLineEdit(topWidget);
......@@ -285,11 +284,6 @@ SearchResultWidget::SearchResultWidget(QWidget *parent) :
connect(m_replaceButton, SIGNAL(clicked()), this, SLOT(handleReplaceButton()));
}
void SearchResultWidget::startSearch()
{
m_cancelButton->setVisible(true);
}
void SearchResultWidget::setInfo(const QString &label, const QString &toolTip, const QString &term)
{
m_label->setText(label);
......@@ -319,7 +313,7 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search
m_count += items.size();
m_searchResultTreeView->addResults(items, mode);
if (firstItems) {
if (!m_dontAskAgainGroup.isEmpty() && showWarningMessage()) {
if (showWarningMessage()) {
Core::InfoBarEntry info("warninglabel", tr("This change cannot be undone."));
info.setCustomButtonInfo(tr("Do not warn again"), this, SLOT(hideNoUndoWarning()));
m_infoBar.addInfo(info);
......@@ -497,6 +491,8 @@ void SearchResultWidget::cancel()
bool SearchResultWidget::showWarningMessage() const
{
if (m_dontAskAgainGroup.isEmpty())
return false;
// read settings
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(m_dontAskAgainGroup);
......
......@@ -53,7 +53,6 @@ class SearchResultWidget : public QWidget
public:
explicit SearchResultWidget(QWidget *parent = 0);
void startSearch();
void setInfo(const QString &label, const QString &toolTip, const QString &term);
void addResult(const QString &fileName, int lineNumber, const QString &lineText,
......
This diff is collapsed.
......@@ -48,7 +48,7 @@ QT_END_NAMESPACE
namespace Find {
namespace Internal {
class SearchResultTreeView;
struct SearchResultWindowPrivate;
class SearchResultWindowPrivate;
class SearchResultWidget;
}
class SearchResultWindow;
......@@ -98,7 +98,6 @@ public:
void setUserData(const QVariant &data);
QVariant userData() const;
QString textToReplace() const;
void setInfo(const QString &label, const QString &toolTip, const QString &term);
public slots:
void addResult(const QString &fileName, int lineNumber, const QString &lineText,
......@@ -156,8 +155,14 @@ public:
void setTextEditorFont(const QFont &font);
void openNewSearchPanel();
// search result object is guaranteed to live till its finishSearch method is called
SearchResult *startNewSearch(SearchMode searchOrSearchAndReplace = SearchOnly,
// The search result window owns the returned SearchResult
// and might delete it any time, even while the search is running
// (e.g. when the user clears the search result pane, or if the user opens so many other searches
// that this search falls out of the history).
SearchResult *startNewSearch(const QString &label,
const QString &toolTip,
const QString &searchTerm,
SearchMode searchOrSearchAndReplace = SearchOnly,
const QString &cfgGroup = QString());
public slots:
......
......@@ -776,8 +776,7 @@ public:
} // end of anonymous namespace
FindReferences::FindReferences(QObject *parent)
: QObject(parent),
m_currentSearch(0)
: QObject(parent)
{
m_watcher.setPendingResultsLimit(1);
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
......@@ -914,18 +913,20 @@ void FindReferences::displayResults(int first, int last)
// the first usage is always a dummy to indicate we now start searching
if (first == 0) {
Usage dummy = m_watcher.future().resultAt(0);
QString replacement = dummy.path;
QString symbolName = dummy.lineText;
const QString replacement = dummy.path;
const QString symbolName = dummy.lineText;
const QString label = tr("QML/JS Usages:");
if (replacement.isEmpty()) {
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly);
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
label, QString(), symbolName, Find::SearchResultWindow::SearchOnly);
} else {
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchAndReplace);
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(
label, QString(), symbolName, Find::SearchResultWindow::SearchAndReplace);
m_currentSearch->setTextToReplace(replacement);
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
}
m_currentSearch->setInfo(tr("Usages:"), QString(), symbolName);
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
......@@ -940,6 +941,10 @@ void FindReferences::displayResults(int first, int last)
++first;
}
if (!m_currentSearch) {
m_watcher.cancel();
return;
}
for (int index = first; index != last; ++index) {
Usage result = m_watcher.future().resultAt(index);
m_currentSearch->addResult(result.path,
......@@ -952,7 +957,8 @@ void FindReferences::displayResults(int first, int last)
void FindReferences::searchFinished()
{
m_currentSearch->finishSearch();
if (m_currentSearch)
m_currentSearch->finishSearch();
m_currentSearch = 0;
emit changed();
}
......
......@@ -37,6 +37,7 @@
#include <QtCore/QObject>
#include <QtCore/QFuture>
#include <QtCore/QFutureWatcher>
#include <QtCore/QPointer>
#include <utils/filesearch.h>
#include <qmljs/qmljsdocument.h>
......@@ -90,7 +91,7 @@ private Q_SLOTS:
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
private:
Find::SearchResult *m_currentSearch;
QPointer<Find::SearchResult> m_currentSearch;
QFutureWatcher<Usage> m_watcher;
};
......
......@@ -113,14 +113,10 @@ void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags,
updateComboEntries(m_filterCombo, true);
m_watcher.setFuture(QFuture<FileSearchResultList>());
m_currentSearchCount = 0;
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(searchMode,
searchMode == SearchResultWindow::SearchAndReplace
? QString::fromLatin1("TextEditor")
: QString());
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(label(),
toolTip().arg(Find::IFindFilter::descriptionForFindFlags(findFlags)),
txt, searchMode, QString::fromLatin1("TextEditor"));
m_currentSearch->setTextToReplace(txt);
m_currentSearch->setInfo(label(),
toolTip().arg(Find::IFindFilter::descriptionForFindFlags(findFlags)),
txt);
QVariantList searchParameters;
searchParameters << qVariantFromValue(txt) << qVariantFromValue(findFlags);
m_currentSearch->setUserData(searchParameters);
......@@ -169,6 +165,10 @@ void BaseFileFind::doReplace(const QString &text,
}
void BaseFileFind::displayResult(int index) {
if (!m_currentSearch) {
m_watcher.cancel();
return;
}
Utils::FileSearchResultList results = m_watcher.future().resultAt(index);
QList<Find::SearchResultItem> items;
foreach (const Utils::FileSearchResult &result, results) {
......@@ -190,7 +190,8 @@ void BaseFileFind::displayResult(int index) {
void BaseFileFind::searchFinished()
{
m_currentSearch->finishSearch();
if (m_currentSearch)
m_currentSearch->finishSearch();
m_currentSearch = 0;
m_isSearching = false;
m_resultLabel = 0;
......
......@@ -78,8 +78,8 @@ public:
protected:
virtual Utils::FileIterator *files() const = 0;
virtual QString label() const = 0; // see Find::SearchResult::setInfo
virtual QString toolTip() const = 0; // see Find::SearchResult::setInfo,
virtual QString label() const = 0; // see Find::SearchResultWindow::startNewSearch
virtual QString toolTip() const = 0; // see Find::SearchResultWindow::startNewSearch,
// add %1 placeholder where the find flags should be put
void writeCommonSettings(QSettings *settings);
......@@ -103,7 +103,7 @@ private:
void runNewSearch(const QString &txt, Find::FindFlags findFlags,
Find::SearchResultWindow::SearchMode searchMode);
Find::SearchResult *m_currentSearch;
QPointer<Find::SearchResult> m_currentSearch;
int m_currentSearchCount;
QFutureWatcher<Utils::FileSearchResultList> m_watcher;
......
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