Skip to content

Commit

Permalink
Enable copy & paste from AutoType selection dialog
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justacid authored and droidmonkey committed Jun 19, 2019
1 parent bb8377a commit 7ceca8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/autotype/AutoTypeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
29 changes: 27 additions & 2 deletions src/gui/entry/AutoTypeMatchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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()) {
Expand Down
3 changes: 3 additions & 0 deletions src/gui/entry/AutoTypeMatchView.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class AutoTypeMatchView : public QTreeView
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;
Expand Down

0 comments on commit 7ceca8f

Please sign in to comment.