make select all, copy on transaction hex area copy untruncated transaction hex

This commit is contained in:
Craig Raw 2021-08-24 10:52:56 +02:00
parent 57b3214c54
commit b22e891b7d

View file

@ -5,6 +5,7 @@ import com.sparrowwallet.drongo.protocol.*;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.IndexRange;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javafx.scene.input.Clipboard; import javafx.scene.input.Clipboard;
@ -25,6 +26,7 @@ public class TransactionHexArea extends CodeArea {
private static final int TRUNCATE_AT = 30000; private static final int TRUNCATE_AT = 30000;
private static final int SEGMENTS_INTERVAL = 250; private static final int SEGMENTS_INTERVAL = 250;
private String fullHex;
private List<TransactionSegment> previousSegmentList = new ArrayList<>(); private List<TransactionSegment> previousSegmentList = new ArrayList<>();
public TransactionHexArea() { public TransactionHexArea() {
@ -37,7 +39,7 @@ public class TransactionHexArea extends CodeArea {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
transaction.bitcoinSerializeToStream(baos); transaction.bitcoinSerializeToStream(baos);
String fullHex = Utils.bytesToHex(baos.toByteArray()); fullHex = Utils.bytesToHex(baos.toByteArray());
String hex = fullHex; String hex = fullHex;
if(hex.length() > TRUNCATE_AT) { if(hex.length() > TRUNCATE_AT) {
hex = hex.substring(0, TRUNCATE_AT); hex = hex.substring(0, TRUNCATE_AT);
@ -242,6 +244,18 @@ public class TransactionHexArea extends CodeArea {
}; };
} }
@Override
public void copy() {
IndexRange selection = getSelection();
if(fullHex != null && selection.getLength() == getLength()) {
ClipboardContent content = new ClipboardContent();
content.putString(fullHex);
Clipboard.getSystemClipboard().setContent(content);
} else {
super.copy();
}
}
private static class TransactionSegment { private static class TransactionSegment {
public TransactionSegment(int start, int length, Integer index, Integer witnessIndex, String style) { public TransactionSegment(int start, int length, Integer index, Integer witnessIndex, String style) {
this.start = start; this.start = start;