From 6f3d4e224e07abe3274e91959186dae779d0eefd Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 22 Jun 2021 11:47:56 +0200 Subject: [PATCH] add context menu item to copy transaction hex --- .../sparrowwallet/sparrow/AppServices.java | 2 +- .../sparrow/control/TransactionHexArea.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 53985ff0..f47d0450 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -585,7 +585,7 @@ public class AppServices { String[] lines = content.split("\r\n|\r|\n"); if(lines.length > 3) { - alert.getDialogPane().setPrefHeight(180 + lines.length * 20); + alert.getDialogPane().setPrefHeight(200 + lines.length * 20); } moveToActiveWindowScreen(alert); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionHexArea.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionHexArea.java index b8d84403..45ce3885 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionHexArea.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionHexArea.java @@ -4,7 +4,11 @@ import com.sparrowwallet.drongo.Utils; import com.sparrowwallet.drongo.protocol.*; import javafx.application.Platform; import javafx.geometry.Point2D; +import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; +import javafx.scene.input.Clipboard; +import javafx.scene.input.ClipboardContent; import javafx.stage.Popup; import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.event.MouseOverTextEvent; @@ -33,7 +37,8 @@ public class TransactionHexArea extends CodeArea { ByteArrayOutputStream baos = new ByteArrayOutputStream(); transaction.bitcoinSerializeToStream(baos); - String hex = Utils.bytesToHex(baos.toByteArray()); + String fullHex = Utils.bytesToHex(baos.toByteArray()); + String hex = fullHex; if(hex.length() > TRUNCATE_AT) { hex = hex.substring(0, TRUNCATE_AT); hex += "[truncated]"; @@ -42,6 +47,7 @@ public class TransactionHexArea extends CodeArea { clear(); appendText(hex); previousSegmentList = new ArrayList<>(); + setContextMenu(new TransactionHexContextMenu(fullHex)); } catch (IOException e) { throw new IllegalStateException("Can't happen"); } @@ -266,4 +272,18 @@ public class TransactionHexArea extends CodeArea { return Objects.hash(start, length, style); } } + + private static class TransactionHexContextMenu extends ContextMenu { + public TransactionHexContextMenu(String hex) { + MenuItem copy = new MenuItem("Copy All"); + copy.setOnAction(AE -> { + hide(); + ClipboardContent content = new ClipboardContent(); + content.putString(hex); + Clipboard.getSystemClipboard().setContent(content); + }); + + getItems().add(copy); + } + } }