From 96e1ddff7993df16228d359f3997038a03f95cfa Mon Sep 17 00:00:00 2001 From: Glavo Date: Thu, 27 Feb 2025 23:58:20 +0800 Subject: [PATCH] =?UTF-8?q?Close=20#3664:=20=E6=94=AF=E6=8C=81=E5=8F=8C?= =?UTF-8?q?=E5=87=BB=E5=A4=8D=E5=88=B6=E4=B8=96=E7=95=8C=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=20(#3665)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Close #3664: 支持双击复制世界信息 * update * update --- .../src/main/java/org/jackhuang/hmcl/ui/FXUtils.java | 12 ++++++++++++ .../jackhuang/hmcl/ui/versions/WorldInfoPage.java | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index 1bfde9976..4d43f7c20 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -1105,6 +1105,18 @@ public final class FXUtils { }); } + public static void copyOnDoubleClick(Labeled label) { + label.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> { + if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2) { + String text = label.getText(); + if (text != null && !text.isEmpty()) { + copyText(label.getText()); + e.consume(); + } + } + }); + } + public static void copyText(String text) { ClipboardContent content = new ClipboardContent(); content.putString(text); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java index a8d7e2c5b..aaf8aa1bc 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldInfoPage.java @@ -103,6 +103,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { BorderPane.setAlignment(label, Pos.CENTER_LEFT); Label worldNameLabel = new Label(); + FXUtils.copyOnDoubleClick(worldNameLabel); worldNameLabel.setText(world.getWorldName()); BorderPane.setAlignment(worldNameLabel, Pos.CENTER_RIGHT); worldNamePane.setRight(worldNameLabel); @@ -115,6 +116,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { gameVersionPane.setLeft(label); Label gameVersionLabel = new Label(); + FXUtils.copyOnDoubleClick(gameVersionLabel); gameVersionLabel.setText(world.getGameVersion()); BorderPane.setAlignment(gameVersionLabel, Pos.CENTER_RIGHT); gameVersionPane.setRight(gameVersionLabel); @@ -127,6 +129,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { randomSeedPane.setLeft(label); Label randomSeedLabel = new Label(); + FXUtils.copyOnDoubleClick(randomSeedLabel); BorderPane.setAlignment(randomSeedLabel, Pos.CENTER_RIGHT); randomSeedPane.setRight(randomSeedLabel); @@ -143,6 +146,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { lastPlayedPane.setLeft(label); Label lastPlayedLabel = new Label(); + FXUtils.copyOnDoubleClick(lastPlayedLabel); lastPlayedLabel.setText(formatDateTime(Instant.ofEpochMilli(world.getLastPlayed()))); BorderPane.setAlignment(lastPlayedLabel, Pos.CENTER_RIGHT); lastPlayedPane.setRight(lastPlayedLabel); @@ -155,6 +159,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { timePane.setLeft(label); Label timeLabel = new Label(); + FXUtils.copyOnDoubleClick(timeLabel); BorderPane.setAlignment(timeLabel, Pos.CENTER_RIGHT); timePane.setRight(timeLabel); @@ -258,6 +263,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { locationPane.setLeft(label); Label locationLabel = new Label(); + FXUtils.copyOnDoubleClick(locationLabel); BorderPane.setAlignment(locationLabel, Pos.CENTER_RIGHT); locationPane.setRight(locationLabel); @@ -276,6 +282,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { lastDeathLocationPane.setLeft(label); Label lastDeathLocationLabel = new Label(); + FXUtils.copyOnDoubleClick(lastDeathLocationLabel); BorderPane.setAlignment(lastDeathLocationLabel, Pos.CENTER_RIGHT); lastDeathLocationPane.setRight(lastDeathLocationLabel); @@ -297,6 +304,7 @@ public final class WorldInfoPage extends StackPane implements DecoratorPage { spawnPane.setLeft(label); Label spawnLabel = new Label(); + FXUtils.copyOnDoubleClick(spawnLabel); BorderPane.setAlignment(spawnLabel, Pos.CENTER_RIGHT); spawnPane.setRight(spawnLabel);