mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
add context menu item to copy transaction hex
This commit is contained in:
parent
4d6609990c
commit
6f3d4e224e
2 changed files with 22 additions and 2 deletions
|
@ -585,7 +585,7 @@ public class AppServices {
|
||||||
|
|
||||||
String[] lines = content.split("\r\n|\r|\n");
|
String[] lines = content.split("\r\n|\r|\n");
|
||||||
if(lines.length > 3) {
|
if(lines.length > 3) {
|
||||||
alert.getDialogPane().setPrefHeight(180 + lines.length * 20);
|
alert.getDialogPane().setPrefHeight(200 + lines.length * 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
moveToActiveWindowScreen(alert);
|
moveToActiveWindowScreen(alert);
|
||||||
|
|
|
@ -4,7 +4,11 @@ import com.sparrowwallet.drongo.Utils;
|
||||||
import com.sparrowwallet.drongo.protocol.*;
|
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.Label;
|
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 javafx.stage.Popup;
|
||||||
import org.fxmisc.richtext.CodeArea;
|
import org.fxmisc.richtext.CodeArea;
|
||||||
import org.fxmisc.richtext.event.MouseOverTextEvent;
|
import org.fxmisc.richtext.event.MouseOverTextEvent;
|
||||||
|
@ -33,7 +37,8 @@ public class TransactionHexArea extends CodeArea {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
transaction.bitcoinSerializeToStream(baos);
|
transaction.bitcoinSerializeToStream(baos);
|
||||||
|
|
||||||
String hex = Utils.bytesToHex(baos.toByteArray());
|
String fullHex = Utils.bytesToHex(baos.toByteArray());
|
||||||
|
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);
|
||||||
hex += "[truncated]";
|
hex += "[truncated]";
|
||||||
|
@ -42,6 +47,7 @@ public class TransactionHexArea extends CodeArea {
|
||||||
clear();
|
clear();
|
||||||
appendText(hex);
|
appendText(hex);
|
||||||
previousSegmentList = new ArrayList<>();
|
previousSegmentList = new ArrayList<>();
|
||||||
|
setContextMenu(new TransactionHexContextMenu(fullHex));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException("Can't happen");
|
throw new IllegalStateException("Can't happen");
|
||||||
}
|
}
|
||||||
|
@ -266,4 +272,18 @@ public class TransactionHexArea extends CodeArea {
|
||||||
return Objects.hash(start, length, style);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue