Core: Try not to evict still-running searches

... when the maximum number of searches has been reached.

Task-number: QTCREATORBUG-28976
Change-Id: I12bad860ce61f71aad9ba2fec93333a5d98bc61d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2023-04-19 16:56:58 +02:00
parent ca3d889831
commit daf1b29b2d
2 changed files with 19 additions and 4 deletions

View File

@@ -36,6 +36,7 @@ public:
void addResults(const QList<SearchResultItem> &items, SearchResult::AddMode mode);
int count() const;
bool isSearching() const { return m_searching; }
void setSupportsReplace(bool replaceSupported, const QString &group);
bool supportsReplace() const;

View File

@@ -90,6 +90,7 @@ namespace Internal {
void popupRequested(SearchResultWidget *widget, bool focus);
void handleExpandCollapseToolButton(bool checked);
void updateFilterButton();
int indexOfSearchToEvict() const;
QList<QWidget *> toolBarWidgets();
SearchResultWindow *q;
@@ -473,11 +474,14 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label,
// temporarily set the index to the last but one existing
d->m_currentIndex = d->m_recentSearchesBox->count() - 2;
}
d->m_searchResultWidgets.last()->notifyVisibilityChanged(false);
const int toRemoveIndex = d->indexOfSearchToEvict();
SearchResultWidget * const widgetToRemove
= d->m_searchResultWidgets.takeAt(toRemoveIndex);
widgetToRemove->notifyVisibilityChanged(false);
// widget first, because that might send interesting signals to SearchResult
delete d->m_searchResultWidgets.takeLast();
delete d->m_searchResults.takeLast();
d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count() - 1);
delete widgetToRemove;
delete d->m_searchResults.takeAt(toRemoveIndex);
d->m_recentSearchesBox->removeItem(toRemoveIndex + 1);
}
d->m_recentSearchesBox->insertItem(1, Tr::tr("%1 %2").arg(label, searchTerm));
}
@@ -616,6 +620,16 @@ void SearchResultWindowPrivate::updateFilterButton()
&& m_searchResultWidgets.at(visibleSearchIndex())->hasFilter());
}
int SearchResultWindowPrivate::indexOfSearchToEvict() const
{
const int lastIndex = m_searchResultWidgets.size() - 1;
for (int i = lastIndex; i >= 0; --i) {
if (!m_searchResultWidgets.at(i)->isSearching())
return i;
}
return lastIndex;
}
QList<QWidget *> SearchResultWindowPrivate::toolBarWidgets()
{
if (!m_historyLabel)