Skip to content

Commit dc9036c

Browse files
committed
Fix storing of custom jstyles
Fixes #6170 Rename method for internalStyle
1 parent 5cef762 commit dc9036c

File tree

8 files changed

+17
-10
lines changed

8 files changed

+17
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
3131
- We fixed an issue with inconsistent capitalization of file extensions when downloading files [#6115](https://github.com/JabRef/jabref/issues/6115)
3232
- We fixed the display of language and encoding in the preferences dialog. [#6130](https://github.com/JabRef/jabref/pull/6130)
3333
- 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)
34+
- We fixe an issue where custom jstyles for Open/LibreOffice where not saved correctly [#6170](https://github.com/JabRef/jabref/issues/6170)
35+
3436

3537
### Removed
3638

src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public StyleSelectDialogViewModel(DialogService dialogService, StyleLoader loade
5151
}
5252

5353
public StyleSelectItemViewModel fromOOBibStyle(OOBibStyle style) {
54-
return new StyleSelectItemViewModel(style.getName(), String.join(", ", style.getJournals()), style.isFromResource() ? Localization.lang("Internal style") : style.getPath(), style);
54+
return new StyleSelectItemViewModel(style.getName(), String.join(", ", style.getJournals()), style.isInternalStyle() ? Localization.lang("Internal style") : style.getPath(), style);
5555
}
5656

5757
public OOBibStyle toOOBibStyle(StyleSelectItemViewModel item) {
@@ -121,6 +121,9 @@ public ObjectProperty<StyleSelectItemViewModel> selectedItemProperty() {
121121
}
122122

123123
public void storePrefs() {
124+
125+
List<String> externalStyles = styles.stream().filter(style -> !style.internalStyleProperty().get()).map(this::toOOBibStyle).map(OOBibStyle::getPath).collect(Collectors.toList());
126+
preferences.setExternalStyles(externalStyles);
124127
preferences.setCurrentStyle(selectedItem.getValue().getStylePath());
125128
preferencesService.setOpenOfficePreferences(preferences);
126129
}

src/main/java/org/jabref/gui/openoffice/StyleSelectItemViewModel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public StyleSelectItemViewModel(String name, String journals, String file, OOBib
2525
this.journals.setValue(journals);
2626
this.file.setValue(file);
2727
this.style = style;
28-
this.internalStyle.set(style.isFromResource());
28+
this.internalStyle.set(style.isInternalStyle());
2929
}
3030

3131
public StringProperty nameProperty() {

src/main/java/org/jabref/logic/citationstyle/CitationStyleGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static List<String> generateCitations(List<BibEntry> bibEntries, String s
5555
try {
5656
return CSL_ADAPTER.makeBibliography(bibEntries, style, outputFormat);
5757
} catch (IllegalArgumentException ignored) {
58-
LOGGER.error("Could not generate BibEntry citation. The CSL engine could not create a preview for your item.");
58+
LOGGER.error("Could not generate BibEntry citation. The CSL engine could not create a preview for your item.", ignored);
5959
return Collections.singletonList(Localization.lang("Cannot generate preview based on selected citation style."));
6060
} catch (IOException | ArrayIndexOutOfBoundsException e) {
6161
LOGGER.error("Could not generate BibEntry citation", e);

src/main/java/org/jabref/logic/openoffice/OOBibStyle.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public class OOBibStyle implements Comparable<OOBibStyle> {
123123
private long styleFileModificationTime = Long.MIN_VALUE;
124124
private String localCopy;
125125
private boolean isDefaultLayoutPresent;
126+
126127
public OOBibStyle(File styleFile, LayoutFormatterPreferences prefs,
127128
Charset encoding) throws IOException {
128129
this.prefs = Objects.requireNonNull(prefs);
@@ -842,7 +843,7 @@ public Object getProperty(String propName) {
842843
*
843844
* @return True if an internal style
844845
*/
845-
public boolean isFromResource() {
846+
public boolean isInternalStyle() {
846847
return fromResource;
847848
}
848849

src/main/java/org/jabref/logic/openoffice/StyleLoader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public StyleLoader(OpenOfficePreferences preferences, LayoutFormatterPreferences
4444
loadExternalStyles();
4545
}
4646

47+
4748
public List<OOBibStyle> getStyles() {
4849
List<OOBibStyle> result = new ArrayList<>(internalStyles);
4950
result.addAll(externalStyles);
@@ -120,7 +121,7 @@ private void storeExternalStyles() {
120121

121122
public boolean removeStyle(OOBibStyle style) {
122123
Objects.requireNonNull(style);
123-
if (!style.isFromResource()) {
124+
if (!style.isInternalStyle()) {
124125
boolean result = externalStyles.remove(style);
125126
storeExternalStyles();
126127
return result;

src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void setUp() {
4343
void testAuthorYear() throws IOException {
4444
OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_AUTHORYEAR_STYLE_PATH, layoutFormatterPreferences);
4545
assertTrue(style.isValid());
46-
assertTrue(style.isFromResource());
46+
assertTrue(style.isInternalStyle());
4747
assertFalse(style.isBibtexKeyCiteMarkers());
4848
assertFalse(style.isBoldCitations());
4949
assertFalse(style.isFormatCitations());
@@ -58,7 +58,7 @@ void testAuthorYearAsFile() throws URISyntaxException, IOException {
5858
.toFile();
5959
OOBibStyle style = new OOBibStyle(defFile, layoutFormatterPreferences, StandardCharsets.UTF_8);
6060
assertTrue(style.isValid());
61-
assertFalse(style.isFromResource());
61+
assertFalse(style.isInternalStyle());
6262
assertFalse(style.isBibtexKeyCiteMarkers());
6363
assertFalse(style.isBoldCitations());
6464
assertFalse(style.isFormatCitations());

src/test/java/org/jabref/logic/openoffice/StyleLoaderTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept
107107
List<OOBibStyle> toremove = new ArrayList<>();
108108
int beforeRemoving = loader.getStyles().size();
109109
for (OOBibStyle style : loader.getStyles()) {
110-
if (!style.isFromResource()) {
110+
if (!style.isInternalStyle()) {
111111
toremove.add(style);
112112
}
113113
}
@@ -127,7 +127,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro
127127
loader = new StyleLoader(preferences, layoutPreferences, encoding);
128128
List<OOBibStyle> toremove = new ArrayList<>();
129129
for (OOBibStyle style : loader.getStyles()) {
130-
if (!style.isFromResource()) {
130+
if (!style.isInternalStyle()) {
131131
toremove.add(style);
132132
}
133133
}
@@ -194,7 +194,7 @@ public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() {
194194
loader = new StyleLoader(preferences, layoutPreferences, encoding);
195195
List<OOBibStyle> toremove = new ArrayList<>();
196196
for (OOBibStyle style : loader.getStyles()) {
197-
if (style.isFromResource()) {
197+
if (style.isInternalStyle()) {
198198
toremove.add(style);
199199
}
200200
}

0 commit comments

Comments
 (0)