Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if styles is empty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styles can never be empty because we have two internal default styles that are always available.

}
}