Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more fields for save sort order and export sort order #10016

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- The formatter `remove_unicode_ligatures` is now called `replace_unicode_ligatures`. [#9890](https://github.com/JabRef/jabref/pull/9890)
- We improved the error message when no terminal was found [#9607](https://github.com/JabRef/jabref/issues/9607)
- In the context of the "systematic literature functionality", we changed the name "database" to "catalog" to use a separate term for online catalogs in comparison to SQL databases. [#9951](https://github.com/JabRef/jabref/pull/9951)
- We now show more fields (including Special Fields) in the dropdown selection for "Save sort order" in the library properties and for "Export sort order" in the preferences. [#10010](https://github.com/JabRef/jabref/issues/10010)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.jabref.gui.libraryproperties.saving;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
Expand Down Expand Up @@ -65,11 +64,15 @@ public void setValues() {
case TABLE -> saveInTableOrderProperty.setValue(true);
}

List<Field> fieldNames = new ArrayList<>(FieldFactory.getCommonFields());
fieldNames.add(InternalField.TYPE_HEADER); // allow entrytype field as sort criterion
fieldNames.sort(Comparator.comparing(Field::getDisplayName));
sortableFieldsProperty.clear();
sortableFieldsProperty.addAll(fieldNames);

Set<Field> fields = FieldFactory.getAllFieldsWithOutInternal();
fields.add(InternalField.INTERNAL_ALL_FIELD);
fields.add(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD);
fields.add(InternalField.KEY_FIELD);
fields.add(InternalField.TYPE_HEADER);

sortableFieldsProperty.addAll(FieldFactory.getStandardFieldsWithCitationKey());
sortCriteriaProperty.clear();
sortCriteriaProperty.addAll(exportSaveOrder.getSortCriteria().stream()
.map(SortCriterionViewModel::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public CustomEntryTypesTabViewModel(BibDatabaseMode mode,
ValidationMessage.error(Localization.lang("Entry type cannot be empty. Please enter a name.")));
fieldValidator = new FunctionBasedValidator<>(
newFieldToAdd,
input -> input != null && StringUtil.isNotBlank(input.getDisplayName()),
input -> (input != null) && StringUtil.isNotBlank(input.getDisplayName()),
ValidationMessage.error(Localization.lang("Field cannot be empty. Please enter a name.")));
}

@Override
public void setValues() {
if (!this.entryTypesWithFields.isEmpty()) {
this.entryTypesWithFields.clear();
Expand All @@ -97,6 +98,7 @@ public void setValues() {
}
}

@Override
public void storeSettings() {
Set<Field> multilineFields = new HashSet<>();
for (EntryTypeViewModel typeViewModel : entryTypesWithFields) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.jabref.gui.preferences.export;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
Expand All @@ -14,6 +13,7 @@
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.metadata.SaveOrder;
import org.jabref.preferences.ExportPreferences;

Expand Down Expand Up @@ -44,9 +44,12 @@ public void setValues() {
.map(SortCriterionViewModel::new)
.toList());

List<Field> fieldNames = new ArrayList<>(FieldFactory.getCommonFields());
fieldNames.sort(Comparator.comparing(Field::getDisplayName));
sortableFieldsProperty.addAll(fieldNames);
Set<Field> fields = FieldFactory.getAllFieldsWithOutInternal();
fields.add(InternalField.INTERNAL_ALL_FIELD);
fields.add(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD);
fields.add(InternalField.KEY_FIELD);
fields.add(InternalField.TYPE_HEADER);
sortableFieldsProperty.addAll(FieldFactory.getStandardFieldsWithCitationKey());
}

@Override
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/org/jabref/model/entry/field/FieldFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -133,7 +135,7 @@ public static Set<Field> getJournalNameFields() {
}

/**
* Returns a List with all standard fields and including some common internal fields
* Returns a Set with all standard fields and including some common internal fields
*/
public static Set<Field> getCommonFields() {
EnumSet<StandardField> allFields = EnumSet.allOf(StandardField.class);
Expand All @@ -147,6 +149,17 @@ public static Set<Field> getCommonFields() {
return publicAndInternalFields;
}

/**
* Returns a sorted Set of Fields (by {@link Field#getDisplayName} with all fields without internal ones
*/
public static Set<Field> getAllFieldsWithOutInternal() {
Set<Field> fields = new TreeSet<>(Comparator.comparing(Field::getDisplayName));
fields.addAll(getAllFields());
fields.removeAll(EnumSet.allOf(InternalField.class));

return fields;
}

/**
* Returns a List with all standard fields and the citation key field
*/
Expand Down