diff --git a/CHANGELOG.md b/CHANGELOG.md index 309becc5f96..3c49eaed2b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue with inconsistent capitalization of file extensions when downloading files [#6115](https://github.com/JabRef/jabref/issues/6115) - We fixed the display of language and encoding in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130) - We fixed an issue where search full-text documents downloaded files with same name, overwriting existing files. [#6174](https://github.com/JabRef/jabref/pull/6174) +- We fixe an issue where custom jstyles for Open/LibreOffice where not saved correctly [#6170](https://github.com/JabRef/jabref/issues/6170) + ### Removed diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java index e318671c6e1..e08c599f348 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java @@ -51,7 +51,7 @@ public StyleSelectDialogViewModel(DialogService dialogService, StyleLoader loade } public StyleSelectItemViewModel fromOOBibStyle(OOBibStyle style) { - return new StyleSelectItemViewModel(style.getName(), String.join(", ", style.getJournals()), style.isFromResource() ? Localization.lang("Internal style") : style.getPath(), style); + return new StyleSelectItemViewModel(style.getName(), String.join(", ", style.getJournals()), style.isInternalStyle() ? Localization.lang("Internal style") : style.getPath(), style); } public OOBibStyle toOOBibStyle(StyleSelectItemViewModel item) { @@ -94,9 +94,7 @@ public void deleteStyle() { public void editStyle() { OOBibStyle style = selectedItem.getValue().getStyle(); - Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("jstyle"); - try { JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), style.getPath(), type); } catch (IOException e) { @@ -105,7 +103,6 @@ public void editStyle() { } public void viewStyle(StyleSelectItemViewModel item) { - DialogPane pane = new DialogPane(); ScrollPane scrollPane = new ScrollPane(); scrollPane.setFitToHeight(true); @@ -121,6 +118,8 @@ public ObjectProperty selectedItemProperty() { } public void storePrefs() { + List externalStyles = styles.stream().map(this::toOOBibStyle).filter(style->!style.isInternalStyle()).map(OOBibStyle::getPath).collect(Collectors.toList()); + preferences.setExternalStyles(externalStyles); preferences.setCurrentStyle(selectedItem.getValue().getStylePath()); preferencesService.setOpenOfficePreferences(preferences); } diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectItemViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectItemViewModel.java index 4f5dc9216d9..72890122d4f 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectItemViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectItemViewModel.java @@ -25,7 +25,7 @@ public StyleSelectItemViewModel(String name, String journals, String file, OOBib this.journals.setValue(journals); this.file.setValue(file); this.style = style; - this.internalStyle.set(style.isFromResource()); + this.internalStyle.set(style.isInternalStyle()); } public StringProperty nameProperty() { diff --git a/src/main/java/org/jabref/logic/citationstyle/CitationStyleGenerator.java b/src/main/java/org/jabref/logic/citationstyle/CitationStyleGenerator.java index 28a2e6f867e..d1baaff83dc 100644 --- a/src/main/java/org/jabref/logic/citationstyle/CitationStyleGenerator.java +++ b/src/main/java/org/jabref/logic/citationstyle/CitationStyleGenerator.java @@ -55,7 +55,7 @@ public static List generateCitations(List bibEntries, String s try { return CSL_ADAPTER.makeBibliography(bibEntries, style, outputFormat); } catch (IllegalArgumentException ignored) { - LOGGER.error("Could not generate BibEntry citation. The CSL engine could not create a preview for your item."); + LOGGER.error("Could not generate BibEntry citation. The CSL engine could not create a preview for your item.", ignored); return Collections.singletonList(Localization.lang("Cannot generate preview based on selected citation style.")); } catch (IOException | ArrayIndexOutOfBoundsException e) { LOGGER.error("Could not generate BibEntry citation", e); diff --git a/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java b/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java index b63eaf94056..0205c9113b3 100644 --- a/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java +++ b/src/main/java/org/jabref/logic/openoffice/OOBibStyle.java @@ -123,6 +123,7 @@ public class OOBibStyle implements Comparable { private long styleFileModificationTime = Long.MIN_VALUE; private String localCopy; private boolean isDefaultLayoutPresent; + public OOBibStyle(File styleFile, LayoutFormatterPreferences prefs, Charset encoding) throws IOException { this.prefs = Objects.requireNonNull(prefs); @@ -842,7 +843,7 @@ public Object getProperty(String propName) { * * @return True if an internal style */ - public boolean isFromResource() { + public boolean isInternalStyle() { return fromResource; } diff --git a/src/main/java/org/jabref/logic/openoffice/StyleLoader.java b/src/main/java/org/jabref/logic/openoffice/StyleLoader.java index e58252c63ea..b6e367a38f6 100644 --- a/src/main/java/org/jabref/logic/openoffice/StyleLoader.java +++ b/src/main/java/org/jabref/logic/openoffice/StyleLoader.java @@ -34,7 +34,6 @@ public class StyleLoader { private final List internalStyles = new ArrayList<>(); private final List externalStyles = new ArrayList<>(); - public StyleLoader(OpenOfficePreferences preferences, LayoutFormatterPreferences jabrefPreferences, Charset encoding) { this.preferences = Objects.requireNonNull(preferences); @@ -75,7 +74,6 @@ public boolean addStyleIfValid(String filename) { LOGGER.info("Problem reading external style file " + filename, e); } return false; - } private void loadExternalStyles() { @@ -120,7 +118,7 @@ private void storeExternalStyles() { public boolean removeStyle(OOBibStyle style) { Objects.requireNonNull(style); - if (!style.isFromResource()) { + if (!style.isInternalStyle()) { boolean result = externalStyles.remove(style); storeExternalStyles(); return result; diff --git a/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java b/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java index d62fac43651..3e48db6b56b 100644 --- a/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java +++ b/src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java @@ -43,7 +43,7 @@ void setUp() { void testAuthorYear() throws IOException { OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, layoutFormatterPreferences); assertTrue(style.isValid()); - assertTrue(style.isFromResource()); + assertTrue(style.isInternalStyle()); assertFalse(style.isBibtexKeyCiteMarkers()); assertFalse(style.isBoldCitations()); assertFalse(style.isFormatCitations()); @@ -58,7 +58,7 @@ void testAuthorYearAsFile() throws URISyntaxException, IOException { .toFile(); OOBibStyle style = new OOBibStyle(defFile, layoutFormatterPreferences, StandardCharsets.UTF_8); assertTrue(style.isValid()); - assertFalse(style.isFromResource()); + assertFalse(style.isInternalStyle()); assertFalse(style.isBibtexKeyCiteMarkers()); assertFalse(style.isBoldCitations()); assertFalse(style.isFormatCitations()); diff --git a/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java b/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java index 3765fd37f39..5ac0ec152a9 100644 --- a/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java +++ b/src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java @@ -107,7 +107,7 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept List toremove = new ArrayList<>(); int beforeRemoving = loader.getStyles().size(); for (OOBibStyle style : loader.getStyles()) { - if (!style.isFromResource()) { + if (!style.isInternalStyle()) { toremove.add(style); } } @@ -127,7 +127,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro loader = new StyleLoader(preferences, layoutPreferences, encoding); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { - if (!style.isFromResource()) { + if (!style.isInternalStyle()) { toremove.add(style); } } @@ -194,7 +194,7 @@ public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() { loader = new StyleLoader(preferences, layoutPreferences, encoding); List toremove = new ArrayList<>(); for (OOBibStyle style : loader.getStyles()) { - if (style.isFromResource()) { + if (style.isInternalStyle()) { toremove.add(style); } }