From d87adfae827d9c82e07db529acc435b77e722640 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 4 Dec 2018 14:25:47 -0800 Subject: [PATCH] Reply to context menu --- src/mainwindow.cpp | 28 ++++++++++++++++++++++++++++ src/mainwindow.h | 2 +- src/sendtab.cpp | 16 ++++++++++------ src/settings.cpp | 12 ++++++++++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d76d53a..aa4f428 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -937,6 +937,34 @@ void MainWindow::setupTransactionsTab() { }); } + // If memo contains a reply to addess, add a "Reply to" menu item + if (!memo.isEmpty()) { + int lastPost = memo.trimmed().lastIndexOf(QRegExp("[\r\n]+")); + QString lastWord = memo.right(memo.length() - lastPost - 1); + qDebug() << lastWord; + if (Settings::getInstance()->isSaplingAddress(lastWord) || + Settings::getInstance()->isSproutAddress(lastWord)) { + menu.addAction(tr("Reply to ") + lastWord.left(25) + "...", [=]() { + // First, cancel any pending stuff in the send tab by pretending to click + // the cancel button + cancelButton(); + + // Then set up the fields in the send tab + ui->Address1->setText(lastWord); + ui->Address1->setCursorPosition(0); + ui->Amount1->setText("0.0001"); + + // And switch to the send tab. + ui->tabWidget->setCurrentIndex(1); + + qApp->processEvents(); + + // Click the memo button + this->memoButtonClicked(1, true); + }); + } + } + menu.exec(ui->transactionsTable->viewport()->mapToGlobal(pos)); }); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 6d4c03b..fe7eb3b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -82,7 +82,7 @@ private: void addNewZaddr(bool sapling); std::function addZAddrsToComboList(bool sapling); - void memoButtonClicked(int number); + void memoButtonClicked(int number, bool includeReplyTo = false); void setMemoEnabled(int number, bool enabled); QString doSendTxValidations(Tx tx); diff --git a/src/sendtab.cpp b/src/sendtab.cpp index d183395..e33a833 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -255,7 +255,7 @@ void MainWindow::setMemoEnabled(int number, bool enabled) { } } -void MainWindow::memoButtonClicked(int number) { +void MainWindow::memoButtonClicked(int number, bool includeReplyTo) { // Memos can only be used with zAddrs. So check that first auto addr = ui->sendToWidgets->findChild(QString("Address") + QString::number(number)); if (!AddressBook::addressFromAddressLabel(addr->text()).startsWith("z")) { @@ -293,8 +293,7 @@ void MainWindow::memoButtonClicked(int number) { }); - // Insert From Address button - QObject::connect(memoDialog.btnInsertFrom, &QPushButton::clicked, [=, &dialog] () { + auto fnAddReplyTo = [=, &dialog]() { QString replyTo = ui->inputsCombo->currentText(); if (!Settings::isZAddress(replyTo)) { replyTo = rpc->getDefaultSaplingAddress(); @@ -305,18 +304,23 @@ void MainWindow::memoButtonClicked(int number) { if (curText.endsWith(replyTo)) return; - memoDialog.memoTxt->setPlainText(memoDialog.memoTxt->toPlainText() + - "\n" + tr("Reply to") + ":\n" + replyTo); + memoDialog.memoTxt->setPlainText(curText + "\n" + tr("Reply to") + ":\n" + replyTo); // MacOS has a really annoying bug where the Plaintext doesn't refresh when the content is // updated. So we do this ugly hack - resize the window slightly to force it to refresh dialog.setGeometry(dialog.geometry().adjusted(0,0,0,1)); dialog.setGeometry(dialog.geometry().adjusted(0,0,0,-1)); - }); + }; + + // Insert From Address button + QObject::connect(memoDialog.btnInsertFrom, &QPushButton::clicked, fnAddReplyTo); memoDialog.memoTxt->setPlainText(currentMemo); memoDialog.memoTxt->setFocus(); + if (includeReplyTo) + fnAddReplyTo(); + if (dialog.exec() == QDialog::Accepted) { memoTxt->setText(memoDialog.memoTxt->toPlainText()); } diff --git a/src/settings.cpp b/src/settings.cpp index b9e443e..5d2e431 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -54,19 +54,31 @@ void Settings::setTestnet(bool isTestnet) { } bool Settings::isSaplingAddress(QString addr) { + if (!isValidAddress(addr)) + return false; + return ( isTestnet() && addr.startsWith("ztestsapling")) || (!isTestnet() && addr.startsWith("zs")); } bool Settings::isSproutAddress(QString addr) { + if (!isValidAddress(addr)) + return false; + return isZAddress(addr) && !isSaplingAddress(addr); } bool Settings::isZAddress(QString addr) { + if (!isValidAddress(addr)) + return false; + return addr.startsWith("z"); } bool Settings::isTAddress(QString addr) { + if (!isValidAddress(addr)) + return false; + return addr.startsWith("t"); }