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

Use Markdown in AI Summary tab implemented #12266

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.text.TextFlow?>
<fx:root alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" type="VBox" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.ai.components.summary.SummaryShowingComponent">
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.web.*?>
mulla028 marked this conversation as resolved.
Show resolved Hide resolved

<fx:root alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="10.0" type="VBox" xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.ai.components.summary.SummaryShowingComponent">
mulla028 marked this conversation as resolved.
Show resolved Hide resolved
<children>
<TextArea fx:id="summaryTextArea" editable="false" wrapText="true" VBox.vgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#onRegenerateButtonClick" text="%Regenerate" />
<CheckBox fx:id="markdownCheckbox" mnemonicParsing="false" onAction="#onMarkdownToggle" text="Markdown" />
<WebView fx:id="markdownWebView" visible="false" managed="false" VBox.vgrow="ALWAYS" />
<TextArea fx:id="summaryTextArea" editable="false" wrapText="true" VBox.vgrow="ALWAYS" />
<Button mnemonicParsing="false" onAction="#onRegenerateButtonClick" text="%Regenerate" />
<TextFlow textAlignment="CENTER">
<children>
<Text fx:id="summaryInfoText" strokeType="OUTSIDE" strokeWidth="0.0" text="%Generated at %0 by %1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@
import java.util.Locale;

import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;

import org.jabref.logic.ai.summarization.Summary;
import org.jabref.logic.layout.format.MarkdownFormatter;

import com.airhacks.afterburner.views.ViewLoader;

public class SummaryShowingComponent extends VBox {
@FXML private TextArea summaryTextArea;
@FXML private Text summaryInfoText;
@FXML private WebView markdownWebView;
@FXML private CheckBox markdownCheckbox;

private final Summary summary;
private final Runnable regenerateCallback;
private final MarkdownFormatter markdownFormatter;

public SummaryShowingComponent(Summary summary, Runnable regenerateCallback) {
this.summary = summary;
this.regenerateCallback = regenerateCallback;
this.markdownFormatter = new MarkdownFormatter();
mulla028 marked this conversation as resolved.
Show resolved Hide resolved

ViewLoader.view(this)
.root(this)
Expand All @@ -33,6 +40,8 @@ public SummaryShowingComponent(Summary summary, Runnable regenerateCallback) {
@FXML
private void initialize() {
summaryTextArea.setText(summary.content());
markdownWebView.setVisible(false);
markdownWebView.setManaged(false);

String newInfo = summaryInfoText
.getText()
Expand All @@ -46,6 +55,29 @@ private static String formatTimestamp(LocalDateTime timestamp) {
return timestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.getDefault()));
}

@FXML
private void onMarkdownToggle() {
if (markdownCheckbox.isSelected()) {
String htmlContent = markdownFormatter.format(summaryTextArea.getText());
markdownWebView.getEngine().loadContent(htmlContent);

markdownWebView.setPrefHeight(summaryTextArea.getPrefHeight());
markdownWebView.setPrefWidth(summaryTextArea.getPrefWidth());

markdownWebView.setVisible(true);
markdownWebView.setManaged(true);

summaryTextArea.setVisible(false);
summaryTextArea.setManaged(false);
} else {
summaryTextArea.setVisible(true);
summaryTextArea.setManaged(true);

markdownWebView.setVisible(false);
markdownWebView.setManaged(false);
}
}

@FXML
private void onRegenerateButtonClick() {
regenerateCallback.run();
Expand Down
Loading