Skip to content

Commit

Permalink
Fix for #164
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Sep 4, 2024
1 parent 69d78f3 commit 0894ccd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class StateManager {
private final ObservableList<SidePaneType> visibleSidePanes = FXCollections.observableArrayList();
private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();
private final ObservableList<String> searchHistory = FXCollections.observableArrayList();
private final OptionalObjectProperty<AiChatWindow> aiChatWindow = OptionalObjectProperty.empty();
private final List<AiChatWindow> aiChatWindows = new ArrayList<>();

public ObservableList<SidePaneType> getVisibleSidePaneComponents() {
return visibleSidePanes;
Expand Down Expand Up @@ -211,7 +211,7 @@ public void clearSearchHistory() {
searchHistory.clear();
}

public OptionalObjectProperty<AiChatWindow> getAiChatWindow() {
return aiChatWindow;
public List<AiChatWindow> getAiChatWindows() {
return aiChatWindows;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class AiChatWindow extends BaseWindow {
private final FilePreferences filePreferences;
private final TaskExecutor taskExecutor;

// This field is used for finding an existing AI chat window when user wants to chat with the same group again.
private String chatName;

public AiChatWindow(AiService aiService,
DialogService dialogService,
AiPreferences aiPreferences,
Expand All @@ -38,6 +41,7 @@ public AiChatWindow(AiService aiService,

public void setChat(StringProperty name, ObservableList<ChatMessage> chatHistory, BibDatabaseContext bibDatabaseContext, ObservableList<BibEntry> entries) {
setTitle(Localization.lang("AI chat with %0", name.getValue()));
chatName = name.getValue();
setScene(
new Scene(
new AiChatGuardedComponent(
Expand All @@ -56,4 +60,8 @@ public void setChat(StringProperty name, ObservableList<ChatMessage> chatHistory
)
);
}

public String getChatName() {
return chatName;
}
}
19 changes: 11 additions & 8 deletions src/main/java/org/jabref/logic/ai/AiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public SummariesService getSummariesService() {
}

public void openAiChat(StringProperty name, ObservableList<ChatMessage> chatHistory, BibDatabaseContext bibDatabaseContext, ObservableList<BibEntry> entries) {
if (stateManager.getAiChatWindow().get().isEmpty()) {
Optional<AiChatWindow> existingWindow = stateManager.getAiChatWindows().stream().filter(window -> window.getChatName().equals(name.get())).findFirst();

if (existingWindow.isPresent()) {
existingWindow.get().requestFocus();
} else {
AiChatWindow aiChatWindow = new AiChatWindow(
this,
dialogService,
Expand All @@ -144,16 +148,15 @@ public void openAiChat(StringProperty name, ObservableList<ChatMessage> chatHist
taskExecutor
);

aiChatWindow.setOnCloseRequest(event -> {
stateManager.getAiChatWindow().set(Optional.empty());
});
aiChatWindow.setOnCloseRequest(event ->
stateManager.getAiChatWindows().remove(aiChatWindow)
);

stateManager.getAiChatWindow().set(Optional.of(aiChatWindow));
stateManager.getAiChatWindows().add(aiChatWindow);
dialogService.showCustomWindow(aiChatWindow);
aiChatWindow.setChat(name, chatHistory, bibDatabaseContext, entries);
aiChatWindow.requestFocus();
}

stateManager.getAiChatWindow().get().get().setChat(name, chatHistory, bibDatabaseContext, entries);
stateManager.getAiChatWindow().get().get().requestFocus();
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2646,9 +2646,7 @@ An\ error\ occurred\ while\ opening\ the\ embeddings\ cache\ file.\ Embeddings\
An\ error\ occurred\ while\ opening\ the\ fully\ ingested\ documents\ cache\ file.\ Fully\ ingested\ documents\ will\ not\ be\ stored\ in\ the\ next\ session.=An error occurred while opening the fully ingested documents cache file. Fully ingested documents will not be stored in the next session.
Invalid\ citation\ key\ for\ %0\ (%1)=Invalid citation key for %0 (%1)
No\ citation\ key\ for\ %0=No citation key for %0
No\ files\ attached\ to\ %0=No files attached to %0
Please\ attach\ at\ least\ one\ PDF\ file\ to\ enable\ summarization\ of\ PDF\ file(s).=Please attach at least one PDF file to enable summarization of PDF file(s).
The\ AI\ will\ not\ be\ able\ to\ find\ information\ in\ this\ entry=The AI will not be able to find information in this entry
Unable\ to\ generate\ summary=Unable to generate summary
Group\ %0=Group %0
AI\ chat\ with\ %0=AI chat with %0
Expand Down

0 comments on commit 0894ccd

Please sign in to comment.