From d6ffee5e99905a3bf237fc554b5e9271097cc849 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Thu, 15 Nov 2018 17:37:16 -0500 Subject: [PATCH] Implement search auto-clear and goto group * Search clears if the search box does not have focus for 5 minutes (fixes #2178) * Goto group from search results after double clicking the group name (fixes #2043) --- src/gui/DatabaseWidget.cpp | 8 ++++++++ src/gui/SearchWidget.cpp | 10 +++++++++- src/gui/SearchWidget.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 701ba588c..5c8d7bc9d 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -893,6 +893,14 @@ void DatabaseWidget::entryActivationSignalReceived(Entry* entry, EntryModel::Mod setupTotp(); } break; + case EntryModel::ParentGroup: + // Call this first to clear out of search mode, otherwise + // the desired entry is not properly selected + endSearch(); + emit clearSearch(); + m_groupView->setCurrentGroup(entry->group()); + m_entryView->setCurrentEntry(entry); + break; // TODO: switch to 'Notes' tab in details view/pane // case EntryModel::Notes: // break; diff --git a/src/gui/SearchWidget.cpp b/src/gui/SearchWidget.cpp index ba8b616d8..6441502b0 100644 --- a/src/gui/SearchWidget.cpp +++ b/src/gui/SearchWidget.cpp @@ -30,15 +30,18 @@ SearchWidget::SearchWidget(QWidget* parent) : QWidget(parent) , m_ui(new Ui::SearchWidget()) + , m_searchTimer(new QTimer(this)) + , m_clearSearchTimer(new QTimer(this)) { m_ui->setupUi(this); - m_searchTimer = new QTimer(this); m_searchTimer->setSingleShot(true); + m_clearSearchTimer->setSingleShot(true); connect(m_ui->searchEdit, SIGNAL(textChanged(QString)), SLOT(startSearchTimer())); connect(m_ui->clearIcon, SIGNAL(triggered(bool)), m_ui->searchEdit, SLOT(clear())); connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(startSearch())); + connect(m_clearSearchTimer, SIGNAL(timeout()), m_ui->searchEdit, SLOT(clear())); connect(this, SIGNAL(escapePressed()), m_ui->searchEdit, SLOT(clear())); new QShortcut(QKeySequence::Find, this, SLOT(searchFocus()), nullptr, Qt::ApplicationShortcut); @@ -101,6 +104,11 @@ bool SearchWidget::eventFilter(QObject* obj, QEvent* event) return true; } } + } else if (event->type() == QEvent::FocusOut) { + // Auto-clear search after 5 minutes + m_clearSearchTimer->start(300000); + } else if (event->type() == QEvent::FocusIn) { + m_clearSearchTimer->stop(); } return QObject::eventFilter(obj, event); diff --git a/src/gui/SearchWidget.h b/src/gui/SearchWidget.h index 39e17bcf4..6f4387004 100644 --- a/src/gui/SearchWidget.h +++ b/src/gui/SearchWidget.h @@ -69,6 +69,7 @@ private slots: private: const QScopedPointer m_ui; QTimer* m_searchTimer; + QTimer* m_clearSearchTimer; QAction* m_actionCaseSensitive; QAction* m_actionLimitGroup; };