diff --git a/CHANGELOG.md b/CHANGELOG.md index 30029a698af..cbcc61437d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added support for import of a Refer/BibIX file format. [#13069](https://github.com/JabRef/jabref/issues/13069) - We added a new `jabkit` command `pseudonymize` to pseudonymize the library. [#13109](https://github.com/JabRef/jabref/issues/13109) - We added functionality to focus running instance when trying to start a second instance. [#13129](https://github.com/JabRef/jabref/issues/13129) +- We added a new setting in the 'Entry Editor' preferences to hide the 'File Annotations' tab when no annotations are available. [#13143](https://github.com/JabRef/jabref/issues/13143) ### Changed diff --git a/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index dfc7969d2f1..51591b03676 100644 --- a/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -321,7 +321,7 @@ private List createTabs() { } tabs.add(new MathSciNetTab()); - tabs.add(new FileAnnotationTab(stateManager)); + tabs.add(new FileAnnotationTab(stateManager, preferences)); tabs.add(new SciteTab(preferences, taskExecutor, dialogService)); tabs.add(new CitationRelationsTab(dialogService, undoManager, stateManager, fileMonitor, preferences, taskExecutor, bibEntryTypesManager)); tabs.add(new RelatedArticlesTab(buildInfo, preferences, dialogService, stateManager, taskExecutor)); diff --git a/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java b/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java index e328b887d14..561736fd7a1 100644 --- a/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/entryeditor/EntryEditorPreferences.java @@ -43,6 +43,7 @@ public static JournalPopupEnabled fromString(String status) { private final BooleanProperty shouldShowAiSummaryTab; private final BooleanProperty shouldShowAiChatTab; private final BooleanProperty shouldShowLatexCitationsTab; + private final BooleanProperty shouldShowFileAnnotationsTab; private final BooleanProperty showSourceTabByDefault; private final BooleanProperty enableValidation; private final BooleanProperty allowIntegerEditionBibtex; @@ -59,6 +60,7 @@ public EntryEditorPreferences(Map> entryEditorTabList, boolean shouldShowAiSummaryTab, boolean shouldShowAiChatTab, boolean shouldShowLatexCitationsTab, + boolean shouldShowFileAnnotationsTab, boolean showSourceTabByDefault, boolean enableValidation, boolean allowIntegerEditionBibtex, @@ -75,6 +77,7 @@ public EntryEditorPreferences(Map> entryEditorTabList, this.shouldShowAiSummaryTab = new SimpleBooleanProperty(shouldShowAiSummaryTab); this.shouldShowAiChatTab = new SimpleBooleanProperty(shouldShowAiChatTab); this.shouldShowLatexCitationsTab = new SimpleBooleanProperty(shouldShowLatexCitationsTab); + this.shouldShowFileAnnotationsTab = new SimpleBooleanProperty(shouldShowFileAnnotationsTab); this.showSourceTabByDefault = new SimpleBooleanProperty(showSourceTabByDefault); this.enableValidation = new SimpleBooleanProperty(enableValidation); this.allowIntegerEditionBibtex = new SimpleBooleanProperty(allowIntegerEditionBibtex); @@ -161,6 +164,18 @@ public void setShouldShowLatexCitationsTab(boolean shouldShowLatexCitationsTab) this.shouldShowLatexCitationsTab.set(shouldShowLatexCitationsTab); } + public boolean shouldShowFileAnnotationsTab() { + return shouldShowFileAnnotationsTab.get(); + } + + public BooleanProperty shouldShowFileAnnotationsTabProperty() { + return shouldShowFileAnnotationsTab; + } + + public void setShouldShowFileAnnotationsTab(boolean shouldShowFileAnnotationsTab) { + this.shouldShowFileAnnotationsTab.set(shouldShowFileAnnotationsTab); + } + public boolean showSourceTabByDefault() { return showSourceTabByDefault.get(); } 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 7dd17139e7a..3273abe6824 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,24 +1,35 @@ 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; import org.jabref.gui.StateManager; +import org.jabref.gui.entryeditor.EntryEditorPreferences; import org.jabref.gui.entryeditor.EntryEditorTab; +import org.jabref.gui.preferences.GuiPreferences; import org.jabref.logic.l10n.Localization; 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; public class FileAnnotationTab extends EntryEditorTab { public static final String NAME = "File annotations"; + private final StateManager stateManager; + private final EntryEditorPreferences entryEditorPreferences; - public FileAnnotationTab(StateManager stateManager) { + public FileAnnotationTab(StateManager stateManager, + GuiPreferences preferences) { this.stateManager = stateManager; + this.entryEditorPreferences = preferences.getEntryEditorPreferences(); setText(Localization.lang("File annotations")); setTooltip(new Tooltip(Localization.lang("Show file annotations"))); @@ -26,7 +37,15 @@ public FileAnnotationTab(StateManager stateManager) { @Override public boolean shouldShow(BibEntry entry) { - return entry.getField(StandardField.FILE).isPresent(); + 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; } @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 2a8f5157b0e..1c06d3b973a 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/JabRefGuiPreferences.java @@ -475,6 +475,7 @@ public EntryEditorPreferences getEntryEditorPreferences() { getBoolean(SHOW_AI_SUMMARY), getBoolean(SHOW_AI_CHAT), getBoolean(SHOW_LATEX_CITATIONS), + getBoolean(SHOW_FILE_ANNOTATIONS), getBoolean(DEFAULT_SHOW_SOURCE), getBoolean(VALIDATE_IN_ENTRY_EDITOR), getBoolean(ALLOW_INTEGER_EDITION_BIBTEX), @@ -491,6 +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.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 bee167050a8..8d1cfb99f20 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,6 +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 64a4bb345a3..2d0b1e74d1e 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java @@ -257,6 +257,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 SHOW_AI_CHAT = "showAiChat"; public static final String ACCEPT_RECOMMENDATIONS = "acceptRecommendations"; public static final String SHOW_LATEX_CITATIONS = "showLatexCitations"; @@ -550,6 +551,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(ACCEPT_RECOMMENDATIONS, Boolean.FALSE); defaults.put(SHOW_LATEX_CITATIONS, Boolean.TRUE); defaults.put(SHOW_SCITE_TAB, Boolean.TRUE); diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties index bff236c92a6..7fa73838843 100644 --- a/jablib/src/main/resources/l10n/JabRef_en.properties +++ b/jablib/src/main/resources/l10n/JabRef_en.properties @@ -2070,6 +2070,7 @@ There\ already\ exists\ an\ external\ file\ type\ with\ the\ same\ name=There al Show\ tab\ 'LaTeX\ citations'=Show tab 'LaTeX citations' +Show\ tab\ 'File\ annotations'\ only\ if\ it\ contains\ highlights\ or\ comments=Show tab 'File annotations' only if it contains highlights or comments Show\ tab\ 'Citation\ information'=Show tab 'Citation information' Search\ scite.ai\ for\ Smart\ Citations=Search scite.ai for Smart Citations See\ full\ report\ at\ [%0]=See full report at [%0]