From 920127a4cef81f0cae48a15e9b1680fe44c93613 Mon Sep 17 00:00:00 2001 From: Alessio Gazzara <81399617+ZodGaz@users.noreply.github.com> Date: Sun, 8 Jun 2025 18:39:51 +0200 Subject: [PATCH 1/4] fixes #13143, added a checkbox as described in the issue to not show the file annotation tab when annotations are not present in the entry files. --- CHANGELOG.md | 2 ++ .../jabref/gui/entryeditor/EntryEditor.java | 2 +- .../entryeditor/EntryEditorPreferences.java | 15 +++++++++++ .../fileannotationtab/FileAnnotationTab.java | 27 ++++++++++++++++--- .../gui/preferences/JabRefGuiPreferences.java | 2 ++ .../entryeditor/EntryEditorTab.java | 2 ++ .../entryeditor/EntryEditorTabViewModel.java | 7 +++++ .../entryeditor/EntryEditorTab.fxml | 1 + .../preferences/JabRefCliPreferences.java | 3 +++ .../main/resources/l10n/JabRef_en.properties | 1 + 10 files changed, 58 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30029a698af..80fda07540a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ 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..653b54b4040 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 @@ -4,21 +4,32 @@ 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 com.airhacks.afterburner.views.ViewLoader; +import org.jabref.model.pdf.FileAnnotation; + +import java.nio.file.Path; +import java.util.List; +import java.util.Map; 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,9 +37,19 @@ 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 protected void bindToEntry(BibEntry entry) { if (stateManager.activeTabProperty().get().isPresent()) { 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..73f2acb7b87 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,8 @@ 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 +552,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..94e6042d4b7 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] From 8cbd3e18af83a094c3f9db2012c8da172107f7df Mon Sep 17 00:00:00 2001 From: Alessio Gazzara <81399617+ZodGaz@users.noreply.github.com> Date: Sun, 8 Jun 2025 18:46:06 +0200 Subject: [PATCH 2/4] removed useless spacing --- .../entryeditor/fileannotationtab/FileAnnotationTab.java | 6 ++---- .../org/jabref/logic/preferences/JabRefCliPreferences.java | 1 - 2 files changed, 2 insertions(+), 5 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 653b54b4040..ec9e8453dc1 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 @@ -43,13 +43,11 @@ public boolean shouldShow(BibEntry entry) { } if (stateManager.activeTabProperty().get().isPresent()) { Map> fileAnnotations = stateManager.activeTabProperty().get().get().getAnnotationCache().getFromCache(entry); - - hasAnnotations = fileAnnotations.values().stream() - .anyMatch(list -> !list.isEmpty()); - + hasAnnotations = fileAnnotations.values().stream().anyMatch(list -> !list.isEmpty()); } return entry.getField(StandardField.FILE).isPresent() && hasAnnotations; } + @Override protected void bindToEntry(BibEntry entry) { if (stateManager.activeTabProperty().get().isPresent()) { 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 73f2acb7b87..2d0b1e74d1e 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,6 @@ public class JabRefCliPreferences implements CliPreferences { 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"; From 9e6748be778726befe02388633bf0704e90aea0a Mon Sep 17 00:00:00 2001 From: Alessio Gazzara <81399617+ZodGaz@users.noreply.github.com> Date: Sun, 8 Jun 2025 19:06:32 +0200 Subject: [PATCH 3/4] Fixed markdown,checkstyle and unit test failures --- CHANGELOG.md | 1 - .../entryeditor/fileannotationtab/FileAnnotationTab.java | 8 ++++---- jablib/src/main/resources/l10n/JabRef_en.properties | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fda07540a..cbcc61437d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,6 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - 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 - We moved some functionality from the graphical application `jabref` with new command verbs `generate-citation-keys`, `check-consistency`, `fetch`, `search`, `convert`, `generate-bib-from-aux`, `preferences` and `pdf` to the new toolkit. [#13012](https://github.com/JabRef/jabref/pull/13012) [#110](https://github.com/JabRef/jabref/issues/110) 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 ec9e8453dc1..e86ab901bc2 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,5 +1,9 @@ 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,10 +19,6 @@ import com.airhacks.afterburner.views.ViewLoader; import org.jabref.model.pdf.FileAnnotation; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - public class FileAnnotationTab extends EntryEditorTab { public static final String NAME = "File annotations"; diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties index 94e6042d4b7..7fa73838843 100644 --- a/jablib/src/main/resources/l10n/JabRef_en.properties +++ b/jablib/src/main/resources/l10n/JabRef_en.properties @@ -2070,7 +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\ '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] From e0aea5741677bc1bde9246991884a76290cf66ac Mon Sep 17 00:00:00 2001 From: Alessio Gazzara <81399617+ZodGaz@users.noreply.github.com> Date: Sun, 8 Jun 2025 19:12:04 +0200 Subject: [PATCH 4/4] Fixed checkstyle test failure --- .../gui/entryeditor/fileannotationtab/FileAnnotationTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e86ab901bc2..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 @@ -15,9 +15,9 @@ 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; -import org.jabref.model.pdf.FileAnnotation; public class FileAnnotationTab extends EntryEditorTab {