forked from qt-creator/qt-creator
Move and cleanup search specific API to SearchResult class
Change-Id: I7e64701e8833ad38b9ac01d316bd00302602a390 Rubber-stamped-by: Daniel Teske Reviewed-on: http://codereview.qt.nokia.com/4179 Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
@@ -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<Usage> &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<Find::SearchResultItem>)),
|
||||
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
||||
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
|
||||
|
||||
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<Usage> &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)
|
||||
|
||||
@@ -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<CPlusPlus::CppModelManagerInterface> _modelManager;
|
||||
Find::SearchResultWindow *_resultWindow;
|
||||
Find::SearchResult *m_currentSearch;
|
||||
QFutureWatcher<CPlusPlus::Usage> m_watcher;
|
||||
|
||||
mutable QMutex m_depsLock;
|
||||
|
||||
@@ -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<Find::SearchResultItem> 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();
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ private:
|
||||
bool m_isRunning;
|
||||
bool m_enabled;
|
||||
QFutureWatcher<Find::SearchResultItem> m_watcher;
|
||||
Find::SearchResult *m_currentSearch;
|
||||
SearchSymbols::SymbolTypes m_symbolsToSearch;
|
||||
SearchSymbols m_search;
|
||||
SearchScope m_scope;
|
||||
|
||||
@@ -336,19 +336,19 @@ QSet<SearchResultTreeItem *> SearchResultTreeModel::addPath(const QStringList &p
|
||||
return pathNodes;
|
||||
}
|
||||
|
||||
void SearchResultTreeModel::addResultsToCurrentParent(const QList<SearchResultItem> &items, SearchResultWindow::AddMode mode)
|
||||
void SearchResultTreeModel::addResultsToCurrentParent(const QList<SearchResultItem> &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<QModelIndex> SearchResultTreeModel::addResults(const QList<SearchResultItem> &items, SearchResultWindow::AddMode mode)
|
||||
QList<QModelIndex> SearchResultTreeModel::addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode)
|
||||
{
|
||||
QSet<SearchResultTreeItem *> pathNodes;
|
||||
QList<SearchResultItem> sortedItems = items;
|
||||
|
||||
@@ -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<QModelIndex> addResults(const QList<SearchResultItem> &items, SearchResultWindow::AddMode mode);
|
||||
QList<QModelIndex> addResults(const QList<SearchResultItem> &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<SearchResultItem> &items, SearchResultWindow::AddMode mode);
|
||||
void addResultsToCurrentParent(const QList<SearchResultItem> &items, SearchResult::AddMode mode);
|
||||
QSet<SearchResultTreeItem *> addPath(const QStringList &path);
|
||||
QVariant data(const SearchResultTreeItem *row, int role) const;
|
||||
bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true);
|
||||
|
||||
@@ -70,7 +70,7 @@ void SearchResultTreeView::clear()
|
||||
m_model->clear();
|
||||
}
|
||||
|
||||
void SearchResultTreeView::addResults(const QList<Find::SearchResultItem> &items, Find::SearchResultWindow::AddMode mode)
|
||||
void SearchResultTreeView::addResults(const QList<Find::SearchResultItem> &items, Find::SearchResult::AddMode mode)
|
||||
{
|
||||
QList<QModelIndex> addedParents = m_model->addResults(items, mode);
|
||||
if (m_autoExpandResults && !addedParents.isEmpty()) {
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
void setTextEditorFont(const QFont &font);
|
||||
|
||||
SearchResultTreeModel *model() const;
|
||||
void addResults(const QList<Find::SearchResultItem> &items, SearchResultWindow::AddMode mode);
|
||||
void addResults(const QList<Find::SearchResultItem> &items, SearchResult::AddMode mode);
|
||||
|
||||
signals:
|
||||
void jumpToSearchResult(const SearchResultItem &item);
|
||||
|
||||
@@ -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<SearchResultItem>() << item, AddOrdered);
|
||||
addResults(QList<SearchResultItem>() << item, SearchResult::AddOrdered);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void SearchResultWindow::addResults(QList<SearchResultItem> &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<SearchResultItem> &items, SearchResult::AddMode mode)
|
||||
\internal
|
||||
*/
|
||||
void SearchResultWindow::addResults(QList<SearchResultItem> &items, AddMode mode)
|
||||
void SearchResultWindow::addResults(const QList<SearchResultItem> &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<SearchResultItem> &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<SearchResultItem> &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
|
||||
|
||||
|
||||
|
||||
@@ -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<SearchResultItem> &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<SearchResultItem> &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<SearchResultItem> &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
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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*)),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Find::SearchResultItem>)),
|
||||
m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch(Find::SearchResultWindow::SearchAndReplace);
|
||||
m_currentSearch->setTextToReplace(replacement);
|
||||
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
||||
SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));
|
||||
}
|
||||
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 QList<Fin
|
||||
if (!changedUnsavedEditors.isEmpty())
|
||||
QmlJS::ModelManagerInterface::instance()->updateSourceFiles(changedUnsavedEditors, false);
|
||||
|
||||
_resultWindow->hide();
|
||||
Find::SearchResultWindow::instance()->hide();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QFuture>
|
||||
#include <QtCore/QFutureWatcher>
|
||||
#include <utils/filesearch.h>
|
||||
@@ -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<Find::SearchResultItem> &items);
|
||||
|
||||
private:
|
||||
Find::SearchResultWindow *_resultWindow;
|
||||
Find::SearchResult *m_currentSearch;
|
||||
QFutureWatcher<Usage> m_watcher;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<FileSearchResultList>());
|
||||
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<Find::SearchResultItem>)),
|
||||
connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
|
||||
this, SLOT(doReplace(QString,QList<Find::SearchResultItem>)));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Utils::FileSearchResultList> m_watcher;
|
||||
bool m_isSearching;
|
||||
|
||||
@@ -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*)),
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <coreplugin/ifile.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <find/ifindfilter.h>
|
||||
#include <find/searchresultwindow.h>
|
||||
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtGui/QLabel>
|
||||
@@ -54,7 +53,7 @@ class FindInCurrentFile : public BaseFileFind
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FindInCurrentFile(Find::SearchResultWindow *resultWindow);
|
||||
explicit FindInCurrentFile();
|
||||
|
||||
QString id() const;
|
||||
QString displayName() const;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include "basefilefind.h"
|
||||
|
||||
#include <find/ifindfilter.h>
|
||||
#include <find/searchresultwindow.h>
|
||||
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtGui/QLabel>
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user