-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
mulla028
wants to merge
15
commits into
JabRef:main
Choose a base branch
from
mulla028:issue-12233
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−19
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cdd56e2
Checkbox and WebView added to the FXML
mulla028 57fb5f6
WebView and CheckBox added, onMarkdownToggle() method implemented to …
mulla028 ad38825
WebView erased from fxml
mulla028 71e1f22
WebView added and set programmatically
mulla028 e1816c4
CheckBox Moved
mulla028 fe4b53f
TextArea wrapped around StackPane | Imports updated | Version updated
mulla028 e62d4f2
StackPane added | MarkdownFormatter initialized outside of contructor…
mulla028 834e51e
CheckBox and The Button on the same level, wrapped around BorderPane
mulla028 b5199d4
replace TextArea with WebView for summary display
mulla028 4a0bd3b
simplify summary component layout
mulla028 cab3a8e
TextFlow removed
mulla028 b74af64
<pre> changed to <body><div>
mulla028 9ee5fb8
Default FontFamily and Size applied using ThemeManager
mulla028 a4bace7
Described the PR in CHANGELOG.md
mulla028 da853b1
MarkdownFormatter renamed and now static
mulla028 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 19 additions & 15 deletions
34
src/main/java/org/jabref/gui/ai/components/summary/SummaryShowingComponent.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.CheckBox?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.TextArea?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import javafx.scene.text.Text?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?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"> | ||
<children> | ||
<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" /> | ||
</children> | ||
</TextFlow> | ||
</children> | ||
<padding> | ||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" /> | ||
</padding> | ||
<?import javafx.scene.text.Text?> | ||
|
||
<fx:root alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="400.0" minWidth="-Infinity" spacing="8.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"> | ||
<children> | ||
<BorderPane minHeight="30.0"> | ||
<left> | ||
<CheckBox fx:id="markdownCheckbox" mnemonicParsing="false" onAction="#onMarkdownToggle" text="Markdown" /> | ||
</left> | ||
<center> | ||
<Button mnemonicParsing="false" onAction="#onRegenerateButtonClick" text="%Regenerate" translateX="-40" /> | ||
</center> | ||
</BorderPane> | ||
<Text fx:id="summaryInfoText" strokeType="OUTSIDE" strokeWidth="0.0" text="%Generated at %0 by %1" /> | ||
</children> | ||
<padding> | ||
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" /> | ||
</padding> | ||
</fx:root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,28 @@ | |
import java.util.Locale; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.TextArea; | ||
import javafx.scene.control.CheckBox; | ||
import javafx.scene.layout.Priority; | ||
import javafx.scene.layout.VBox; | ||
import javafx.scene.text.Text; | ||
import javafx.scene.web.WebView; | ||
|
||
import org.jabref.gui.theme.ThemeManager; | ||
import org.jabref.logic.ai.summarization.Summary; | ||
import org.jabref.logic.layout.format.MarkdownFormatter; | ||
import org.jabref.logic.util.WebViewStore; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
import jakarta.inject.Inject; | ||
|
||
public class SummaryShowingComponent extends VBox { | ||
@FXML private TextArea summaryTextArea; | ||
private static final MarkdownFormatter MARKDOWN_FORMATTER = new MarkdownFormatter(); | ||
@FXML private Text summaryInfoText; | ||
@FXML private CheckBox markdownCheckbox; | ||
|
||
@Inject private ThemeManager themeManager; | ||
|
||
private WebView contentWebView; | ||
private final Summary summary; | ||
private final Runnable regenerateCallback; | ||
|
||
|
@@ -32,20 +42,51 @@ public SummaryShowingComponent(Summary summary, Runnable regenerateCallback) { | |
|
||
@FXML | ||
private void initialize() { | ||
summaryTextArea.setText(summary.content()); | ||
initializeWebView(); | ||
updateContent(false); // Start in plain text mode | ||
updateInfoText(); | ||
} | ||
|
||
private void initializeWebView() { | ||
contentWebView = WebViewStore.get(); | ||
VBox.setVgrow(contentWebView, Priority.ALWAYS); | ||
|
||
themeManager.installCss(contentWebView.getEngine()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
getChildren().addFirst(contentWebView); | ||
} | ||
|
||
private void updateContent(boolean isMarkdown) { | ||
String content = summary.content(); | ||
if (isMarkdown) { | ||
contentWebView.getEngine().loadContent(MARKDOWN_FORMATTER.format(content)); | ||
} else { | ||
contentWebView.getEngine().loadContent( | ||
"<body style='margin: 0; padding: 5px; width: 100vw'>" + | ||
"<div style='white-space: pre-wrap; word-wrap: break-word; width: 100vw'>" + | ||
content + | ||
"</div></body>" | ||
); | ||
} | ||
} | ||
|
||
private void updateInfoText() { | ||
String newInfo = summaryInfoText | ||
.getText() | ||
.replaceAll("%0", formatTimestamp(summary.timestamp())) | ||
.replaceAll("%1", summary.aiProvider().getLabel() + " " + summary.model()); | ||
|
||
summaryInfoText.setText(newInfo); | ||
} | ||
|
||
private static String formatTimestamp(LocalDateTime timestamp) { | ||
return timestamp.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.getDefault())); | ||
} | ||
|
||
@FXML | ||
private void onMarkdownToggle() { | ||
updateContent(markdownCheckbox.isSelected()); | ||
} | ||
|
||
@FXML | ||
private void onRegenerateButtonClick() { | ||
regenerateCallback.run(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As AI features are not currently released, we don't put them in
CHANGLELOG.md