修复 MessageDialogPane 总是折叠内容的问题 (#1815)
* fix #1751: Use ScrollPane in message dialog only when needed close #1777 * Parse segment only if it contains xml tag
This commit is contained in:
@@ -710,6 +710,9 @@ public final class FXUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Node> parseSegment(String segment, Consumer<String> hyperlinkAction) {
|
public static List<Node> parseSegment(String segment, Consumer<String> hyperlinkAction) {
|
||||||
|
if (segment.indexOf('<') < 0)
|
||||||
|
return Collections.singletonList(new Text(segment));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.ButtonBase;
|
import javafx.scene.control.ButtonBase;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ScrollPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.text.TextFlow;
|
||||||
import org.jackhuang.hmcl.setting.Theme;
|
import org.jackhuang.hmcl.setting.Theme;
|
||||||
import org.jackhuang.hmcl.ui.Controllers;
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
@@ -69,7 +73,17 @@ public final class MessageDialogPane extends StackPane {
|
|||||||
public MessageDialogPane(@NotNull String text, @Nullable String title, @NotNull MessageType type) {
|
public MessageDialogPane(@NotNull String text, @Nullable String title, @NotNull MessageType type) {
|
||||||
FXUtils.loadFXML(this, "/assets/fxml/message-dialog.fxml");
|
FXUtils.loadFXML(this, "/assets/fxml/message-dialog.fxml");
|
||||||
|
|
||||||
content.getChildren().setAll(FXUtils.segmentToTextFlow(text, Controllers::onHyperlinkAction));
|
EnhancedTextFlow textFlow = new EnhancedTextFlow();
|
||||||
|
textFlow.getChildren().setAll(FXUtils.parseSegment(text, Controllers::onHyperlinkAction));
|
||||||
|
|
||||||
|
if (textFlow.computePrefHeight(400.0) <= 350.0)
|
||||||
|
content.getChildren().setAll(textFlow);
|
||||||
|
else {
|
||||||
|
ScrollPane scrollPane = new ScrollPane(textFlow);
|
||||||
|
VBox.setVgrow(scrollPane, Priority.ALWAYS);
|
||||||
|
scrollPane.setFitToWidth(true);
|
||||||
|
content.getChildren().setAll(scrollPane);
|
||||||
|
}
|
||||||
|
|
||||||
if (title != null)
|
if (title != null)
|
||||||
this.title.setText(title);
|
this.title.setText(title);
|
||||||
@@ -114,6 +128,13 @@ public final class MessageDialogPane extends StackPane {
|
|||||||
return cancelButton;
|
return cancelButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class EnhancedTextFlow extends TextFlow {
|
||||||
|
@Override
|
||||||
|
public double computePrefHeight(double width) {
|
||||||
|
return super.computePrefHeight(width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final MessageDialogPane dialog;
|
private final MessageDialogPane dialog;
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +1,24 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.ScrollPane?>
|
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import java.lang.String?>
|
<?import java.lang.String?>
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<fx:root xmlns="http://javafx.com/javafx"
|
<fx:root xmlns="http://javafx.com/javafx"
|
||||||
xmlns:fx="http://javafx.com/fxml"
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
type="StackPane">
|
type="StackPane">
|
||||||
<BorderPane styleClass="jfx-dialog-layout">
|
<HBox spacing="8" styleClass="jfx-dialog-layout">
|
||||||
<left>
|
<Label fx:id="graphic" translateX="10" translateY="10" minWidth="40" maxWidth="40" minHeight="40"
|
||||||
<Label fx:id="graphic" translateX="10" translateY="10" minWidth="40" maxWidth="40" minHeight="40" maxHeight="40" />
|
maxHeight="40"/>
|
||||||
</left>
|
<VBox HBox.hgrow="ALWAYS">
|
||||||
<center>
|
<StackPane>
|
||||||
<VBox>
|
<styleClass>
|
||||||
<BorderPane.margin>
|
<String fx:value="jfx-layout-heading"/>
|
||||||
<Insets left="8" />
|
<String fx:value="title"/>
|
||||||
</BorderPane.margin>
|
</styleClass>
|
||||||
<HBox spacing="8">
|
<Label fx:id="title" text="%message.info"/>
|
||||||
<StackPane>
|
</StackPane>
|
||||||
<styleClass>
|
<StackPane fx:id="content" styleClass="jfx-layout-body"/>
|
||||||
<String fx:value="jfx-layout-heading" />
|
<HBox fx:id="actions" styleClass="jfx-layout-actions"/>
|
||||||
<String fx:value="title" />
|
</VBox>
|
||||||
</styleClass>
|
</HBox>
|
||||||
<Label fx:id="title" text="%message.info" />
|
|
||||||
</StackPane>
|
|
||||||
</HBox>
|
|
||||||
<ScrollPane VBox.vgrow="ALWAYS" fitToWidth="true" fitToHeight="true">
|
|
||||||
<StackPane fx:id="content" styleClass="jfx-layout-body" />
|
|
||||||
</ScrollPane>
|
|
||||||
</VBox>
|
|
||||||
</center>
|
|
||||||
<bottom>
|
|
||||||
<HBox fx:id="actions" styleClass="jfx-layout-actions" />
|
|
||||||
</bottom>
|
|
||||||
</BorderPane>
|
|
||||||
</fx:root>
|
</fx:root>
|
||||||
|
|||||||
Reference in New Issue
Block a user