Skip to content

Commit 72aa5af

Browse files
committed
fix: Various formatting problems with update prompt
1 parent 7880623 commit 72aa5af

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

src/main/java/me/coley/recaf/ui/controls/pane/UpdatePane.java

+42-18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public UpdatePane(GuiController controller) {
3737
GridPane grid = new GridPane();
3838
GridPane.setFillHeight(btn, true);
3939
GridPane.setFillWidth(btn, true);
40+
grid.setMaxWidth(800);
4041
grid.setPadding(new Insets(10));
4142
grid.setVgap(10);
4243
grid.setHgap(10);
@@ -62,17 +63,46 @@ private BorderPane getNotes() {
6263
Node document = parser.parse(SelfUpdater.getLatestPatchnotes().replaceAll("\\(\\[.+\\)\\)", ""));
6364
document.accept(new AbstractVisitor() {
6465
@Override
65-
public void visit(Text text) {
66-
Node parent = getRoot(text);
67-
if (parent instanceof Heading) {
68-
// Skip the version H1 text
69-
if (((Heading) parent).getLevel() == 1)
70-
return;
71-
//
72-
addLine(text.getLiteral(), "h2");
73-
} else if (parent instanceof BulletList || parent instanceof OrderedList) {
74-
String msg = text.getLiteral();
75-
addLine(" ● " + msg, null);
66+
public void visit(Paragraph paragraph) {
67+
StringBuilder sb = new StringBuilder();
68+
Node node = paragraph.getFirstChild();
69+
build(sb, node);
70+
addLine(sb.toString(), null);
71+
}
72+
73+
@Override
74+
public void visit(Heading heading) {
75+
// Skip the version H2 text
76+
if (heading.getLevel() <= 2)
77+
return;
78+
addLine(build(heading), "h2");
79+
}
80+
81+
@Override
82+
public void visit(BulletList list) {
83+
Node item = list.getFirstChild();
84+
do {
85+
String itemText = build(item);
86+
addLine(" ● " + itemText, null);
87+
item = item.getNext();
88+
} while (item != null);
89+
}
90+
91+
private String build(Node node) {
92+
StringBuilder sb = new StringBuilder();
93+
build(sb, node);
94+
return sb.toString();
95+
}
96+
97+
private void build(StringBuilder sb, Node node) {
98+
if (node instanceof Text)
99+
sb.append(((Text) node).getLiteral());
100+
else {
101+
Node child = node.getFirstChild();
102+
do {
103+
build(sb, child);
104+
child = child.getNext();
105+
} while (child != null);
76106
}
77107
}
78108

@@ -82,12 +112,6 @@ private void addLine(String text, String style) {
82112
t.getStyleClass().add(style);
83113
flow.getChildren().add(t);
84114
}
85-
86-
private Node getRoot(Node node) {
87-
while(!(node.getParent() instanceof Document))
88-
node = node.getParent();
89-
return node;
90-
}
91115
});
92116
BorderPane pane = new BorderPane(flow);
93117
pane.getStyleClass().add("content");
@@ -120,7 +144,7 @@ private void update() {
120144
try {
121145
SelfUpdater.updateRecaf();
122146
controller.exit();
123-
} catch(IOException ex) {
147+
} catch (IOException ex) {
124148
Log.error(ex, "Failed to start update process");
125149
ExceptionAlert.show(ex, "Recaf failed to start the update process");
126150
}

0 commit comments

Comments
 (0)