summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@nokia.com>2012-05-25 16:45:18 +0200
committerEike Ziller <eike.ziller@nokia.com>2012-06-05 10:08:40 +0200
commitddc0c89bd62cc41b145a0f4a01135c3c87f5da66 (patch)
tree8c61bcefe0b5b33b2322c468a035b8c75ad21ace /src/plugins/qmljseditor
parent72187be3dddb601ffbe30739e620776e43ba9f7e (diff)
downloadqt-creator-ddc0c89bd62cc41b145a0f4a01135c3c87f5da66.tar.gz
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>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljsfindreferences.cpp43
-rw-r--r--src/plugins/qmljseditor/qmljsfindreferences.h1
2 files changed, 32 insertions, 12 deletions
diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp
index 5931634ba1..72e8f4ca00 100644
--- a/src/plugins/qmljseditor/qmljsfindreferences.cpp
+++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp
@@ -698,18 +698,23 @@ class ProcessFile: public std::unary_function<QString, QList<FindReferences::Usa
typedef FindReferences::Usage Usage;
QString name;
const ObjectValue *scope;
+ QFutureInterface<Usage> *future;
public:
ProcessFile(const ContextPtr &context,
QString name,
- const ObjectValue *scope)
- : context(context), name(name), scope(scope)
+ const ObjectValue *scope,
+ QFutureInterface<Usage> *future)
+ : context(context), name(name), scope(scope), future(future)
{ }
QList<Usage> operator()(const QString &fileName)
{
QList<Usage> usages;
-
+ if (future->isPaused())
+ future->waitForResume();
+ if (future->isCanceled())
+ return usages;
Document::Ptr doc = context->snapshot().document(fileName);
if (!doc)
return usages;
@@ -719,7 +724,8 @@ public:
FindUsages::Result results = findUsages(name, scope);
foreach (const AST::SourceLocation &loc, results)
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
-
+ if (future->isPaused())
+ future->waitForResume();
return usages;
}
};
@@ -730,18 +736,23 @@ class SearchFileForType: public std::unary_function<QString, QList<FindReference
typedef FindReferences::Usage Usage;
QString name;
const ObjectValue *scope;
+ QFutureInterface<Usage> *future;
public:
SearchFileForType(const ContextPtr &context,
- QString name,
- const ObjectValue *scope)
- : context(context), name(name), scope(scope)
+ QString name,
+ const ObjectValue *scope,
+ QFutureInterface<Usage> *future)
+ : context(context), name(name), scope(scope), future(future)
{ }
QList<Usage> operator()(const QString &fileName)
{
QList<Usage> usages;
-
+ if (future->isPaused())
+ future->waitForResume();
+ if (future->isCanceled())
+ return usages;
Document::Ptr doc = context->snapshot().document(fileName);
if (!doc)
return usages;
@@ -751,7 +762,8 @@ public:
FindTypeUsages::Result results = findUsages(name, scope);
foreach (const AST::SourceLocation &loc, results)
usages.append(Usage(fileName, matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length));
-
+ if (future->isPaused())
+ future->waitForResume();
return usages;
}
};
@@ -857,7 +869,7 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
return;
future.reportResult(searchStarting);
- SearchFileForType process(context, name, typeValue);
+ SearchFileForType process(context, name, typeValue, &future);
UpdateUI reduce(&future);
QtConcurrent::blockingMappedReduced<QList<FindReferences::Usage> > (files, process, reduce);
@@ -872,7 +884,7 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
searchStarting.lineText.prepend(scope->className() + QLatin1Char('.'));
future.reportResult(searchStarting);
- ProcessFile process(context, name, scope);
+ ProcessFile process(context, name, scope, &future);
UpdateUI reduce(&future);
QtConcurrent::blockingMappedReduced<QList<FindReferences::Usage> > (files, process, reduce);
@@ -930,13 +942,14 @@ void FindReferences::displayResults(int first, int last)
connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel()));
+ connect(m_currentSearch, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
Find::SearchResultWindow::instance()->popup(true);
Core::ProgressManager *progressManager = Core::ICore::progressManager();
Core::FutureProgress *progress = progressManager->addTask(
m_watcher.future(), tr("Searching"),
QmlJSEditor::Constants::TASK_SEARCH);
- connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup()));
+ connect(progress, SIGNAL(clicked()), m_currentSearch, SLOT(popup()));
++first;
}
@@ -968,6 +981,12 @@ void FindReferences::cancel()
m_watcher.cancel();
}
+void FindReferences::setPaused(bool paused)
+{
+ if (!paused || m_watcher.isRunning()) // guard against pausing when the search is finished
+ m_watcher.setPaused(paused);
+}
+
void FindReferences::openEditor(const Find::SearchResultItem &item)
{
if (item.path.size() > 0) {
diff --git a/src/plugins/qmljseditor/qmljsfindreferences.h b/src/plugins/qmljseditor/qmljsfindreferences.h
index a525979651..4ee3c988f5 100644
--- a/src/plugins/qmljseditor/qmljsfindreferences.h
+++ b/src/plugins/qmljseditor/qmljsfindreferences.h
@@ -87,6 +87,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);