mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Enable copy & paste from AutoType selection dialog
This change adds a right-click context menu to the AutoType dialog, which allows the user to copy either the username or password. The dialog then automatically closes.
This commit is contained in:
parent
bb8377ae6a
commit
7ceca8ff3c
@ -75,6 +75,7 @@ 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());
|
||||
|
@ -18,8 +18,11 @@
|
||||
|
||||
#include "AutoTypeMatchView.h"
|
||||
|
||||
#include "core/Entry.h"
|
||||
#include "gui/Clipboard.h"
|
||||
#include "gui/SortFilterHideProxyModel.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QHeaderView>
|
||||
#include <QKeyEvent>
|
||||
|
||||
@ -42,13 +45,35 @@ AutoTypeMatchView::AutoTypeMatchView(QWidget* parent)
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
header()->setDefaultSectionSize(150);
|
||||
|
||||
setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
auto* copyUserNameAction = new QAction(tr("Copy &username"), this);
|
||||
auto* copyPasswordAction = new QAction(tr("Copy &password"), this);
|
||||
addAction(copyUserNameAction);
|
||||
addAction(copyPasswordAction);
|
||||
|
||||
connect(copyUserNameAction, SIGNAL(triggered()), this, SLOT(userNameCopied()));
|
||||
connect(copyPasswordAction, SIGNAL(triggered()), this, SLOT(passwordCopied()));
|
||||
|
||||
connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitMatchActivated(QModelIndex)));
|
||||
// clang-format off
|
||||
connect(
|
||||
selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(matchSelectionChanged()));
|
||||
connect(selectionModel(),
|
||||
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
||||
SIGNAL(matchSelectionChanged()));
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void AutoTypeMatchView::userNameCopied()
|
||||
{
|
||||
clipboard()->setText(currentMatch().entry->username());
|
||||
emit matchTextCopied();
|
||||
}
|
||||
|
||||
void AutoTypeMatchView::passwordCopied()
|
||||
{
|
||||
clipboard()->setText(currentMatch().entry->password());
|
||||
emit matchTextCopied();
|
||||
}
|
||||
|
||||
void AutoTypeMatchView::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if ((event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && currentIndex().isValid()) {
|
||||
|
@ -42,12 +42,15 @@ public:
|
||||
signals:
|
||||
void matchActivated(AutoTypeMatch match);
|
||||
void matchSelectionChanged();
|
||||
void matchTextCopied();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void emitMatchActivated(const QModelIndex& index);
|
||||
void userNameCopied();
|
||||
void passwordCopied();
|
||||
|
||||
private:
|
||||
AutoTypeMatchModel* const m_model;
|
||||
|
Loading…
Reference in New Issue
Block a user