diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cce8e24958..a25b3fa0479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Added +- We added an option in Journal Abbreviations preferences to disable the built-in JabRef journal abbreviation list, allowing users to rely solely on their own custom lists. [#12468](https://github.com/JabRef/jabref/issues/12468) - We added a label to the Group dropdown in the Import Dialog. [#15567](https://github.com/JabRef/jabref/issues/15567) - We added a related work text extractor, which finds and inserts the related work text into bib entries from references in the texts. [#9840](https://github.com/JabRef/jabref/issues/9840) - We added a hover button on group rows to quickly add a new group or subgroup. [#12289](https://github.com/JabRef/jabref/issues/12289) diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java b/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java index c9d9b0ca235..383ec2cbba3 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.java @@ -57,6 +57,7 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView searchTerm.isEmpty() || abbreviation.containsCaseIndependent(searchTerm))); useFJournal.selectedProperty().bindBidirectional(viewModel.useFJournalProperty()); + useBuiltInList.selectedProperty().bindBidirectional(viewModel.useBuiltInListProperty()); } private void setAnimations() { diff --git a/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java b/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java index ca04e09f917..b7b21bdd103 100644 --- a/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java +++ b/jabgui/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTabViewModel.java @@ -47,6 +47,7 @@ public class JournalAbbreviationsTabViewModel implements PreferenceTabViewModel private final SimpleBooleanProperty isEditableAndRemovable = new SimpleBooleanProperty(false); private final SimpleBooleanProperty isAbbreviationEditableAndRemovable = new SimpleBooleanProperty(false); private final SimpleBooleanProperty useFJournal = new SimpleBooleanProperty(true); + private final SimpleBooleanProperty useBuiltInList = new SimpleBooleanProperty(true); private final DialogService dialogService; private final TaskExecutor taskExecutor; @@ -107,6 +108,8 @@ public JournalAbbreviationsTabViewModel(JournalAbbreviationPreferences abbreviat public void setValues() { journalFiles.clear(); + useBuiltInList.set(abbreviationsPreferences.shouldUseBuiltInList()); + useFJournal.set(abbreviationsPreferences.shouldUseFJournalField()); createFileObjects(); selectLastJournalFile(); addBuiltInList(); @@ -311,6 +314,7 @@ public void storeSettings() { abbreviationsPreferences.setExternalJournalLists(journalStringList); abbreviationsPreferences.setUseFJournalField(useFJournal.get()); + abbreviationsPreferences.setUseBuiltInList(useBuiltInList.get()); if (shouldWriteLists) { saveJournalAbbreviationFiles(); @@ -363,4 +367,8 @@ public SimpleBooleanProperty isFileRemovableProperty() { public SimpleBooleanProperty useFJournalProperty() { return useFJournal; } + + public SimpleBooleanProperty useBuiltInListProperty() { + return useBuiltInList; + } } diff --git a/jabgui/src/main/resources/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml b/jabgui/src/main/resources/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml index f909ee6a3d6..c241ae8fef3 100644 --- a/jabgui/src/main/resources/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml +++ b/jabgui/src/main/resources/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml @@ -82,6 +82,10 @@ + + + + diff --git a/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java b/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java index fad8f2c7e27..f7b95f8d3bf 100644 --- a/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java +++ b/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java @@ -11,6 +11,7 @@ import org.jabref.logic.journals.ltwa.LtwaRepository; +import org.h2.mvstore.MVStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,23 +36,41 @@ public static Collection readAbbreviationsFromCsvFile(Path file) t public static JournalAbbreviationRepository loadRepository(JournalAbbreviationPreferences journalAbbreviationPreferences) { JournalAbbreviationRepository repository; - // Initialize with built-in list - try (InputStream resourceAsStream = JournalAbbreviationRepository.class.getResourceAsStream("/journals/journal-list.mv")) { - if (resourceAsStream == null) { - LOGGER.warn("There is no journal-list.mv. We use a default journal list."); - repository = new JournalAbbreviationRepository(); - } else { - Path tempDir = Files.createTempDirectory("jabref-journal"); - Path tempJournalList = tempDir.resolve("journal-list.mv"); - Files.copy(resourceAsStream, tempJournalList); - repository = new JournalAbbreviationRepository(tempJournalList, loadLtwaRepository()); + if (!journalAbbreviationPreferences.shouldUseBuiltInList()) { + LOGGER.debug("Built-in journal abbreviation list is disabled by user preference."); + try { + Path tempDir = Files.createTempDirectory("jabref-journal-empty"); + Path emptyJournalList = tempDir.resolve("journal-list.mv"); + // Write an empty MV store so the repository has no built-in entries + try (MVStore store = new MVStore.Builder() + .fileName(emptyJournalList.toAbsolutePath().toString()).open()) { + store.openMap("FullToAbbreviation"); + } + repository = new JournalAbbreviationRepository(emptyJournalList, loadLtwaRepository()); tempDir.toFile().deleteOnExit(); - tempJournalList.toFile().deleteOnExit(); - LOGGER.debug("Loaded journal abbreviations from {}", tempJournalList.toAbsolutePath()); + emptyJournalList.toFile().deleteOnExit(); + } catch (IOException e) { + LOGGER.error("Error while creating empty journal abbreviation repository", e); + return null; + } + } else { + try (InputStream resourceAsStream = JournalAbbreviationRepository.class.getResourceAsStream("/journals/journal-list.mv")) { + if (resourceAsStream == null) { + LOGGER.warn("There is no journal-list.mv. We use a default journal list."); + repository = new JournalAbbreviationRepository(); + } else { + Path tempDir = Files.createTempDirectory("jabref-journal"); + Path tempJournalList = tempDir.resolve("journal-list.mv"); + Files.copy(resourceAsStream, tempJournalList); + repository = new JournalAbbreviationRepository(tempJournalList, loadLtwaRepository()); + tempDir.toFile().deleteOnExit(); + tempJournalList.toFile().deleteOnExit(); + LOGGER.debug("Loaded journal abbreviations from {}", tempJournalList.toAbsolutePath()); + } + } catch (IOException e) { + LOGGER.error("Error while loading journal abbreviation repository", e); + return null; } - } catch (IOException e) { - LOGGER.error("Error while loading journal abbreviation repository", e); - return null; } // Read external lists @@ -90,6 +109,6 @@ private static LtwaRepository loadLtwaRepository() throws IOException { } public static JournalAbbreviationRepository loadBuiltInRepository() { - return loadRepository(new JournalAbbreviationPreferences(List.of(), true)); + return loadRepository(new JournalAbbreviationPreferences(List.of(), true, true)); } } diff --git a/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java b/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java index 0dab28fb911..073c0813f41 100644 --- a/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java @@ -11,23 +11,28 @@ public class JournalAbbreviationPreferences { private final ObservableList externalJournalLists; private final BooleanProperty useFJournalField; + private final BooleanProperty useBuiltInList; public JournalAbbreviationPreferences(List externalJournalLists, - boolean useFJournalField) { + boolean useFJournalField, + boolean useBuiltInList) { this.externalJournalLists = FXCollections.observableArrayList(externalJournalLists); this.useFJournalField = new SimpleBooleanProperty(useFJournalField); + this.useBuiltInList = new SimpleBooleanProperty(useBuiltInList); } private JournalAbbreviationPreferences() { this( List.of(), // externalJournalLists - true // useFJournalField + true, // useFJournalField + true // useBuiltInList ); } public void setAll(JournalAbbreviationPreferences preferences) { this.externalJournalLists.setAll(preferences.externalJournalLists); this.useFJournalField.set(preferences.shouldUseFJournalField()); + this.useBuiltInList.set(preferences.shouldUseBuiltInList()); } public static JournalAbbreviationPreferences getDefault() { @@ -54,4 +59,16 @@ public BooleanProperty useFJournalFieldProperty() { public void setUseFJournalField(boolean useFJournalField) { this.useFJournalField.set(useFJournalField); } + + public boolean shouldUseBuiltInList() { + return useBuiltInList.get(); + } + + public BooleanProperty useBuiltInListProperty() { + return useBuiltInList; + } + + public void setUseBuiltInList(boolean useBuiltInList) { + this.useBuiltInList.set(useBuiltInList); + } } 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 0fc6b72f7ae..986de2a67e1 100644 --- a/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java +++ b/jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java @@ -350,6 +350,7 @@ public class JabRefCliPreferences implements CliPreferences { // Journal private static final String EXTERNAL_JOURNAL_LISTS = "externalJournalLists"; private static final String USE_AMS_FJOURNAL = "useAMSFJournal"; + private static final String USE_BUILT_IN_JOURNAL_LIST = "useBuiltInJournalList"; // Protected terms private static final String PROTECTED_TERMS_ENABLED_EXTERNAL = "protectedTermsEnabledExternal"; @@ -1051,6 +1052,8 @@ public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { putStringList(EXTERNAL_JOURNAL_LISTS, journalAbbreviationPreferences.getExternalJournalLists())); EasyBind.listen(journalAbbreviationPreferences.useFJournalFieldProperty(), (_, _, newValue) -> putBoolean(USE_AMS_FJOURNAL, newValue)); + EasyBind.listen(journalAbbreviationPreferences.useBuiltInListProperty(), + (_, _, newValue) -> putBoolean(USE_BUILT_IN_JOURNAL_LIST, newValue)); return journalAbbreviationPreferences; } @@ -1058,7 +1061,8 @@ public JournalAbbreviationPreferences getJournalAbbreviationPreferences() { private JournalAbbreviationPreferences getJournalAbbreviationPreferencesFromBackingStore(JournalAbbreviationPreferences defaults) { return new JournalAbbreviationPreferences( convertStringToList(get(EXTERNAL_JOURNAL_LISTS, convertListToString(defaults.getExternalJournalLists()))), - getBoolean(USE_AMS_FJOURNAL, defaults.useFJournalFieldProperty().get())); + getBoolean(USE_AMS_FJOURNAL, defaults.useFJournalFieldProperty().get()), + getBoolean(USE_BUILT_IN_JOURNAL_LIST, defaults.useBuiltInListProperty().get())); } // endregion diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties index 697fd806c6e..678365185ed 100644 --- a/jablib/src/main/resources/l10n/JabRef_en.properties +++ b/jablib/src/main/resources/l10n/JabRef_en.properties @@ -2848,6 +2848,7 @@ A\ backup\ file\ for\ '%0'\ was\ found\ at\ [%1]=A backup file for '%0' was foun Do\ you\ want\ to\ recover\ the\ library\ from\ the\ backup\ file?=Do you want to recover the library from the backup file? This\ could\ indicate\ that\ JabRef\ did\ not\ shut\ down\ cleanly\ last\ time\ the\ file\ was\ used.=This could indicate that JabRef did not shut down cleanly last time the file was used. +Use\ JabRef\ built-in\ journal\ abbreviation\ list=Use JabRef built-in journal abbreviation list Use\ the\ field\ FJournal\ to\ store\ the\ full\ journal\ name\ for\ (un)abbreviations\ in\ the\ entry=Use the field FJournal to store the full journal name for (un)abbreviations in the entry Library\ to\ import\ into=Library to import into