Skip to content

Commit

Permalink
fix: Various formatting problems with update prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jan 8, 2022
1 parent 7880623 commit 72aa5af
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/main/java/me/coley/recaf/ui/controls/pane/UpdatePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public UpdatePane(GuiController controller) {
GridPane grid = new GridPane();
GridPane.setFillHeight(btn, true);
GridPane.setFillWidth(btn, true);
grid.setMaxWidth(800);
grid.setPadding(new Insets(10));
grid.setVgap(10);
grid.setHgap(10);
Expand All @@ -62,17 +63,46 @@ private BorderPane getNotes() {
Node document = parser.parse(SelfUpdater.getLatestPatchnotes().replaceAll("\\(\\[.+\\)\\)", ""));
document.accept(new AbstractVisitor() {
@Override
public void visit(Text text) {
Node parent = getRoot(text);
if (parent instanceof Heading) {
// Skip the version H1 text
if (((Heading) parent).getLevel() == 1)
return;
//
addLine(text.getLiteral(), "h2");
} else if (parent instanceof BulletList || parent instanceof OrderedList) {
String msg = text.getLiteral();
addLine(" ● " + msg, null);
public void visit(Paragraph paragraph) {
StringBuilder sb = new StringBuilder();
Node node = paragraph.getFirstChild();
build(sb, node);
addLine(sb.toString(), null);
}

@Override
public void visit(Heading heading) {
// Skip the version H2 text
if (heading.getLevel() <= 2)
return;
addLine(build(heading), "h2");
}

@Override
public void visit(BulletList list) {
Node item = list.getFirstChild();
do {
String itemText = build(item);
addLine(" ● " + itemText, null);
item = item.getNext();
} while (item != null);
}

private String build(Node node) {
StringBuilder sb = new StringBuilder();
build(sb, node);
return sb.toString();
}

private void build(StringBuilder sb, Node node) {
if (node instanceof Text)
sb.append(((Text) node).getLiteral());
else {
Node child = node.getFirstChild();
do {
build(sb, child);
child = child.getNext();
} while (child != null);
}
}

Expand All @@ -82,12 +112,6 @@ private void addLine(String text, String style) {
t.getStyleClass().add(style);
flow.getChildren().add(t);
}

private Node getRoot(Node node) {
while(!(node.getParent() instanceof Document))
node = node.getParent();
return node;
}
});
BorderPane pane = new BorderPane(flow);
pane.getStyleClass().add("content");
Expand Down Expand Up @@ -120,7 +144,7 @@ private void update() {
try {
SelfUpdater.updateRecaf();
controller.exit();
} catch(IOException ex) {
} catch (IOException ex) {
Log.error(ex, "Failed to start update process");
ExceptionAlert.show(ex, "Recaf failed to start the update process");
}
Expand Down

0 comments on commit 72aa5af

Please sign in to comment.