diff --git a/src/main/java/com/sparrowwallet/sparrow/control/CopyableTextField.java b/src/main/java/com/sparrowwallet/sparrow/control/CopyableTextField.java index f7217a5e..e265d634 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/CopyableTextField.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/CopyableTextField.java @@ -10,6 +10,7 @@ import javafx.beans.value.ChangeListener; import javafx.event.EventHandler; import javafx.scene.Cursor; import javafx.scene.Node; +import javafx.scene.control.ContextMenu; import javafx.scene.control.Tooltip; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; @@ -52,6 +53,7 @@ public class CopyableTextField extends CustomTextField { selectedTextProperty().removeListener(selectionListener); } }); + setContextMenu(new ContextMenu()); } private void setupCopyButtonField(ObjectProperty rightProperty) { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/SelectableCodeArea.java b/src/main/java/com/sparrowwallet/sparrow/control/SelectableCodeArea.java new file mode 100644 index 00000000..f339aa9f --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/control/SelectableCodeArea.java @@ -0,0 +1,34 @@ +package com.sparrowwallet.sparrow.control; + +import javafx.scene.control.ContextMenu; +import javafx.scene.control.MenuItem; +import javafx.scene.input.Clipboard; +import javafx.scene.input.ClipboardContent; +import org.fxmisc.richtext.CodeArea; + +public class SelectableCodeArea extends CodeArea { + public SelectableCodeArea() { + super(); + + ContextMenu contextMenu = new ContextMenu(); + MenuItem copy = new MenuItem("Copy"); + copy.setDisable(true); + copy.setOnAction(event -> { + ClipboardContent content = new ClipboardContent(); + content.putString(getSelectedText()); + Clipboard.getSystemClipboard().setContent(content); + }); + MenuItem copyAll = new MenuItem("Copy All"); + copyAll.setOnAction(event -> { + ClipboardContent content = new ClipboardContent(); + content.putString(getText()); + Clipboard.getSystemClipboard().setContent(content); + }); + contextMenu.getItems().addAll(copy, copyAll); + setContextMenu(contextMenu); + + selectedTextProperty().addListener((observable, oldValue, newValue) -> { + copy.setDisable(newValue.isEmpty()); + }); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java index 88d890bf..5cf9e38d 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/ReceiveController.java @@ -27,7 +27,6 @@ import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import org.controlsfx.glyphfont.Glyph; -import org.fxmisc.richtext.CodeArea; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +62,7 @@ public class ReceiveController extends WalletFormController implements Initializ private ScriptArea scriptPubKeyArea; @FXML - private CodeArea outputDescriptor; + private SelectableCodeArea outputDescriptor; @FXML private Button displayAddress; diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/receive.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/receive.fxml index 3930ecad..ea36b98a 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/receive.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/receive.fxml @@ -12,11 +12,11 @@ - +
@@ -72,7 +72,7 @@ - +