Skip to content

Commit

Permalink
Select newly added jstyle in table to prevent exception (#5556)
Browse files Browse the repository at this point in the history
Fixes #5452
  • Loading branch information
Siedlerchr authored and tobiasdiez committed Nov 3, 2019
1 parent ca2953d commit f2e5bf2
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ public StyleSelectDialogViewModel(DialogService dialogService, StyleLoader loade
styles.addAll(loadStyles());

String currentStyle = preferences.getCurrentStyle();
Optional<StyleSelectItemViewModel> lastUsedStyle = styles.stream().filter(style -> style.getStylePath().equals(currentStyle)).findFirst();

if (lastUsedStyle.isPresent()) {
selectedItem.setValue(lastUsedStyle.get());
} else {
selectedItem.setValue(styles.get(0));
}
selectedItem.setValue(getStyleOrDefault(currentStyle));
}

public StyleSelectItemViewModel fromOOBibStyle(OOBibStyle style) {
Expand All @@ -75,6 +69,7 @@ public void addStyleFile() {
if (loader.addStyleIfValid(stylePath)) {
preferences.setCurrentStyle(stylePath);
styles.setAll(loadStyles());
selectedItem.setValue(getStyleOrDefault(stylePath));
} else {
dialogService.showErrorDialogAndWait(Localization.lang("Invalid style selected"), Localization.lang("You must select a valid style file."));
}
Expand Down Expand Up @@ -129,4 +124,8 @@ public void storePrefs() {
preferences.setCurrentStyle(selectedItem.getValue().getStylePath());
preferencesService.setOpenOfficePreferences(preferences);
}

private StyleSelectItemViewModel getStyleOrDefault(String stylePath) {
return styles.stream().filter(style -> style.getStylePath().equals(stylePath)).findFirst().orElse(styles.get(0));
}
}

0 comments on commit f2e5bf2

Please sign in to comment.