Implement "Search Again" for symbol search.

Task-number: QTCREATORBUG-621

Change-Id: I4bd39c88afc1df93712b1d9a76f875516c657f3d
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
Eike Ziller
2011-12-15 08:01:58 +01:00
parent 26d8b8753c
commit 4de9fd8dac
3 changed files with 54 additions and 13 deletions

View File

@@ -184,6 +184,7 @@ private:
} // namespace CppTools } // namespace CppTools
Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes) Q_DECLARE_OPERATORS_FOR_FLAGS(CppTools::SearchSymbols::SymbolTypes)
Q_DECLARE_METATYPE(CppTools::SearchSymbols::SymbolTypes)
Q_DECLARE_METATYPE(CppTools::ModelItemInfo) Q_DECLARE_METATYPE(CppTools::ModelItemInfo)
#endif // SEARCHSYMBOLS_H #endif // SEARCHSYMBOLS_H

View File

@@ -59,22 +59,24 @@ namespace {
const char * const SETTINGS_SEARCHSCOPE = "SearchScope"; const char * const SETTINGS_SEARCHSCOPE = "SearchScope";
void runSearch(QFutureInterface<Find::SearchResultItem> &future, void runSearch(QFutureInterface<Find::SearchResultItem> &future,
QString txt, Find::FindFlags findFlags, CPlusPlus::Snapshot snapshot, SymbolsFindParameters parameters, CPlusPlus::Snapshot snapshot,
SearchSymbols::SymbolTypes types, QSet<QString> fileNames) QSet<QString> fileNames)
{ {
future.setProgressRange(0, snapshot.size()); future.setProgressRange(0, snapshot.size());
future.setProgressValue(0); future.setProgressValue(0);
int progress = 0; int progress = 0;
SearchSymbols search; SearchSymbols search;
search.setSymbolsToSearchFor(types); search.setSymbolsToSearchFor(parameters.types);
search.setSeparateScope(true); search.setSeparateScope(true);
CPlusPlus::Snapshot::const_iterator it = snapshot.begin(); CPlusPlus::Snapshot::const_iterator it = snapshot.begin();
QString findString = (findFlags & Find::FindRegularExpression ? txt : QRegExp::escape(txt)); QString findString = (parameters.flags & Find::FindRegularExpression
if (findFlags & Find::FindWholeWords) ? parameters.text : QRegExp::escape(parameters.text));
if (parameters.flags & Find::FindWholeWords)
findString = QString::fromLatin1("\\b%1\\b").arg(findString); 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()) { while (it != snapshot.end() && !future.isCanceled()) {
if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) { if (fileNames.isEmpty() || fileNames.contains(it.value()->fileName())) {
QVector<Find::SearchResultItem> resultItems; QVector<Find::SearchResultItem> resultItems;
@@ -82,7 +84,8 @@ namespace {
foreach (const ModelItemInfo &info, modelInfos) { foreach (const ModelItemInfo &info, modelInfos) {
int index = matcher.indexIn(info.symbolName); int index = matcher.indexIn(info.symbolName);
if (index != -1) { 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; Find::SearchResultItem item;
item.path = path; item.path = path;
item.text = info.symbolName; item.text = info.symbolName;
@@ -150,12 +153,28 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
{ {
Find::SearchResultWindow *window = Find::SearchResultWindow::instance(); Find::SearchResultWindow *window = Find::SearchResultWindow::instance();
Find::SearchResult *search = window->startNewSearch(label(), toolTip(findFlags), txt); 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(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
connect(this, SIGNAL(enabledChanged(bool)), search, SLOT(setSearchAgainEnabled(bool)));
window->popup(true); 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; QSet<QString> projectFileNames;
if (m_scope == SymbolsFindFilter::SearchProjectsOnly) { if (parameters.scope == SymbolsFindFilter::SearchProjectsOnly) {
foreach (ProjectExplorer::Project *project, foreach (ProjectExplorer::Project *project,
ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects()) { ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projects()) {
projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet(); projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet();
@@ -168,10 +187,9 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags)
this, SLOT(finish())); this, SLOT(finish()));
connect(watcher, SIGNAL(resultsReadyAt(int,int)), connect(watcher, SIGNAL(resultsReadyAt(int,int)),
this, SLOT(addResults(int, int))); this, SLOT(addResults(int, int)));
watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, QString, watcher->setFuture(QtConcurrent::run<Find::SearchResultItem, SymbolsFindParameters,
Find::FindFlags, CPlusPlus::Snapshot, CPlusPlus::Snapshot, QSet<QString> >(runSearch, parameters,
SearchSymbols::SymbolTypes, QSet<QString> >(runSearch, txt, findFlags, m_manager->snapshot(), m_manager->snapshot(), projectFileNames));
m_symbolsToSearch, projectFileNames));
Core::ICore::instance()->progressManager()->addTask(watcher->future(), Core::ICore::instance()->progressManager()->addTask(watcher->future(),
tr("Searching"), tr("Searching"),
Find::Constants::TASK_SEARCH); 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 QString SymbolsFindFilter::label() const
{ {
return tr("C++ Symbols:"); return tr("C++ Symbols:");

View File

@@ -89,10 +89,12 @@ private slots:
void cancel(); void cancel();
void onTaskStarted(const QString &type); void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type); void onAllTasksFinished(const QString &type);
void searchAgain();
private: private:
QString label() const; QString label() const;
QString toolTip(Find::FindFlags findFlags) const; QString toolTip(Find::FindFlags findFlags) const;
void startSearch(Find::SearchResult *search);
CppModelManager *m_manager; CppModelManager *m_manager;
bool m_enabled; bool m_enabled;
@@ -102,6 +104,15 @@ private:
SearchScope m_scope; SearchScope m_scope;
}; };
class SymbolsFindParameters
{
public:
QString text;
Find::FindFlags flags;
SearchSymbols::SymbolTypes types;
SymbolsFindFilter::SearchScope scope;
};
class SymbolsFindFilterConfigWidget : public QWidget class SymbolsFindFilterConfigWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@@ -128,4 +139,7 @@ private:
} // Internal } // Internal
} // CppTools } // CppTools
Q_DECLARE_METATYPE(CppTools::Internal::SymbolsFindFilter::SearchScope)
Q_DECLARE_METATYPE(CppTools::Internal::SymbolsFindParameters)
#endif // SYMBOLSFINDFILTER_H #endif // SYMBOLSFINDFILTER_H