diff --git a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationsFileViewModel.java b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationsFileViewModel.java index 88ecb96d240..b22dd902d95 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/AbbreviationsFileViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/journals/AbbreviationsFileViewModel.java @@ -18,6 +18,7 @@ import org.jabref.logic.journals.Abbreviation; import org.jabref.logic.journals.AbbreviationWriter; import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.logic.journals.JournalAbbreviationMvGenerator; /** * This class provides a model for abbreviation files. It actually doesn't save the files as objects but rather saves @@ -57,6 +58,31 @@ public void readAbbreviations() throws IOException { throw new FileNotFoundException(); } } + /** + * Reads journal abbreviations from the specified MV file and populates the abbreviations list. + *

+ * If a valid file path is provided, this method loads abbreviations using + * {@link JournalAbbreviationMvGenerator#loadAbbreviationsFromMv(Path)} and converts them + * into {@link AbbreviationViewModel} objects before adding them to the abbreviations list. + *

+ * + * @throws IOException if the MV file cannot be found or read. + * @throws FileNotFoundException if no MV file path is specified. + */ + + public void readAbbreviationsFromMv() throws IOException { + if (path.isPresent()) { + // Load abbreviations from the MV file using MV processor. + Collection abbreviationList = JournalAbbreviationMvGenerator.loadAbbreviationsFromMv(path.get()); + + // Convert each Abbreviation into an AbbreviationViewModel and add it to the abbreviations list. + for (Abbreviation abbreviation : abbreviationList) { + abbreviations.add(new AbbreviationViewModel(abbreviation)); + } + } else { + throw new FileNotFoundException("MV file not specified"); + } + } /** * This method will write all abbreviations of this abbreviation file to the file on the file system. @@ -64,7 +90,7 @@ public void readAbbreviations() throws IOException { * {@link AbbreviationWriter#writeOrCreate}. */ public void writeOrCreate() throws IOException { - if (!isBuiltInList.get()) { + if (!isBuiltInList.get() && !isMvFile()) { List actualAbbreviations = abbreviations.stream().filter(abb -> !abb.isPseudoAbbreviation()) .map(AbbreviationViewModel::getAbbreviationObject) @@ -107,4 +133,8 @@ public boolean equals(Object obj) { return false; } } + + public boolean isMvFile() { + return path.isPresent() && path.get().toString().endsWith(".mv"); + } } diff --git a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml index f909ee6a3d6..602241ce7eb 100644 --- a/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/journals/JournalAbbreviationsTab.fxml @@ -49,6 +49,11 @@ + +