copy context menu changes on receive tab

This commit is contained in:
Craig Raw 2024-04-22 16:57:44 +02:00
parent 1887e1c7b0
commit f1cddc28e7
4 changed files with 39 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import javafx.beans.value.ChangeListener;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Tooltip; import javafx.scene.control.Tooltip;
import javafx.scene.input.Clipboard; import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent; import javafx.scene.input.ClipboardContent;
@ -52,6 +53,7 @@ public class CopyableTextField extends CustomTextField {
selectedTextProperty().removeListener(selectionListener); selectedTextProperty().removeListener(selectionListener);
} }
}); });
setContextMenu(new ContextMenu());
} }
private void setupCopyButtonField(ObjectProperty<Node> rightProperty) { private void setupCopyButtonField(ObjectProperty<Node> rightProperty) {

View file

@ -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());
});
}
}

View file

@ -27,7 +27,6 @@ import javafx.scene.control.*;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import org.controlsfx.glyphfont.Glyph; import org.controlsfx.glyphfont.Glyph;
import org.fxmisc.richtext.CodeArea;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -63,7 +62,7 @@ public class ReceiveController extends WalletFormController implements Initializ
private ScriptArea scriptPubKeyArea; private ScriptArea scriptPubKeyArea;
@FXML @FXML
private CodeArea outputDescriptor; private SelectableCodeArea outputDescriptor;
@FXML @FXML
private Button displayAddress; private Button displayAddress;

View file

@ -12,11 +12,11 @@
<?import tornadofx.control.Field?> <?import tornadofx.control.Field?>
<?import javafx.scene.image.ImageView?> <?import javafx.scene.image.ImageView?>
<?import org.fxmisc.flowless.VirtualizedScrollPane?> <?import org.fxmisc.flowless.VirtualizedScrollPane?>
<?import org.fxmisc.richtext.CodeArea?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?> <?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import org.controlsfx.glyphfont.Glyph?> <?import org.controlsfx.glyphfont.Glyph?>
<?import com.sparrowwallet.sparrow.control.CopyableTextField?> <?import com.sparrowwallet.sparrow.control.CopyableTextField?>
<?import com.sparrowwallet.sparrow.control.ScriptArea?> <?import com.sparrowwallet.sparrow.control.ScriptArea?>
<?import com.sparrowwallet.sparrow.control.SelectableCodeArea?>
<BorderPane stylesheets="@receive.css, @wallet.css, @../script.css, @../descriptor.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.ReceiveController"> <BorderPane stylesheets="@receive.css, @wallet.css, @../script.css, @../descriptor.css, @../general.css" styleClass="wallet-pane" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.wallet.ReceiveController">
<center> <center>
@ -72,7 +72,7 @@
<Field text="Descriptor:"> <Field text="Descriptor:">
<VirtualizedScrollPane> <VirtualizedScrollPane>
<content> <content>
<CodeArea fx:id="outputDescriptor" editable="false" wrapText="true" prefHeight="68" maxHeight="68" styleClass="uneditable-codearea" /> <SelectableCodeArea fx:id="outputDescriptor" editable="false" wrapText="true" prefHeight="68" maxHeight="68" styleClass="uneditable-codearea" />
</content> </content>
</VirtualizedScrollPane> </VirtualizedScrollPane>
</Field> </Field>