From 4ff8eb58dfb62fb617270b46cd997ab76cf54a34 Mon Sep 17 00:00:00 2001 From: Alessio Gazzara <81399617+ZodGaz@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:10:20 +0200 Subject: [PATCH] Refactor "enableFileAnnotationsTab" to "smartFileAnnotationsTab" and rewrote shouldShow in FileAnnotationTab as requested in #13279 --- .../fileannotationtab/FileAnnotationTab.java | 20 +++++++++---------- .../gui/preferences/JabRefGuiPreferences.java | 4 ++-- .../entryeditor/EntryEditorTab.java | 4 ++-- .../entryeditor/EntryEditorTabViewModel.java | 10 +++++----- .../entryeditor/EntryEditorTab.fxml | 2 +- .../preferences/JabRefCliPreferences.java | 4 ++-- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/jabgui/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FileAnnotationTab.java b/jabgui/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FileAnnotationTab.java index 3273abe6824..462618171ae 100644 --- a/jabgui/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FileAnnotationTab.java +++ b/jabgui/src/main/java/org/jabref/gui/entryeditor/fileannotationtab/FileAnnotationTab.java @@ -1,9 +1,5 @@ package org.jabref.gui.entryeditor.fileannotationtab; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - import javafx.scene.Parent; import javafx.scene.control.Tooltip; @@ -15,7 +11,6 @@ import org.jabref.logic.pdf.FileAnnotationCache; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; -import org.jabref.model.pdf.FileAnnotation; import com.airhacks.afterburner.views.ViewLoader; @@ -37,15 +32,18 @@ public FileAnnotationTab(StateManager stateManager, @Override public boolean shouldShow(BibEntry entry) { - boolean hasAnnotations = false; if (!entryEditorPreferences.shouldShowFileAnnotationsTab()) { return entry.getField(StandardField.FILE).isPresent(); } - if (stateManager.activeTabProperty().get().isPresent()) { - Map> fileAnnotations = stateManager.activeTabProperty().get().get().getAnnotationCache().getFromCache(entry); - hasAnnotations = fileAnnotations.values().stream().anyMatch(list -> !list.isEmpty()); - } - return entry.getField(StandardField.FILE).isPresent() && hasAnnotations; + + return entry.getField(StandardField.FILE).isPresent() + && stateManager.activeTabProperty().get() + .map(tab -> tab.getAnnotationCache() + .getFromCache(entry) + .values() + .stream() + .anyMatch(list -> !list.isEmpty())) + .orElse(false); } @Override diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java index 1c06d3b973a..fee55c3d475 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java @@ -475,7 +475,7 @@ public EntryEditorPreferences getEntryEditorPreferences() { getBoolean(SHOW_AI_SUMMARY), getBoolean(SHOW_AI_CHAT), getBoolean(SHOW_LATEX_CITATIONS), - getBoolean(SHOW_FILE_ANNOTATIONS), + getBoolean(SMART_FILE_ANNOTATIONS), getBoolean(DEFAULT_SHOW_SOURCE), getBoolean(VALIDATE_IN_ENTRY_EDITOR), getBoolean(ALLOW_INTEGER_EDITION_BIBTEX), @@ -492,7 +492,7 @@ public EntryEditorPreferences getEntryEditorPreferences() { EasyBind.listen(entryEditorPreferences.shouldShowAiSummaryTabProperty(), (_, _, newValue) -> putBoolean(SHOW_AI_SUMMARY, newValue)); EasyBind.listen(entryEditorPreferences.shouldShowAiChatTabProperty(), (_, _, newValue) -> putBoolean(SHOW_AI_CHAT, newValue)); EasyBind.listen(entryEditorPreferences.shouldShowLatexCitationsTabProperty(), (_, _, newValue) -> putBoolean(SHOW_LATEX_CITATIONS, newValue)); - EasyBind.listen(entryEditorPreferences.shouldShowFileAnnotationsTabProperty(), (_, _, newValue) -> putBoolean(SHOW_FILE_ANNOTATIONS, newValue)); + EasyBind.listen(entryEditorPreferences.shouldShowFileAnnotationsTabProperty(), (_, _, newValue) -> putBoolean(SMART_FILE_ANNOTATIONS, newValue)); EasyBind.listen(entryEditorPreferences.showSourceTabByDefaultProperty(), (_, _, newValue) -> putBoolean(DEFAULT_SHOW_SOURCE, newValue)); EasyBind.listen(entryEditorPreferences.enableValidationProperty(), (_, _, newValue) -> putBoolean(VALIDATE_IN_ENTRY_EDITOR, newValue)); EasyBind.listen(entryEditorPreferences.allowIntegerEditionBibtexProperty(), (_, _, newValue) -> putBoolean(ALLOW_INTEGER_EDITION_BIBTEX, newValue)); diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java b/jabgui/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java index 8d1cfb99f20..e4d41f6b348 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/entryeditor/EntryEditorTab.java @@ -24,7 +24,7 @@ public class EntryEditorTab extends AbstractPreferenceTabView - + diff --git a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java index 081d853803b..6cc56d08f19 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java @@ -258,7 +258,7 @@ public class JabRefCliPreferences implements CliPreferences { public static final String NAME_FORMATER_KEY = "nameFormatterNames"; public static final String SHOW_RECOMMENDATIONS = "showRecommendations"; public static final String SHOW_AI_SUMMARY = "showAiSummary"; - public static final String SHOW_FILE_ANNOTATIONS = "showFileAnnotations"; + public static final String SMART_FILE_ANNOTATIONS = "smartFileAnnotations"; public static final String SHOW_AI_CHAT = "showAiChat"; public static final String ACCEPT_RECOMMENDATIONS = "acceptRecommendations"; public static final String SHOW_LATEX_CITATIONS = "showLatexCitations"; @@ -553,7 +553,7 @@ protected JabRefCliPreferences() { defaults.put(SHOW_RECOMMENDATIONS, Boolean.TRUE); defaults.put(SHOW_AI_CHAT, Boolean.TRUE); defaults.put(SHOW_AI_SUMMARY, Boolean.TRUE); - defaults.put(SHOW_FILE_ANNOTATIONS, Boolean.TRUE); + defaults.put(SMART_FILE_ANNOTATIONS, Boolean.TRUE); defaults.put(ACCEPT_RECOMMENDATIONS, Boolean.FALSE); defaults.put(SHOW_LATEX_CITATIONS, Boolean.TRUE); defaults.put(SHOW_SCITE_TAB, Boolean.TRUE);