diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 1d8911f7c67..75232ac1ea1 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -162,7 +162,7 @@ public: CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager) : QObject(modelManager), _modelManager(modelManager), - _resultWindow(Find::SearchResultWindow::instance()) + m_currentSearch(0) { m_watcher.setPendingResultsLimit(1); connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int))); @@ -227,9 +227,9 @@ static void find_helper(QFutureInterface &future, void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) { - Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly); + m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly); - connect(search, SIGNAL(activated(Find::SearchResultItem)), + connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); findAll_helper(symbol, context); @@ -242,14 +242,14 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus: const QString textToReplace = replacement.isEmpty() ? QString::fromUtf8(id->chars(), id->size()) : replacement; - Find::SearchResult *search = _resultWindow->startNewSearch( + m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch( Find::SearchResultWindow::SearchAndReplace, QLatin1String("CppEditor")); - _resultWindow->setTextToReplace(textToReplace); + m_currentSearch->setTextToReplace(textToReplace); - connect(search, SIGNAL(activated(Find::SearchResultItem)), + connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); - connect(search, SIGNAL(replaceButtonClicked(QString,QList)), + connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList)), SLOT(onReplaceButtonClicked(QString,QList))); findAll_helper(symbol, context); @@ -261,7 +261,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont if (! (symbol && symbol->identifier())) return; - _resultWindow->popup(true); + Find::SearchResultWindow::instance()->popup(true); const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy(); @@ -275,7 +275,7 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"), CppTools::Constants::TASK_SEARCH); - connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup())); + connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup())); } void CppFindReferences::onReplaceButtonClicked(const QString &text, @@ -284,7 +284,7 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text, const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items); if (!fileNames.isEmpty()) { _modelManager->updateSourceFiles(fileNames); - _resultWindow->hide(); + Find::SearchResultWindow::instance()->hide(); } } @@ -292,7 +292,7 @@ void CppFindReferences::displayResults(int first, int last) { for (int index = first; index != last; ++index) { Usage result = m_watcher.future().resultAt(index); - _resultWindow->addResult(result.path, + m_currentSearch->addResult(result.path, result.line, result.lineText, result.col, @@ -302,7 +302,8 @@ void CppFindReferences::displayResults(int first, int last) void CppFindReferences::searchFinished() { - _resultWindow->finishSearch(); + m_currentSearch->finishSearch(); + m_currentSearch = 0; emit changed(); } @@ -413,11 +414,11 @@ static void findMacroUses_helper(QFutureInterface &future, void CppFindReferences::findMacroUses(const Macro ¯o) { - Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly); + m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly); - _resultWindow->popup(true); + Find::SearchResultWindow::instance()->popup(true); - connect(search, SIGNAL(activated(Find::SearchResultItem)), + connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); const Snapshot snapshot = _modelManager->snapshot(); @@ -427,7 +428,7 @@ void CppFindReferences::findMacroUses(const Macro ¯o) { // ### FIXME: Encoding? const QByteArray &source = getSource(macro.fileName(), workingCopy).toLatin1(); - _resultWindow->addResult(macro.fileName(), macro.line(), + m_currentSearch->addResult(macro.fileName(), macro.line(), source.mid(macro.offset(), macro.length()), 0, macro.length()); } @@ -438,7 +439,7 @@ void CppFindReferences::findMacroUses(const Macro ¯o) Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching"), CppTools::Constants::TASK_SEARCH); - connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup())); + connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup())); } DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot snapshot) diff --git a/src/plugins/cpptools/cppfindreferences.h b/src/plugins/cpptools/cppfindreferences.h index c98b812f5b4..6d6c3c85584 100644 --- a/src/plugins/cpptools/cppfindreferences.h +++ b/src/plugins/cpptools/cppfindreferences.h @@ -46,8 +46,8 @@ QT_FORWARD_DECLARE_CLASS(QTimer) namespace Find { - class SearchResultWindow; struct SearchResultItem; + class SearchResult; } // namespace Find namespace CPlusPlus { @@ -92,7 +92,7 @@ private: private: QPointer _modelManager; - Find::SearchResultWindow *_resultWindow; + Find::SearchResult *m_currentSearch; QFutureWatcher m_watcher; mutable QMutex m_depsLock; diff --git a/src/plugins/cpptools/symbolsfindfilter.cpp b/src/plugins/cpptools/symbolsfindfilter.cpp index 5254d63e577..f14ef8d1431 100644 --- a/src/plugins/cpptools/symbolsfindfilter.cpp +++ b/src/plugins/cpptools/symbolsfindfilter.cpp @@ -102,10 +102,11 @@ namespace { SymbolsFindFilter::SymbolsFindFilter(CppModelManager *manager) : m_manager(manager), - m_isRunning(false), - m_enabled(true), - m_symbolsToSearch(SearchSymbols::AllTypes), - m_scope(SearchProjectsOnly) + m_isRunning(false), + m_enabled(true), + m_currentSearch(0), + m_symbolsToSearch(SearchSymbols::AllTypes), + m_scope(SearchProjectsOnly) { // for disabling while parser is running connect(Core::ICore::instance()->progressManager(), SIGNAL(taskStarted(QString)), @@ -154,8 +155,8 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) m_isRunning = true; emit changed(); Find::SearchResultWindow *window = Find::SearchResultWindow::instance(); - Find::SearchResult *result = window->startNewSearch(); - connect(result, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); + m_currentSearch = window->startNewSearch(); + connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); window->popup(true); m_search.setSymbolsToSearchFor(m_symbolsToSearch); @@ -179,17 +180,16 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) void SymbolsFindFilter::addResults(int begin, int end) { - Find::SearchResultWindow *window = Find::SearchResultWindow::instance(); QList items; for (int i = begin; i < end; ++i) items << m_watcher.resultAt(i); - window->addResults(items, Find::SearchResultWindow::AddSorted); + m_currentSearch->addResults(items, Find::SearchResult::AddSorted); } void SymbolsFindFilter::finish() { - Find::SearchResultWindow *window = Find::SearchResultWindow::instance(); - window->finishSearch(); + m_currentSearch->finishSearch(); + m_currentSearch = 0; m_isRunning = false; emit changed(); } diff --git a/src/plugins/cpptools/symbolsfindfilter.h b/src/plugins/cpptools/symbolsfindfilter.h index 04995e42a39..fee3e5bf29a 100644 --- a/src/plugins/cpptools/symbolsfindfilter.h +++ b/src/plugins/cpptools/symbolsfindfilter.h @@ -95,6 +95,7 @@ private: bool m_isRunning; bool m_enabled; QFutureWatcher m_watcher; + Find::SearchResult *m_currentSearch; SearchSymbols::SymbolTypes m_symbolsToSearch; SearchSymbols m_search; SearchScope m_scope; diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp index 1464c1c3f1c..e6269a84663 100644 --- a/src/plugins/find/searchresulttreemodel.cpp +++ b/src/plugins/find/searchresulttreemodel.cpp @@ -336,19 +336,19 @@ QSet SearchResultTreeModel::addPath(const QStringList &p return pathNodes; } -void SearchResultTreeModel::addResultsToCurrentParent(const QList &items, SearchResultWindow::AddMode mode) +void SearchResultTreeModel::addResultsToCurrentParent(const QList &items, SearchResult::AddMode mode) { if (!m_currentParent) return; - if (mode == SearchResultWindow::AddOrdered) { + if (mode == SearchResult::AddOrdered) { // this is the mode for e.g. text search beginInsertRows(m_currentIndex, m_currentParent->childrenCount(), m_currentParent->childrenCount() + items.count()); foreach (const SearchResultItem &item, items) { m_currentParent->appendChild(item); } endInsertRows(); - } else if (mode == SearchResultWindow::AddSorted) { + } else if (mode == SearchResult::AddSorted) { foreach (const SearchResultItem &item, items) { SearchResultTreeItem *existingItem; const int insertionIndex = m_currentParent->insertionIndex(item, &existingItem); @@ -386,7 +386,7 @@ static bool lessThanByPath(const SearchResultItem &a, const SearchResultItem &b) * Adds the search result to the list of results, creating nodes for the path when * necessary. */ -QList SearchResultTreeModel::addResults(const QList &items, SearchResultWindow::AddMode mode) +QList SearchResultTreeModel::addResults(const QList &items, SearchResult::AddMode mode) { QSet pathNodes; QList sortedItems = items; diff --git a/src/plugins/find/searchresulttreemodel.h b/src/plugins/find/searchresulttreemodel.h index cefe31f2d84..20927ccecdb 100644 --- a/src/plugins/find/searchresulttreemodel.h +++ b/src/plugins/find/searchresulttreemodel.h @@ -68,7 +68,7 @@ public: QModelIndex next(const QModelIndex &idx, bool includeGenerated = false, bool *wrapped = 0) const; QModelIndex prev(const QModelIndex &idx, bool includeGenerated = false, bool *wrapped = 0) const; - QList addResults(const QList &items, SearchResultWindow::AddMode mode); + QList addResults(const QList &items, SearchResult::AddMode mode); QModelIndex find(const QRegExp &expr, const QModelIndex &index, QTextDocument::FindFlags flags, bool *wrapped = 0); @@ -84,7 +84,7 @@ public slots: private: QModelIndex index(SearchResultTreeItem *item) const; - void addResultsToCurrentParent(const QList &items, SearchResultWindow::AddMode mode); + void addResultsToCurrentParent(const QList &items, SearchResult::AddMode mode); QSet addPath(const QStringList &path); QVariant data(const SearchResultTreeItem *row, int role) const; bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true); diff --git a/src/plugins/find/searchresulttreeview.cpp b/src/plugins/find/searchresulttreeview.cpp index 5a3bd81f7b0..c4f66e10799 100644 --- a/src/plugins/find/searchresulttreeview.cpp +++ b/src/plugins/find/searchresulttreeview.cpp @@ -70,7 +70,7 @@ void SearchResultTreeView::clear() m_model->clear(); } -void SearchResultTreeView::addResults(const QList &items, Find::SearchResultWindow::AddMode mode) +void SearchResultTreeView::addResults(const QList &items, Find::SearchResult::AddMode mode) { QList addedParents = m_model->addResults(items, mode); if (m_autoExpandResults && !addedParents.isEmpty()) { diff --git a/src/plugins/find/searchresulttreeview.h b/src/plugins/find/searchresulttreeview.h index fc912848458..e12c5d66e33 100644 --- a/src/plugins/find/searchresulttreeview.h +++ b/src/plugins/find/searchresulttreeview.h @@ -53,7 +53,7 @@ public: void setTextEditorFont(const QFont &font); SearchResultTreeModel *model() const; - void addResults(const QList &items, SearchResultWindow::AddMode mode); + void addResults(const QList &items, SearchResult::AddMode mode); signals: void jumpToSearchResult(const SearchResultItem &item); diff --git a/src/plugins/find/searchresultwindow.cpp b/src/plugins/find/searchresultwindow.cpp index d2cc7d94f81..73957b9e5d6 100644 --- a/src/plugins/find/searchresultwindow.cpp +++ b/src/plugins/find/searchresultwindow.cpp @@ -414,8 +414,7 @@ SearchResultWindow *SearchResultWindow::instance() /*! \fn void SearchResultWindow::setTextToReplace(const QString &textToReplace) - \brief Sets the value in the UI element that allows the user to type - the text that should replace text in search results to \a textToReplace. + \internal */ void SearchResultWindow::setTextToReplace(const QString &textToReplace) { @@ -424,7 +423,7 @@ void SearchResultWindow::setTextToReplace(const QString &textToReplace) /*! \fn QString SearchResultWindow::textToReplace() const - \brief Returns the text that should replace the text in search results. + \internal */ QString SearchResultWindow::textToReplace() const { @@ -534,8 +533,7 @@ SearchResult *SearchResultWindow::startNewSearch(SearchMode searchOrSearchAndRep /*! \fn void SearchResultWindow::finishSearch() - \brief Notifies the search result window that the current search - has finished, and the UI should reflect that. + \internal */ void SearchResultWindow::finishSearch() { @@ -582,16 +580,6 @@ bool SearchResultWindow::isEmpty() const return (d->m_searchResultTreeView->model()->rowCount() < 1); } -/*! - \fn int SearchResultWindow::numberOfResults() const - Returns the number of search results currently shown in the search - results window. -*/ -int SearchResultWindow::numberOfResults() const -{ - return d->m_itemCount; -} - /*! \fn bool SearchResultWindow::hasFocus() \internal @@ -653,15 +641,7 @@ void SearchResultWindow::handleJumpToSearchResult(const SearchResultItem &item) /*! \fn void SearchResultWindow::addResult(const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart, int searchTermLength, const QVariant &userData) - \brief Adds a single result line to the search results. - - The \a fileName, \a lineNumber and \a rowText are shown in the result line. - \a searchTermStart and \a searchTermLength specify the region that - should be visually marked (string position and length in \a rowText). - You can attach arbitrary \a userData to the search result, which can - be used e.g. when reacting to the signals of the SearchResult for your search. - - \sa addResults() + \internal */ void SearchResultWindow::addResult(const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart, int searchTermLength, const QVariant &userData) @@ -674,17 +654,14 @@ void SearchResultWindow::addResult(const QString &fileName, int lineNumber, cons item.textMarkLength = searchTermLength; item.useTextEditorFont = true; item.userData = userData; - addResults(QList() << item, AddOrdered); + addResults(QList() << item, SearchResult::AddOrdered); } /*! - \fn void SearchResultWindow::addResults(QList &items, AddMode mode) - \brief Adds all of the given search result \a items to the search - results window. - - \sa addResult() + \fn void SearchResultWindow::addResults(const QList &items, SearchResult::AddMode mode) + \internal */ -void SearchResultWindow::addResults(QList &items, AddMode mode) +void SearchResultWindow::addResults(const QList &items, SearchResult::AddMode mode) { bool firstItems = (d->m_itemCount == 0); d->m_itemCount += items.size(); @@ -845,6 +822,93 @@ bool SearchResultWindow::canNavigate() return true; } +/*! + \fn void SearchResult::setUserData(const QVariant &data) + \brief Attach some random \a data to this search, that you can use later. + + \sa userData() +*/ +void SearchResult::setUserData(const QVariant &data) +{ + m_userData = data; +} + +/*! + \fn void SearchResult::userData() + \brief Return the data that was attached to this search by calling setUserData(). + + \sa setUserData() +*/ +QVariant SearchResult::userData() const +{ + return m_userData; +} + +/*! + \fn QString SearchResult::textToReplace() const + \brief Returns the text that should replace the text in search results. +*/ +QString SearchResult::textToReplace() const +{ + // TODO: should point to associated SearchResultWidget + return SearchResultWindow::instance()->textToReplace(); +} + +/*! + \fn void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &rowText, int searchTermStart, int searchTermLength, const QVariant &userData) + \brief Adds a single result line to the search results. + + The \a fileName, \a lineNumber and \a rowText are shown in the result line. + \a searchTermStart and \a searchTermLength specify the region that + should be visually marked (string position and length in \a rowText). + You can attach arbitrary \a userData to the search result, which can + be used e.g. when reacting to the signals of the SearchResult for your search. + + \sa addResults() +*/ +void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &lineText, + int searchTermStart, int searchTermLength, const QVariant &userData) +{ + // TODO: should point to associated SearchResultWidget + SearchResultWindow::instance()->addResult(fileName, lineNumber, lineText, + searchTermStart, searchTermLength, userData); +} + +/*! + \fn void SearchResult::addResults(const QList &items, SearchResult::AddMode mode) + \brief Adds all of the given search result \a items to the search + results window. + + \sa addResult() +*/ +void SearchResult::addResults(const QList &items, AddMode mode) +{ + // TODO: should point to associated SearchResultWidget + SearchResultWindow::instance()->addResults(items, mode); +} + +/*! + \fn void SearchResult::finishSearch() + \brief Notifies the search result window that the current search + has finished, and the UI should reflect that. +*/ +void SearchResult::finishSearch() +{ + // TODO: should point to associated SearchResultWidget + SearchResultWindow::instance()->finishSearch(); +} + +/*! + \fn void SearchResult::setTextToReplace(const QString &textToReplace) + \brief Sets the value in the UI element that allows the user to type + the text that should replace text in search results to \a textToReplace. +*/ +void SearchResult::setTextToReplace(const QString &textToReplace) +{ + // TODO: should point to associated SearchResultWidget + SearchResultWindow::instance()->setTextToReplace(textToReplace); +} + } // namespace Find diff --git a/src/plugins/find/searchresultwindow.h b/src/plugins/find/searchresultwindow.h index 748d30c3e66..5203f3cba77 100644 --- a/src/plugins/find/searchresultwindow.h +++ b/src/plugins/find/searchresultwindow.h @@ -89,8 +89,21 @@ class FIND_EXPORT SearchResult : public QObject Q_OBJECT public: - void setUserData(const QVariant &data) { m_userData = data; } - QVariant userData() const { return m_userData; } + enum AddMode { + AddSorted, + AddOrdered + }; + + void setUserData(const QVariant &data); + QVariant userData() const; + QString textToReplace() const; + +public slots: + void addResult(const QString &fileName, int lineNumber, const QString &lineText, + int searchTermStart, int searchTermLength, const QVariant &userData = QVariant()); + void addResults(const QList &items, AddMode mode); + void finishSearch(); + void setTextToReplace(const QString &textToReplace); signals: void activated(const Find::SearchResultItem &item); @@ -113,10 +126,6 @@ public: SearchAndReplace }; - enum AddMode { - AddSorted, - AddOrdered - }; SearchResultWindow(); virtual ~SearchResultWindow(); @@ -129,7 +138,6 @@ public: int priorityInStatusBar() const; void visibilityChanged(bool visible); bool isEmpty() const; - int numberOfResults() const; bool hasFocus(); bool canFocus(); void setFocus(); @@ -142,20 +150,12 @@ public: void setTextEditorFont(const QFont &font); - void setTextToReplace(const QString &textToReplace); - QString textToReplace() const; - // search result object only lives till next startnewsearch call SearchResult *startNewSearch(SearchMode searchOrSearchAndReplace = SearchOnly, const QString &cfgGroup = QString()); - void addResults(QList &items, AddMode mode); - public slots: void clearContents(); - void addResult(const QString &fileName, int lineNumber, const QString &lineText, - int searchTermStart, int searchTermLength, const QVariant &userData = QVariant()); - void finishSearch(); private slots: void handleExpandCollapseToolButton(bool checked); @@ -165,6 +165,15 @@ private slots: void hideNoUndoWarning(); private: + // TODO: move to the new SearchResultWidget + void addResult(const QString &fileName, int lineNumber, const QString &lineText, + int searchTermStart, int searchTermLength, const QVariant &userData); + void addResults(const QList &items, SearchResult::AddMode mode); // TODO: move to SearchResultWidget) + void finishSearch(); + void setTextToReplace(const QString &textToReplace); + QString textToReplace() const; + + void setShowReplaceUI(bool show); void readSettings(); void writeSettings(); @@ -174,6 +183,7 @@ private: Internal::SearchResultWindowPrivate *d; static SearchResultWindow *m_instance; + friend class SearchResult; }; } // namespace Find diff --git a/src/plugins/projectexplorer/allprojectsfind.cpp b/src/plugins/projectexplorer/allprojectsfind.cpp index 0db0c776d75..12bbf71481d 100644 --- a/src/plugins/projectexplorer/allprojectsfind.cpp +++ b/src/plugins/projectexplorer/allprojectsfind.cpp @@ -52,10 +52,9 @@ using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; using namespace TextEditor; -AllProjectsFind::AllProjectsFind(ProjectExplorerPlugin *plugin, SearchResultWindow *resultWindow) - : BaseFileFind(resultWindow), - m_plugin(plugin), - m_configWidget(0) +AllProjectsFind::AllProjectsFind(ProjectExplorerPlugin *plugin) + : m_plugin(plugin), + m_configWidget(0) { connect(m_plugin, SIGNAL(fileListChanged()), this, SIGNAL(changed())); } diff --git a/src/plugins/projectexplorer/allprojectsfind.h b/src/plugins/projectexplorer/allprojectsfind.h index 2da5afec366..a00b6bd3da5 100644 --- a/src/plugins/projectexplorer/allprojectsfind.h +++ b/src/plugins/projectexplorer/allprojectsfind.h @@ -49,7 +49,7 @@ class AllProjectsFind : public TextEditor::BaseFileFind Q_OBJECT public: - AllProjectsFind(ProjectExplorerPlugin *plugin, Find::SearchResultWindow *resultWindow); + AllProjectsFind(ProjectExplorerPlugin *plugin); QString id() const; QString displayName() const; diff --git a/src/plugins/projectexplorer/currentprojectfind.cpp b/src/plugins/projectexplorer/currentprojectfind.cpp index 3d99eb91ee6..8754a4403db 100644 --- a/src/plugins/projectexplorer/currentprojectfind.cpp +++ b/src/plugins/projectexplorer/currentprojectfind.cpp @@ -44,8 +44,8 @@ using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; using namespace TextEditor; -CurrentProjectFind::CurrentProjectFind(ProjectExplorerPlugin *plugin, SearchResultWindow *resultWindow) - : AllProjectsFind(plugin, resultWindow), +CurrentProjectFind::CurrentProjectFind(ProjectExplorerPlugin *plugin) + : AllProjectsFind(plugin), m_plugin(plugin) { connect(m_plugin, SIGNAL(currentProjectChanged(ProjectExplorer::Project*)), diff --git a/src/plugins/projectexplorer/currentprojectfind.h b/src/plugins/projectexplorer/currentprojectfind.h index a5bae10a87b..1da22d9be6d 100644 --- a/src/plugins/projectexplorer/currentprojectfind.h +++ b/src/plugins/projectexplorer/currentprojectfind.h @@ -51,7 +51,7 @@ class CurrentProjectFind : public AllProjectsFind Q_OBJECT public: - CurrentProjectFind(ProjectExplorerPlugin *plugin, Find::SearchResultWindow *resultWindow); + CurrentProjectFind(ProjectExplorerPlugin *plugin); QString id() const; QString displayName() const; diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 448da71631a..15499369c6e 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -400,12 +400,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er ProcessStepFactory *processStepFactory = new ProcessStepFactory; addAutoReleasedObject(processStepFactory); - AllProjectsFind *allProjectsFind = new AllProjectsFind(this, - Find::SearchResultWindow::instance()); + AllProjectsFind *allProjectsFind = new AllProjectsFind(this); addAutoReleasedObject(allProjectsFind); - CurrentProjectFind *currentProjectFind = new CurrentProjectFind(this, - Find::SearchResultWindow::instance()); + CurrentProjectFind *currentProjectFind = new CurrentProjectFind(this); addAutoReleasedObject(currentProjectFind); addAutoReleasedObject(new LocalApplicationRunControlFactory); diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp index 974ea395118..d8afb967fcd 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.cpp +++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp @@ -774,8 +774,8 @@ public: } // end of anonymous namespace FindReferences::FindReferences(QObject *parent) - : QObject(parent) - , _resultWindow(Find::SearchResultWindow::instance()) + : QObject(parent), + m_currentSearch(0) { m_watcher.setPendingResultsLimit(1); connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int))); @@ -904,31 +904,30 @@ void FindReferences::displayResults(int first, int last) Usage dummy = m_watcher.future().resultAt(0); QString replacement = dummy.path; - Find::SearchResult *search; if (replacement.isEmpty()) { - search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly); + m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchOnly); } else { - search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchAndReplace); - _resultWindow->setTextToReplace(replacement); - connect(search, SIGNAL(replaceButtonClicked(QString,QList)), + m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchAndReplace); + m_currentSearch->setTextToReplace(replacement); + connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList)), SLOT(onReplaceButtonClicked(QString,QList))); } - connect(search, SIGNAL(activated(Find::SearchResultItem)), + connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); - _resultWindow->popup(true); + Find::SearchResultWindow::instance()->popup(true); Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); Core::FutureProgress *progress = progressManager->addTask( m_watcher.future(), tr("Searching"), QmlJSEditor::Constants::TASK_SEARCH); - connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup())); + connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup())); ++first; } for (int index = first; index != last; ++index) { Usage result = m_watcher.future().resultAt(index); - _resultWindow->addResult(result.path, + m_currentSearch->addResult(result.path, result.line, result.lineText, result.col, @@ -938,7 +937,8 @@ void FindReferences::displayResults(int first, int last) void FindReferences::searchFinished() { - _resultWindow->finishSearch(); + m_currentSearch->finishSearch(); + m_currentSearch = 0; emit changed(); } @@ -973,5 +973,5 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QListupdateSourceFiles(changedUnsavedEditors, false); - _resultWindow->hide(); + Find::SearchResultWindow::instance()->hide(); } diff --git a/src/plugins/qmljseditor/qmljsfindreferences.h b/src/plugins/qmljseditor/qmljsfindreferences.h index 636132a872d..326213d8bf8 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.h +++ b/src/plugins/qmljseditor/qmljsfindreferences.h @@ -35,7 +35,6 @@ #include #include -#include #include #include #include @@ -44,8 +43,8 @@ QT_FORWARD_DECLARE_CLASS(QTimer) namespace Find { - class SearchResultWindow; struct SearchResultItem; + class SearchResult; } // namespace Find namespace QmlJSEditor { @@ -90,7 +89,7 @@ private Q_SLOTS: void onReplaceButtonClicked(const QString &text, const QList &items); private: - Find::SearchResultWindow *_resultWindow; + Find::SearchResult *m_currentSearch; QFutureWatcher m_watcher; }; diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp index 5c12527f9a2..7ede1725c05 100644 --- a/src/plugins/texteditor/basefilefind.cpp +++ b/src/plugins/texteditor/basefilefind.cpp @@ -61,8 +61,9 @@ using namespace Utils; using namespace Find; using namespace TextEditor; -BaseFileFind::BaseFileFind(SearchResultWindow *resultWindow) - : m_resultWindow(resultWindow), +BaseFileFind::BaseFileFind() + : m_currentSearch(0), + m_currentSearchCount(0), m_isSearching(false), m_resultLabel(0), m_filterCombo(0) @@ -115,20 +116,22 @@ void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags, if (m_filterCombo) updateComboEntries(m_filterCombo, true); m_watcher.setFuture(QFuture()); - SearchResult *result = m_resultWindow->startNewSearch(searchMode, - searchMode == SearchResultWindow::SearchAndReplace - ? QString::fromLatin1("TextEditor") - : QString()); + m_currentSearchCount = 0; + m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(searchMode, + searchMode == SearchResultWindow::SearchAndReplace + ? QString::fromLatin1("TextEditor") + : QString()); + m_currentSearch->setTextToReplace(txt); QVariantList searchParameters; searchParameters << qVariantFromValue(txt) << qVariantFromValue(findFlags); - result->setUserData(searchParameters); - connect(result, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); + m_currentSearch->setUserData(searchParameters); + connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); if (searchMode == SearchResultWindow::SearchAndReplace) { - connect(result, SIGNAL(replaceButtonClicked(QString,QList)), + connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList)), this, SLOT(doReplace(QString,QList))); } - connect(result, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool))); - m_resultWindow->popup(true); + connect(m_currentSearch, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool))); + Find::SearchResultWindow::instance()->popup(true); if (findFlags & Find::FindRegularExpression) { m_watcher.setFuture(Utils::findInFilesRegExp(txt, files(), textDocumentFlagsForFindFlags(findFlags), ITextEditor::openedTextEditorsContents())); @@ -141,7 +144,7 @@ void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags, tr("Search"), Constants::TASK_SEARCH); progress->setWidget(createProgressWidget()); - connect(progress, SIGNAL(clicked()), m_resultWindow, SLOT(popup())); + connect(progress, SIGNAL(clicked()), Find::SearchResultWindow::instance(), SLOT(popup())); } void BaseFileFind::findAll(const QString &txt, Find::FindFlags findFlags) @@ -161,7 +164,7 @@ void BaseFileFind::doReplace(const QString &text, Core::FileManager *fileManager = Core::ICore::instance()->fileManager(); if (!files.isEmpty()) { fileManager->notifyFilesChangedInternally(files); - m_resultWindow->hide(); + Find::SearchResultWindow::instance()->hide(); } } @@ -179,14 +182,16 @@ void BaseFileFind::displayResult(int index) { item.userData = result.regexpCapturedTexts; items << item; } - m_resultWindow->addResults(items, Find::SearchResultWindow::AddOrdered); + m_currentSearch->addResults(items, Find::SearchResult::AddOrdered); + m_currentSearchCount += items.count(); if (m_resultLabel) - m_resultLabel->setText(tr("%1 found").arg(m_resultWindow->numberOfResults())); + m_resultLabel->setText(tr("%1 found").arg(m_currentSearchCount)); } void BaseFileFind::searchFinished() { - m_resultWindow->finishSearch(); + m_currentSearch->finishSearch(); + m_currentSearch = 0; m_isSearching = false; m_resultLabel = 0; emit changed(); @@ -202,7 +207,7 @@ QWidget *BaseFileFind::createProgressWidget() f.setPointSizeF(StyleHelper::sidebarFontSize()); m_resultLabel->setFont(f); m_resultLabel->setPalette(StyleHelper::sidebarFontPalette(m_resultLabel->palette())); - m_resultLabel->setText(tr("%1 found").arg(m_resultWindow->numberOfResults())); + m_resultLabel->setText(tr("%1 found").arg(m_currentSearchCount)); return m_resultLabel; } diff --git a/src/plugins/texteditor/basefilefind.h b/src/plugins/texteditor/basefilefind.h index 8e864ee48a0..291fac76ead 100644 --- a/src/plugins/texteditor/basefilefind.h +++ b/src/plugins/texteditor/basefilefind.h @@ -53,7 +53,6 @@ namespace Utils { class FileIterator; } namespace Find { -class SearchResultWindow; struct SearchResultItem; class IFindSupport; } @@ -65,7 +64,7 @@ class TEXTEDITOR_EXPORT BaseFileFind : public Find::IFindFilter Q_OBJECT public: - explicit BaseFileFind(Find::SearchResultWindow *resultWindow); + explicit BaseFileFind(); ~BaseFileFind(); bool isEnabled() const; @@ -101,7 +100,8 @@ private: void runNewSearch(const QString &txt, Find::FindFlags findFlags, Find::SearchResultWindow::SearchMode searchMode); - Find::SearchResultWindow *m_resultWindow; + Find::SearchResult *m_currentSearch; + int m_currentSearchCount; QFutureWatcher m_watcher; bool m_isSearching; diff --git a/src/plugins/texteditor/findincurrentfile.cpp b/src/plugins/texteditor/findincurrentfile.cpp index af9b1a7bfde..def69e03fc2 100644 --- a/src/plugins/texteditor/findincurrentfile.cpp +++ b/src/plugins/texteditor/findincurrentfile.cpp @@ -47,9 +47,8 @@ using namespace Find; using namespace TextEditor; using namespace TextEditor::Internal; -FindInCurrentFile::FindInCurrentFile(SearchResultWindow *resultWindow) - : BaseFileFind(resultWindow), - m_configWidget(0), +FindInCurrentFile::FindInCurrentFile() + : m_configWidget(0), m_currentFile(0) { connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)), diff --git a/src/plugins/texteditor/findincurrentfile.h b/src/plugins/texteditor/findincurrentfile.h index 5c804c7fb0d..dc0fdad1f9e 100644 --- a/src/plugins/texteditor/findincurrentfile.h +++ b/src/plugins/texteditor/findincurrentfile.h @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -54,7 +53,7 @@ class FindInCurrentFile : public BaseFileFind Q_OBJECT public: - explicit FindInCurrentFile(Find::SearchResultWindow *resultWindow); + explicit FindInCurrentFile(); QString id() const; QString displayName() const; diff --git a/src/plugins/texteditor/findinfiles.cpp b/src/plugins/texteditor/findinfiles.cpp index bb258ee4e7b..42b894915b4 100644 --- a/src/plugins/texteditor/findinfiles.cpp +++ b/src/plugins/texteditor/findinfiles.cpp @@ -45,9 +45,8 @@ using namespace Find; using namespace TextEditor; -FindInFiles::FindInFiles(SearchResultWindow *resultWindow) - : BaseFileFind(resultWindow), - m_configWidget(0), +FindInFiles::FindInFiles() + : m_configWidget(0), m_directory(0) { } diff --git a/src/plugins/texteditor/findinfiles.h b/src/plugins/texteditor/findinfiles.h index 7cf15e5cedb..9a0e3060ee7 100644 --- a/src/plugins/texteditor/findinfiles.h +++ b/src/plugins/texteditor/findinfiles.h @@ -36,7 +36,6 @@ #include "basefilefind.h" #include -#include #include #include @@ -51,7 +50,7 @@ class TEXTEDITOR_EXPORT FindInFiles : public BaseFileFind Q_OBJECT public: - explicit FindInFiles(Find::SearchResultWindow *resultWindow); + explicit FindInFiles(); QString id() const; QString displayName() const; diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index 8f4b1dc9351..9b08c141823 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -182,8 +182,8 @@ void TextEditorPlugin::extensionsInitialized() updateSearchResultsFont(m_settings->fontSettings()); - addAutoReleasedObject(new FindInFiles(Find::SearchResultWindow::instance())); - addAutoReleasedObject(new FindInCurrentFile(Find::SearchResultWindow::instance())); + addAutoReleasedObject(new FindInFiles); + addAutoReleasedObject(new FindInCurrentFile); Core::VariableManager *vm = Core::VariableManager::instance(); vm->registerVariable(QLatin1String(kCurrentDocumentSelection),