Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/autotype/AutoTypeSelectDialog.cpp')
-rw-r--r--src/autotype/AutoTypeSelectDialog.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/autotype/AutoTypeSelectDialog.cpp b/src/autotype/AutoTypeSelectDialog.cpp
index 1449f9e02..997858f0d 100644
--- a/src/autotype/AutoTypeSelectDialog.cpp
+++ b/src/autotype/AutoTypeSelectDialog.cpp
@@ -27,6 +27,8 @@
#include <QDialogButtonBox>
#include <QHeaderView>
#include <QLabel>
+#include <QLineEdit>
+#include <QSortFilterProxyModel>
#include <QVBoxLayout>
#include "autotype/AutoTypeSelectView.h"
@@ -38,6 +40,7 @@
AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
: QDialog(parent)
, m_view(new AutoTypeSelectView(this))
+ , m_filterLineEdit(new AutoTypeFilterLineEdit(this))
, m_matchActivatedEmitted(false)
, m_rejected(false)
{
@@ -72,13 +75,31 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
connect(m_view, SIGNAL(clicked(QModelIndex)), SLOT(emitMatchActivated(QModelIndex)));
connect(m_view->model(), SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(matchRemoved()));
connect(m_view, SIGNAL(rejected()), SLOT(reject()));
+ connect(m_view, SIGNAL(matchTextCopied()), SLOT(reject()));
// clang-format on
+ QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_view->model());
+ if (proxy) {
+ proxy->setFilterKeyColumn(-1);
+ proxy->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ }
+
layout->addWidget(m_view);
+ connect(m_filterLineEdit, SIGNAL(textChanged(QString)), SLOT(filterList(QString)));
+ connect(m_filterLineEdit, SIGNAL(returnPressed()), SLOT(activateCurrentIndex()));
+ connect(m_filterLineEdit, SIGNAL(keyUpPressed()), SLOT(moveSelectionUp()));
+ connect(m_filterLineEdit, SIGNAL(keyDownPressed()), SLOT(moveSelectionDown()));
+ connect(m_filterLineEdit, SIGNAL(escapeReleased()), SLOT(reject()));
+
+ m_filterLineEdit->setPlaceholderText(tr("Search..."));
+ layout->addWidget(m_filterLineEdit);
+
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel, Qt::Horizontal, this);
connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
layout->addWidget(buttonBox);
+
+ m_filterLineEdit->setFocus();
}
void AutoTypeSelectDialog::setMatchList(const QList<AutoTypeMatch>& matchList)
@@ -121,7 +142,43 @@ void AutoTypeSelectDialog::matchRemoved()
return;
}
- if (m_view->model()->rowCount() == 0) {
+ if (m_view->model()->rowCount() == 0 && m_filterLineEdit->text().isEmpty()) {
reject();
}
}
+
+void AutoTypeSelectDialog::filterList(QString filterString)
+{
+ QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(m_view->model());
+ if (proxy) {
+ proxy->setFilterWildcard(filterString);
+ if (!m_view->currentIndex().isValid()) {
+ m_view->setCurrentIndex(m_view->model()->index(0, 0));
+ }
+ }
+}
+
+void AutoTypeSelectDialog::moveSelectionUp()
+{
+ auto current = m_view->currentIndex();
+ auto previous = current.sibling(current.row() - 1, 0);
+
+ if (previous.isValid()) {
+ m_view->setCurrentIndex(previous);
+ }
+}
+
+void AutoTypeSelectDialog::moveSelectionDown()
+{
+ auto current = m_view->currentIndex();
+ auto next = current.sibling(current.row() + 1, 0);
+
+ if (next.isValid()) {
+ m_view->setCurrentIndex(next);
+ }
+}
+
+void AutoTypeSelectDialog::activateCurrentIndex()
+{
+ emitMatchActivated(m_view->currentIndex());
+}