Show warning with continue/cancel in case of many search results

Task-number: QTCREATORBUG-6116
Change-Id: I57a66b8989f1cc4137b02df370704dfe43d392ac
Reviewed-by: Robert Löhning <robert.loehning@nokia.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Eike Ziller
2012-05-25 16:45:18 +02:00
parent 72187be3dd
commit ddc0c89bd6
15 changed files with 219 additions and 29 deletions

View File

@@ -113,6 +113,8 @@ public:
QList<Usage> operator()(const QString &fileName)
{
QList<Usage> usages;
if (future->isPaused())
future->waitForResume();
if (future->isCanceled())
return usages;
const Identifier *symbolId = symbol->identifier();
@@ -145,6 +147,8 @@ public:
usages = process.usages();
}
if (future->isPaused())
future->waitForResume();
return usages;
}
};
@@ -252,6 +256,7 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
search->setTextToReplace(replacement);
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
search->setSearchAgainSupported(true);
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
CppFindReferencesParameters parameters;
@@ -293,7 +298,7 @@ void CppFindReferences::findAll_helper(Find::SearchResult *search)
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
CppTools::Constants::TASK_SEARCH);
connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
}
void CppFindReferences::onReplaceButtonClicked(const QString &text,
@@ -511,6 +516,16 @@ void CppFindReferences::cancel()
watcher->cancel();
}
void CppFindReferences::setPaused(bool paused)
{
Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender());
QTC_ASSERT(search, return);
QFutureWatcher<Usage> *watcher = m_watchers.key(search);
QTC_ASSERT(watcher, return);
if (!paused || watcher->isRunning()) // guard against pausing when the search is finished
watcher->setPaused(paused);
}
void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{
if (item.path.size() > 0) {
@@ -545,6 +560,8 @@ public:
QList<Usage> operator()(const QString &fileName)
{
QList<Usage> usages;
if (future->isPaused())
future->waitForResume();
if (future->isCanceled())
return usages;
@@ -566,6 +583,8 @@ public:
}
}
if (future->isPaused())
future->waitForResume();
return usages;
}
@@ -638,6 +657,7 @@ void CppFindReferences::findMacroUses(const Macro &macro)
connect(search, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
const Snapshot snapshot = _modelManager->snapshot();
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
@@ -662,7 +682,7 @@ void CppFindReferences::findMacroUses(const Macro &macro)
Core::ProgressManager *progressManager = Core::ICore::progressManager();
Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"),
CppTools::Constants::TASK_SEARCH);
connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
}
DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot snapshot)

View File

@@ -89,6 +89,7 @@ private Q_SLOTS:
void displayResults(int first, int last);
void searchFinished();
void cancel();
void setPaused(bool paused);
void openEditor(const Find::SearchResultItem &item);
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
void searchAgain();

View File

@@ -36,6 +36,7 @@
#include "cpptoolsconstants.h"
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/progressmanager/futureprogress.h>
#include <coreplugin/icore.h>
#include <find/textfindconstants.h>
#include <utils/runextensions.h>
@@ -77,7 +78,11 @@ namespace {
findString = QString::fromLatin1("\\b%1\\b").arg(findString);
QRegExp matcher(findString, (parameters.flags & Find::FindCaseSensitively
? Qt::CaseSensitive : Qt::CaseInsensitive));
while (it != snapshot.end() && !future.isCanceled()) {
while (it != snapshot.end()) {
if (future.isPaused())
future.waitForResume();
if (future.isCanceled())
break;
if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) {
QVector<Find::SearchResultItem> resultItems;
QList<ModelItemInfo> modelInfos = search(it.value());
@@ -104,6 +109,8 @@ namespace {
++progress;
future.setProgressValue(progress);
}
if (future.isPaused())
future.waitForResume();
}
} //namespace
@@ -144,6 +151,16 @@ void SymbolsFindFilter::cancel()
watcher->cancel();
}
void SymbolsFindFilter::setPaused(bool paused)
{
Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender());
QTC_ASSERT(search, return);
QFutureWatcher<Find::SearchResultItem> *watcher = m_watchers.key(search);
QTC_ASSERT(watcher, return);
if (!paused || watcher->isRunning()) // guard against pausing when the search is finished
watcher->setPaused(paused);
}
Find::FindFlags SymbolsFindFilter::supportedFindFlags() const
{
return Find::FindCaseSensitively | Find::FindRegularExpression | Find::FindWholeWords;
@@ -157,6 +174,7 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
connect(search, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool)));
window->popup(true);
@@ -190,9 +208,10 @@ void SymbolsFindFilter::startSearch(Find::SearchResult *search)
watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, SymbolsFindParameters,
CPlusPlus::Snapshot, QSet<QString> >(runSearch, parameters,
m_manager->snapshot(), projectFileNames));
Core::ICore::progressManager()->addTask(watcher->future(),
Core::FutureProgress *progress = Core::ICore::progressManager()->addTask(watcher->future(),
tr("Searching"),
Find::Constants::TASK_SEARCH);
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
}
void SymbolsFindFilter::addResults(int begin, int end)

View File

@@ -87,6 +87,7 @@ private slots:
void addResults(int begin, int end);
void finish();
void cancel();
void setPaused(bool paused);
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
void searchAgain();