diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java index ded9dd93b79..e318671c6e1 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java @@ -47,13 +47,7 @@ public StyleSelectDialogViewModel(DialogService dialogService, StyleLoader loade styles.addAll(loadStyles()); String currentStyle = preferences.getCurrentStyle(); - Optional 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) { @@ -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.")); } @@ -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)); + } }