Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add copy context-menu in AutoType dialog #3038

Merged
merged 1 commit into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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