Skip to content

Commit 69915b8

Browse files
committed
qt: Disable requests context menu actions when appropriate
The recent requests table will allow you to copy data points even if they do not exist. This PR implements checks to disable the 'copy label', 'copy message', and 'copy amount' context menu action if the respective fields are empty.
1 parent f5cdc29 commit 69915b8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/qt/receivecoinsdialog.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid
4343

4444
// context menu actions
4545
QAction *copyURIAction = new QAction(tr("Copy URI"), this);
46-
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
47-
QAction *copyMessageAction = new QAction(tr("Copy message"), this);
48-
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
46+
copyLabelAction = new QAction(tr("Copy label"), this);
47+
copyMessageAction = new QAction(tr("Copy message"), this);
48+
copyAmountAction = new QAction(tr("Copy amount"), this);
4949

5050
// context menu
5151
contextMenu = new QMenu(this);
@@ -267,9 +267,18 @@ void ReceiveCoinsDialog::copyColumnToClipboard(int column)
267267
// context menu
268268
void ReceiveCoinsDialog::showMenu(const QPoint &point)
269269
{
270-
if (!selectedRow().isValid()) {
270+
QModelIndex sel = selectedRow();
271+
if (!sel.isValid()) {
271272
return;
272273
}
274+
275+
// disable context menu actions when appropriate
276+
const RecentRequestsTableModel * const submodel = model->getRecentRequestsTableModel();
277+
const RecentRequestEntry *req = &submodel->entry(sel.row());
278+
copyLabelAction->setEnabled(!req->recipient.label.isEmpty());
279+
copyMessageAction->setEnabled(!req->recipient.message.isEmpty());
280+
copyAmountAction->setEnabled(!(req->recipient.amount == 0));
281+
273282
contextMenu->exec(QCursor::pos());
274283
}
275284

src/qt/receivecoinsdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public Q_SLOTS:
5454
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer;
5555
WalletModel *model;
5656
QMenu *contextMenu;
57+
QAction *copyLabelAction;
58+
QAction *copyMessageAction;
59+
QAction *copyAmountAction;
5760
const PlatformStyle *platformStyle;
5861

5962
QModelIndex selectedRow();

0 commit comments

Comments
 (0)