Prevent expired entries search if no results returned

* Fixes #8626
* Also remove old feature to set the title of a new entry to the current search text. This only made sense before advanced searching was made available.
This commit is contained in:
Jonathan White 2022-10-24 23:19:31 -04:00
parent c5eaee80cb
commit ceb2cd2b67

View File

@ -391,10 +391,6 @@ void DatabaseWidget::createEntry()
m_newEntry.reset(new Entry()); m_newEntry.reset(new Entry());
if (isSearchActive()) {
m_newEntry->setTitle(getCurrentSearch());
endSearch();
}
m_newEntry->setUuid(QUuid::createUuid()); m_newEntry->setUuid(QUuid::createUuid());
m_newEntry->setUsername(m_db->metadata()->defaultUserName()); m_newEntry->setUsername(m_db->metadata()->defaultUserName());
m_newParent = m_groupView->currentGroup(); m_newParent = m_groupView->currentGroup();
@ -1414,25 +1410,33 @@ void DatabaseWidget::search(const QString& searchtext)
return; return;
} }
emit searchModeAboutToActivate(); auto searchGroup = m_db->rootGroup();
if (m_searchLimitGroup && m_nextSearchLabelText.isEmpty()) {
searchGroup = currentGroup();
}
Group* searchGroup = m_searchLimitGroup ? currentGroup() : m_db->rootGroup(); auto results = m_entrySearcher->search(searchtext, searchGroup);
QList<Entry*> searchResult = m_entrySearcher->search(searchtext, searchGroup);
m_entryView->displaySearch(searchResult);
m_lastSearchText = searchtext;
// Display a label detailing our search results // Display a label detailing our search results
if (!m_nextSearchLabelText.isEmpty()) { if (!m_nextSearchLabelText.isEmpty()) {
// Custom searches don't display if there are no results
if (results.isEmpty()) {
endSearch();
return;
}
m_searchingLabel->setText(m_nextSearchLabelText); m_searchingLabel->setText(m_nextSearchLabelText);
m_nextSearchLabelText.clear(); m_nextSearchLabelText.clear();
} else if (!searchResult.isEmpty()) { } else if (!results.isEmpty()) {
m_searchingLabel->setText(tr("Search Results (%1)").arg(searchResult.size())); m_searchingLabel->setText(tr("Search Results (%1)").arg(results.size()));
} else { } else {
m_searchingLabel->setText(tr("No Results")); m_searchingLabel->setText(tr("No Results"));
} }
emit searchModeAboutToActivate();
m_entryView->displaySearch(results);
m_lastSearchText = searchtext;
m_searchingLabel->setVisible(true); m_searchingLabel->setVisible(true);
#ifdef WITH_XC_KEESHARE #ifdef WITH_XC_KEESHARE
m_shareLabel->setVisible(false); m_shareLabel->setVisible(false);