Commit 4de9fd8d authored by Eike Ziller's avatar Eike Ziller

Implement "Search Again" for symbol search.

Task-number: QTCREATORBUG-621

Change-Id: I4bd39c88afc1df93712b1d9a76f875516c657f3d
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent 26d8b875
......@@ -184,6 +184,7 @@ private:
} // namespace CppTools
Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes)
Q_DECLARE_METATYPE(CppTools::SearchSymbols::SymbolTypes)
Q_DECLARE_METATYPE(CppTools::ModelItemInfo)
#endif // SEARCHSYMBOLS_H
......@@ -59,22 +59,24 @@ namespace {
const char * const SETTINGS_SEARCHSCOPE = "SearchScope";
void runSearch(QFutureInterface<Find::SearchResultItem> &future,
QString txt, Find::FindFlags findFlags, CPlusPlus::Snapshot snapshot,
SearchSymbols::SymbolTypes types, QSet<QString> fileNames)
SymbolsFindParameters parameters, CPlusPlus::Snapshot snapshot,
QSet<QString> fileNames)
{
future.setProgressRange(0, snapshot.size());
future.setProgressValue(0);
int progress = 0;
SearchSymbols search;
search.setSymbolsToSearchFor(types);
search.setSymbolsToSearchFor(parameters.types);
search.setSeparateScope(true);
CPlusPlus::Snapshot::const_iterator it = snapshot.begin();
QString findString = (findFlags & Find::FindRegularExpression ? txt : QRegExp::escape(txt));
if (findFlags & Find::FindWholeWords)
QString findString = (parameters.flags & Find::FindRegularExpression
? parameters.text : QRegExp::escape(parameters.text));
if (parameters.flags & Find::FindWholeWords)
findString = QString::fromLatin1("\\b%1\\b").arg(findString);
QRegExp matcher(findString, (findFlags & Find::FindCaseSensitively ? Qt::CaseSensitive : Qt::CaseInsensitive));
QRegExp matcher(findString, (parameters.flags & Find::FindCaseSensitively
? Qt::CaseSensitive : Qt::CaseInsensitive));
while (it != snapshot.end() && !future.isCanceled()) {
if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) {
QVector<Find::SearchResultItem> resultItems;
......@@ -82,7 +84,8 @@ namespace {
foreach (const ModelItemInfo &info, modelInfos) {
int index = matcher.indexIn(info.symbolName);
if (index != -1) {
QStringList path = info.fullyQualifiedName.mid(0, info.fullyQualifiedName.size() - 1);
QStringList path = info.fullyQualifiedName.mid(0,
info.fullyQualifiedName.size() - 1);
Find::SearchResultItem item;
item.path = path;
item.text = info.symbolName;
......@@ -150,12 +153,28 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
{
Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
Find::SearchResult *search = window->startNewSearch(label(), toolTip(findFlags), txt);
connect(search, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem)));
search->setSearchAgainSupported(true);
connect(search, SIGNAL(activated(Find::SearchResultItem)),
this, SLOT(openEditor(Find::SearchResultItem)));
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool)));
window->popup(true);
SymbolsFindParameters parameters;
parameters.text = txt;
parameters.flags = findFlags;
parameters.types = m_symbolsToSearch;
parameters.scope = m_scope;
search->setUserData(qVariantFromValue(parameters));
startSearch(search);
}
void SymbolsFindFilter::startSearch(Find::SearchResult *search)
{
SymbolsFindParameters parameters = search->userData().value<SymbolsFindParameters>();
QSet<QString> projectFileNames;
if (m_scope == SymbolsFindFilter::SearchProjectsOnly) {
if (parameters.scope == SymbolsFindFilter::SearchProjectsOnly) {
foreach (ProjectExplorer::Project *project,
ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects()) {
projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet();
......@@ -168,10 +187,9 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
this, SLOT(finish()));
connect(watcher, SIGNAL(resultsReadyAt(int,int)),
this, SLOT(addResults(int, int)));
watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, QString,
Find::FindFlags, CPlusPlus::Snapshot,
SearchSymbols::SymbolTypes, QSet<QString> >(runSearch, txt, findFlags, m_manager->snapshot(),
m_symbolsToSearch, projectFileNames));
watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, SymbolsFindParameters,
CPlusPlus::Snapshot, QSet<QString> >(runSearch, parameters,
m_manager->snapshot(), projectFileNames));
Core::ICore::instance()->progressManager()->addTask(watcher->future(),
tr("Searching"),
Find::Constants::TASK_SEARCH);
......@@ -254,6 +272,14 @@ void SymbolsFindFilter::onAllTasksFinished(const QString &type)
}
}
void SymbolsFindFilter::searchAgain()
{
Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender());
QTC_ASSERT(search, return);
search->reset();
startSearch(search);
}
QString SymbolsFindFilter::label() const
{
return tr("C++ Symbols:");
......
......@@ -89,10 +89,12 @@ private slots:
void cancel();
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
void searchAgain();
private:
QString label() const;
QString toolTip(Find::FindFlags findFlags) const;
void startSearch(Find::SearchResult *search);
CppModelManager *m_manager;
bool m_enabled;
......@@ -102,6 +104,15 @@ private:
SearchScope m_scope;
};
class SymbolsFindParameters
{
public:
QString text;
Find::FindFlags flags;
SearchSymbols::SymbolTypes types;
SymbolsFindFilter::SearchScope scope;
};
class SymbolsFindFilterConfigWidget : public QWidget
{
Q_OBJECT
......@@ -128,4 +139,7 @@ private:
} // Internal
} // CppTools
Q_DECLARE_METATYPE(CppTools::Internal::SymbolsFindFilter::SearchScope)
Q_DECLARE_METATYPE(CppTools::Internal::SymbolsFindParameters)
#endif // SYMBOLSFINDFILTER_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