Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to copy popup text to clipboard. #6054

Merged
merged 1 commit into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ shared.sendFundsDetailsWithFee=Sending: {0}\nFrom address: {1}\nTo receiving add
# suppress inspection "TrailingSpacesInProperty"
shared.sendFundsDetailsDust=Bisq detected that this transaction would create a change output which is below the minimum dust threshold (and therefore not allowed by Bitcoin consensus rules). Instead, this dust ({0} satoshi{1}) will be added to the mining fee.\n\n\n
shared.copyToClipboard=Copy to clipboard
shared.copiedToClipboard=Copied to clipboard!
shared.language=Language
shared.country=Country
shared.applyAndShutDown=Apply and shut down
Expand Down
32 changes: 30 additions & 2 deletions desktop/src/main/java/bisq/desktop/main/overlays/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.desktop.main.MainView;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Layout;
import bisq.desktop.util.Transitions;

import bisq.core.locale.GlobalSettings;
Expand Down Expand Up @@ -53,12 +54,14 @@
import javafx.stage.StageStyle;
import javafx.stage.Window;

import javafx.scene.Node;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
Expand Down Expand Up @@ -97,6 +100,8 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import static javafx.scene.input.MouseEvent.MOUSE_CLICKED;

@Slf4j
public abstract class Overlay<T extends Overlay<T>> {

Expand Down Expand Up @@ -169,7 +174,7 @@ protected enum Type {

protected boolean useAnimation = true;

protected Label headlineIcon, headLineLabel, messageLabel;
protected Label headlineIcon, copyIcon, headLineLabel, messageLabel;
protected String headLine, message, closeButtonText, actionButtonText,
secondaryActionButtonText, dontShowAgainId, dontShowAgainText,
truncatedMessage;
Expand Down Expand Up @@ -751,6 +756,21 @@ protected void applyStyles() {


if (headLineLabel != null) {
copyIcon.getStyleClass().add("popup-icon-information");
copyIcon.setManaged(true);
copyIcon.setVisible(true);
FormBuilder.getIconForLabel(AwesomeIcon.COPY, copyIcon, "1.5em");
copyIcon.addEventHandler(MOUSE_CLICKED, mouseEvent -> {
if (message != null) {
String forClipboard = headLineLabel.getText() + System.lineSeparator() + message
+ System.lineSeparator() + (messageHyperlinks == null ? "" : messageHyperlinks.toString());
Utilities.copyToClipboard(forClipboard);
Tooltip tp = new Tooltip(Res.get("shared.copiedToClipboard"));
Node node = (Node) mouseEvent.getSource();
UserThread.runAfter(() -> tp.hide(), 1);
tp.show(node, mouseEvent.getScreenX() + Layout.PADDING, mouseEvent.getScreenY() + Layout.PADDING);
}
});

switch (type) {
case Information:
Expand Down Expand Up @@ -795,6 +815,14 @@ protected void addHeadLine() {

HBox hBox = new HBox();
hBox.setSpacing(7);
copyIcon = new Label();
copyIcon.setManaged(false);
copyIcon.setVisible(false);
copyIcon.setPadding(new Insets(3));
copyIcon.setTooltip(new Tooltip(Res.get("shared.copyToClipboard")));
final Pane spacer = new Pane();
HBox.setHgrow(spacer, Priority.ALWAYS);
spacer.setMinSize(Layout.PADDING, 1);
headLineLabel = new AutoTooltipLabel(headLine);
headlineIcon = new Label();
headlineIcon.setManaged(false);
Expand All @@ -805,7 +833,7 @@ protected void addHeadLine() {
if (headlineStyle != null)
headLineLabel.setStyle(headlineStyle);

hBox.getChildren().addAll(headlineIcon, headLineLabel);
hBox.getChildren().addAll(headlineIcon, headLineLabel, spacer, copyIcon);

GridPane.setHalignment(hBox, HPos.LEFT);
GridPane.setRowIndex(hBox, rowIndex);
Expand Down