Skip to content

Commit

Permalink
Merge pull request #10343 from papatekken/fix-10157
Browse files Browse the repository at this point in the history
Fix the exception when export saving order is less than 3 in export tab of preferences.
  • Loading branch information
Siedlerchr authored Sep 10, 2023
2 parents ed543e9 + 5df0f55 commit 0cf4acc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- Passwords can be stored in GNOME key ring. [#10274](https://github.com/JabRef/jabref/issues/10274)
- We fixed an issue where groups based on an aux file could not be created due to an exception [#10350](https://github.com/JabRef/jabref/issues/10350)
- We fixed an issue where the JabRef browser extension could not communicate with JabRef under macOS due to missing files. You should use the `.pkg` for the first installation as it updates all necessary files for the extension [#10308](https://github.com/JabRef/jabref/issues/10308)
- We fixed a bug where an exception was raised when saving less than three export save orders in the preference. [#10157](https://github.com/JabRef/jabref/issues/10157)

### Removed

Expand Down
44 changes: 33 additions & 11 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -2237,11 +2237,17 @@ public ExportPreferences getExportPreferences() {
}

private SaveOrder getExportSaveOrder() {
List<SaveOrder.SortCriterion> sortCriteria = List.of(
new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_PRIMARY_SORT_FIELD)), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING)),
new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_SECONDARY_SORT_FIELD)), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING)),
new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_TERTIARY_SORT_FIELD)), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING))
);
List<SaveOrder.SortCriterion> sortCriteria = new ArrayList<>();

if (!"".equals(get(EXPORT_PRIMARY_SORT_FIELD))) {
sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_PRIMARY_SORT_FIELD)), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING)));
}
if (!"".equals(get(EXPORT_SECONDARY_SORT_FIELD))) {
sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_SECONDARY_SORT_FIELD)), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING)));
}
if (!"".equals(get(EXPORT_TERTIARY_SORT_FIELD))) {
sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_TERTIARY_SORT_FIELD)), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING)));
}

return new SaveOrder(
SaveOrder.OrderType.fromBooleans(getBoolean(EXPORT_IN_SPECIFIED_ORDER), getBoolean(EXPORT_IN_ORIGINAL_ORDER)),
Expand All @@ -2253,12 +2259,28 @@ private void storeExportSaveOrder(SaveOrder saveOrder) {
putBoolean(EXPORT_IN_ORIGINAL_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.ORIGINAL);
putBoolean(EXPORT_IN_SPECIFIED_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.SPECIFIED);

put(EXPORT_PRIMARY_SORT_FIELD, saveOrder.getSortCriteria().get(0).field.getName());
put(EXPORT_SECONDARY_SORT_FIELD, saveOrder.getSortCriteria().get(1).field.getName());
put(EXPORT_TERTIARY_SORT_FIELD, saveOrder.getSortCriteria().get(2).field.getName());
putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(0).descending);
putBoolean(EXPORT_SECONDARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(1).descending);
putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(2).descending);
long saveOrderCount = saveOrder.getSortCriteria().size();
if (saveOrderCount >= 1) {
put(EXPORT_PRIMARY_SORT_FIELD, saveOrder.getSortCriteria().get(0).field.getName());
putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(0).descending);
} else {
put(EXPORT_PRIMARY_SORT_FIELD, "");
putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, false);
}
if (saveOrderCount >= 2) {
put(EXPORT_SECONDARY_SORT_FIELD, saveOrder.getSortCriteria().get(1).field.getName());
putBoolean(EXPORT_SECONDARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(1).descending);
} else {
put(EXPORT_SECONDARY_SORT_FIELD, "");
putBoolean(EXPORT_SECONDARY_SORT_DESCENDING, false);
}
if (saveOrderCount >= 3) {
put(EXPORT_TERTIARY_SORT_FIELD, saveOrder.getSortCriteria().get(2).field.getName());
putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(2).descending);
} else {
put(EXPORT_TERTIARY_SORT_FIELD, "");
putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, false);
}
}

/**
Expand Down

0 comments on commit 0cf4acc

Please sign in to comment.