Skip to content

Commit

Permalink
Fix storing of custom jstyles (#6242)
Browse files Browse the repository at this point in the history
* Fix storing of custom jstyles


Fixes #6170
Rename method for internalStyle

* fix empty lines
Reorder filter
  • Loading branch information
Siedlerchr authored Apr 5, 2020
1 parent efc69be commit d223bdd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -94,9 +94,7 @@ public void deleteStyle() {

public void editStyle() {
OOBibStyle style = selectedItem.getValue().getStyle();

Optional<ExternalFileType> type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("jstyle");

try {
JabRefDesktop.openExternalFileAnyFormat(new BibDatabaseContext(), style.getPath(), type);
} catch (IOException e) {
Expand All @@ -105,7 +103,6 @@ public void editStyle() {
}

public void viewStyle(StyleSelectItemViewModel item) {

DialogPane pane = new DialogPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToHeight(true);
Expand All @@ -121,6 +118,8 @@ public ObjectProperty<StyleSelectItemViewModel> selectedItemProperty() {
}

public void storePrefs() {
List<String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static List<String> generateCitations(List<BibEntry> 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);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/openoffice/OOBibStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class OOBibStyle implements Comparable<OOBibStyle> {
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);
Expand Down Expand Up @@ -842,7 +843,7 @@ public Object getProperty(String propName) {
*
* @return True if an internal style
*/
public boolean isFromResource() {
public boolean isInternalStyle() {
return fromResource;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jabref/logic/openoffice/StyleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class StyleLoader {
private final List<OOBibStyle> internalStyles = new ArrayList<>();
private final List<OOBibStyle> externalStyles = new ArrayList<>();


public StyleLoader(OpenOfficePreferences preferences, LayoutFormatterPreferences jabrefPreferences,
Charset encoding) {
this.preferences = Objects.requireNonNull(preferences);
Expand Down Expand Up @@ -75,7 +74,6 @@ public boolean addStyleIfValid(String filename) {
LOGGER.info("Problem reading external style file " + filename, e);
}
return false;

}

private void loadExternalStyles() {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/logic/openoffice/OOBibStyleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testInitalizeWithOneExternalFileRemoveStyle() throws URISyntaxExcept
List<OOBibStyle> toremove = new ArrayList<>();
int beforeRemoving = loader.getStyles().size();
for (OOBibStyle style : loader.getStyles()) {
if (!style.isFromResource()) {
if (!style.isInternalStyle()) {
toremove.add(style);
}
}
Expand All @@ -127,7 +127,7 @@ public void testInitalizeWithOneExternalFileRemoveStyleUpdatesPreferences() thro
loader = new StyleLoader(preferences, layoutPreferences, encoding);
List<OOBibStyle> toremove = new ArrayList<>();
for (OOBibStyle style : loader.getStyles()) {
if (!style.isFromResource()) {
if (!style.isInternalStyle()) {
toremove.add(style);
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testRemoveInternalStyleReturnsFalseAndDoNotRemove() {
loader = new StyleLoader(preferences, layoutPreferences, encoding);
List<OOBibStyle> toremove = new ArrayList<>();
for (OOBibStyle style : loader.getStyles()) {
if (style.isFromResource()) {
if (style.isInternalStyle()) {
toremove.add(style);
}
}
Expand Down

0 comments on commit d223bdd

Please sign in to comment.