Commit 88d95250 authored by Eike Ziller's avatar Eike Ziller

Move repeated searches to top.

Task-number: QTCREATORBUG-6907

Change-Id: I25c04185beb3729e2d11cc88d17fcd1a3b51037c
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 009797c0
...@@ -311,7 +311,7 @@ void CppFindReferences::searchAgain() ...@@ -311,7 +311,7 @@ void CppFindReferences::searchAgain()
Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender()); Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender());
CppFindReferencesParameters parameters = search->userData().value<CppFindReferencesParameters>(); CppFindReferencesParameters parameters = search->userData().value<CppFindReferencesParameters>();
Snapshot snapshot = CppModelManagerInterface::instance()->snapshot(); Snapshot snapshot = CppModelManagerInterface::instance()->snapshot();
search->reset(); search->restart();
if (!findSymbol(&parameters, snapshot)) { if (!findSymbol(&parameters, snapshot)) {
search->finishSearch(); search->finishSearch();
return; return;
......
...@@ -276,7 +276,7 @@ void SymbolsFindFilter::searchAgain() ...@@ -276,7 +276,7 @@ void SymbolsFindFilter::searchAgain()
{ {
Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender()); Find::SearchResult *search = qobject_cast<Find::SearchResult *>(sender());
QTC_ASSERT(search, return); QTC_ASSERT(search, return);
search->reset(); search->restart();
startSearch(search); startSearch(search);
} }
......
...@@ -457,7 +457,7 @@ void SearchResultWidget::goToPrevious() ...@@ -457,7 +457,7 @@ void SearchResultWidget::goToPrevious()
} }
} }
void SearchResultWidget::reset() void SearchResultWidget::restart()
{ {
m_replaceTextEdit->setEnabled(false); m_replaceTextEdit->setEnabled(false);
m_replaceButton->setEnabled(false); m_replaceButton->setEnabled(false);
...@@ -466,6 +466,7 @@ void SearchResultWidget::reset() ...@@ -466,6 +466,7 @@ void SearchResultWidget::reset()
m_cancelButton->setVisible(true); m_cancelButton->setVisible(true);
m_searchAgainButton->setVisible(false); m_searchAgainButton->setVisible(false);
updateMatchesFoundLabel(); updateMatchesFoundLabel();
emit restarted();
} }
void SearchResultWidget::setSearchAgainSupported(bool supported) void SearchResultWidget::setSearchAgainSupported(bool supported)
......
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
void goToNext(); void goToNext();
void goToPrevious(); void goToPrevious();
void reset(); void restart();
void setSearchAgainSupported(bool supported); void setSearchAgainSupported(bool supported);
void setSearchAgainEnabled(bool enabled); void setSearchAgainEnabled(bool enabled);
...@@ -96,6 +96,7 @@ signals: ...@@ -96,6 +96,7 @@ signals:
void replaceButtonClicked(const QString &replaceText, const QList<Find::SearchResultItem> &checkedItems); void replaceButtonClicked(const QString &replaceText, const QList<Find::SearchResultItem> &checkedItems);
void searchAgainRequested(); void searchAgainRequested();
void cancelled(); void cancelled();
void restarted();
void visibilityChanged(bool visible); void visibilityChanged(bool visible);
void navigateStateChanged(); void navigateStateChanged();
......
...@@ -101,6 +101,7 @@ namespace Internal { ...@@ -101,6 +101,7 @@ namespace Internal {
public slots: public slots:
void setCurrentIndex(int index); void setCurrentIndex(int index);
void moveWidgetToTop();
}; };
SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window) SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window)
...@@ -135,6 +136,40 @@ namespace Internal { ...@@ -135,6 +136,40 @@ namespace Internal {
} }
q->navigateStateChanged(); q->navigateStateChanged();
} }
void SearchResultWindowPrivate::moveWidgetToTop()
{
SearchResultWidget *widget = qobject_cast<SearchResultWidget *>(sender());
QTC_ASSERT(widget, return);
int index = m_searchResultWidgets.indexOf(widget);
if (index == 0)
return; // nothing to do
int internalIndex = index + 1/*account for "new search" entry*/;
QString searchEntry = m_recentSearchesBox->itemText(internalIndex);
m_searchResultWidgets.removeAt(index);
m_widget->removeWidget(widget);
m_recentSearchesBox->removeItem(internalIndex);
SearchResult *result = m_searchResults.takeAt(index);
m_searchResultWidgets.prepend(widget);
m_widget->insertWidget(1, widget);
m_recentSearchesBox->insertItem(1, searchEntry);
m_searchResults.prepend(result);
// adapt the current index
if (index == visibleSearchIndex()) {
// was visible, so we switch
// this is the default case
m_currentIndex = 1;
m_widget->setCurrentIndex(1);
m_recentSearchesBox->setCurrentIndex(1);
} else if (visibleSearchIndex() < index) {
// academical case where the widget moved before the current widget
// only our internal book keeping needed
++m_currentIndex;
}
}
} }
using namespace Find::Internal; using namespace Find::Internal;
...@@ -344,6 +379,7 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label, ...@@ -344,6 +379,7 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
d->m_searchResultWidgets.prepend(widget); d->m_searchResultWidgets.prepend(widget);
d->m_widget->insertWidget(1, widget); d->m_widget->insertWidget(1, widget);
connect(widget, SIGNAL(navigateStateChanged()), this, SLOT(navigateStateChanged())); connect(widget, SIGNAL(navigateStateChanged()), this, SLOT(navigateStateChanged()));
connect(widget, SIGNAL(restarted()), d, SLOT(moveWidgetToTop()));
widget->setTextEditorFont(d->m_font); widget->setTextEditorFont(d->m_font);
widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly); widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly);
widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked()); widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked());
...@@ -651,9 +687,9 @@ void SearchResult::setTextToReplace(const QString &textToReplace) ...@@ -651,9 +687,9 @@ void SearchResult::setTextToReplace(const QString &textToReplace)
/*! /*!
* \brief Removes all search results. * \brief Removes all search results.
*/ */
void SearchResult::reset() void SearchResult::restart()
{ {
m_widget->reset(); m_widget->restart();
} }
void SearchResult::setSearchAgainEnabled(bool enabled) void SearchResult::setSearchAgainEnabled(bool enabled)
......
...@@ -107,7 +107,7 @@ public slots: ...@@ -107,7 +107,7 @@ public slots:
void addResults(const QList<SearchResultItem> &items, AddMode mode); void addResults(const QList<SearchResultItem> &items, AddMode mode);
void finishSearch(); void finishSearch();
void setTextToReplace(const QString &textToReplace); void setTextToReplace(const QString &textToReplace);
void reset(); void restart();
void setSearchAgainEnabled(bool enabled); void setSearchAgainEnabled(bool enabled);
signals: signals:
......
...@@ -319,7 +319,7 @@ void BaseFileFind::hideHighlightAll(bool visible) ...@@ -319,7 +319,7 @@ void BaseFileFind::hideHighlightAll(bool visible)
void BaseFileFind::searchAgain() void BaseFileFind::searchAgain()
{ {
SearchResult *search = qobject_cast<SearchResult *>(sender()); SearchResult *search = qobject_cast<SearchResult *>(sender());
search->reset(); search->restart();
runSearch(search); runSearch(search);
} }
......
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