diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a89efc32a..e52aaab4a26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv ### Added +- We added a table for naming linked files in the Linked Files tab in Preferences. [#11368](https://github.com/JabRef/jabref/issues/11368) - We added a new Welcome tab which shows a welcome screen if no database is open. [#12272](https://github.com/JabRef/jabref/issues/12272) - We added F5 as a shortcut key for fetching data and Alt+F as a shortcut for looking up data using DOI. [#11802](https://github.com/JabRef/jabref/issues/11802) - We added a feature to rename the subgroup, with the keybinding (F2) for quick access. [#11896](https://github.com/JabRef/jabref/issues/11896) diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java index 2b044661236..1c866cac305 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanel.java @@ -15,7 +15,7 @@ import org.jabref.gui.icon.IconTheme; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.logic.citationkeypattern.AbstractCitationKeyPatterns; -import org.jabref.logic.citationkeypattern.CitationKeyPattern; +import org.jabref.logic.citationkeypattern.KeyPattern; import org.jabref.logic.l10n.Localization; import org.jabref.logic.preferences.CliPreferences; import org.jabref.model.entry.BibEntryType; @@ -24,11 +24,11 @@ import com.airhacks.afterburner.views.ViewLoader; import jakarta.inject.Inject; -public class CitationKeyPatternsPanel extends TableView { +public class CitationKeyPatternsPanel extends TableView { - @FXML public TableColumn entryTypeColumn; - @FXML public TableColumn patternColumn; - @FXML public TableColumn actionsColumn; + @FXML public TableColumn entryTypeColumn; + @FXML public TableColumn patternColumn; + @FXML public TableColumn actionsColumn; @Inject private CliPreferences preferences; @@ -41,9 +41,9 @@ public class CitationKeyPatternsPanel extends TableView cellData.getValue().entryType()); - new ValueTableCellFactory() + new ValueTableCellFactory() .withText(EntryType::getDisplayName) .install(entryTypeColumn); this.setOnSort(event -> @@ -69,16 +69,16 @@ private void initialize() { patternColumn.setSortable(true); patternColumn.setReorderable(false); patternColumn.setCellValueFactory(cellData -> cellData.getValue().pattern()); - patternColumn.setCellFactory(_ -> new CitationKeyPatternSuggestionCell(patterns)); + patternColumn.setCellFactory(_ -> new PatternSuggestionCell(patterns)); patternColumn.setEditable(true); patternColumn.setOnEditCommit( - (TableColumn.CellEditEvent event) -> + (TableColumn.CellEditEvent event) -> event.getRowValue().setPattern(event.getNewValue())); actionsColumn.setSortable(false); actionsColumn.setReorderable(false); actionsColumn.setCellValueFactory(cellData -> cellData.getValue().entryType()); - new ValueTableCellFactory() + new ValueTableCellFactory() .withGraphic(entryType -> IconTheme.JabRefIcons.REFRESH.getGraphicNode()) .withTooltip(entryType -> Localization.lang("Reset %s to default value").formatted(entryType.getDisplayName())) @@ -99,11 +99,11 @@ public void resetAll() { viewModel.resetAll(); } - public ListProperty patternListProperty() { + public ListProperty patternListProperty() { return viewModel.patternListProperty(); } - public ObjectProperty defaultKeyPatternProperty() { + public ObjectProperty defaultKeyPatternProperty() { return viewModel.defaultKeyPatternProperty(); } @@ -124,9 +124,9 @@ private void jumpToSearchKey(KeyEvent keypressed) { .findFirst().ifPresent(this::scrollTo); } - private static class HighlightTableRow extends TableRow { + private static class HighlightTableRow extends TableRow { @Override - public void updateItem(CitationKeyPatternsPanelItemModel item, boolean empty) { + public void updateItem(PatternsItemModel item, boolean empty) { super.updateItem(item, empty); if (item == null || item.getEntryType() == null) { setStyle(""); diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelViewModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelViewModel.java index 78df89b5ba7..cee0ddb3de4 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelViewModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelViewModel.java @@ -10,8 +10,8 @@ import javafx.collections.FXCollections; import org.jabref.logic.citationkeypattern.AbstractCitationKeyPatterns; -import org.jabref.logic.citationkeypattern.CitationKeyPattern; import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; +import org.jabref.logic.citationkeypattern.KeyPattern; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntryType; import org.jabref.model.entry.types.EntryType; @@ -20,7 +20,7 @@ public class CitationKeyPatternsPanelViewModel { public static final String ENTRY_TYPE_DEFAULT_NAME = "default"; - public static Comparator defaultOnTopComparator = (o1, o2) -> { + public static Comparator defaultOnTopComparator = (o1, o2) -> { String itemOneName = o1.getEntryType().getName(); String itemTwoName = o2.getEntryType().getName(); @@ -35,8 +35,8 @@ public class CitationKeyPatternsPanelViewModel { return 0; }; - private final ListProperty patternListProperty = new SimpleListProperty<>(); - private final ObjectProperty defaultItemProperty = new SimpleObjectProperty<>(); + private final ListProperty patternListProperty = new SimpleListProperty<>(); + private final ObjectProperty defaultItemProperty = new SimpleObjectProperty<>(); private final CitationKeyPatternPreferences keyPatternPreferences; @@ -46,13 +46,13 @@ public CitationKeyPatternsPanelViewModel(CitationKeyPatternPreferences keyPatter public void setValues(Collection entryTypeList, AbstractCitationKeyPatterns initialKeyPattern) { String defaultPattern; - if ((initialKeyPattern.getDefaultValue() == null) || initialKeyPattern.getDefaultValue().equals(CitationKeyPattern.NULL_CITATION_KEY_PATTERN)) { + if ((initialKeyPattern.getDefaultValue() == null) || initialKeyPattern.getDefaultValue().equals(KeyPattern.NULL_PATTERN)) { defaultPattern = ""; } else { defaultPattern = initialKeyPattern.getDefaultValue().stringRepresentation(); } - defaultItemProperty.setValue(new CitationKeyPatternsPanelItemModel(new DefaultEntryType(), defaultPattern)); + defaultItemProperty.setValue(new PatternsItemModel(new DefaultEntryType(), defaultPattern)); patternListProperty.setValue(FXCollections.observableArrayList()); patternListProperty.add(defaultItemProperty.getValue()); @@ -65,11 +65,11 @@ public void setValues(Collection entryTypeList, AbstractCitationKe } else { pattern = initialKeyPattern.getPatterns().get(entryType).stringRepresentation(); } - patternListProperty.add(new CitationKeyPatternsPanelItemModel(entryType, pattern)); + patternListProperty.add(new PatternsItemModel(entryType, pattern)); }); } - public void setItemToDefaultPattern(CitationKeyPatternsPanelItemModel item) { + public void setItemToDefaultPattern(PatternsItemModel item) { item.setPattern(keyPatternPreferences.getDefaultPattern()); } @@ -78,11 +78,11 @@ public void resetAll() { defaultItemProperty.getValue().setPattern(keyPatternPreferences.getDefaultPattern()); } - public ListProperty patternListProperty() { + public ListProperty patternListProperty() { return patternListProperty; } - public ObjectProperty defaultKeyPatternProperty() { + public ObjectProperty defaultKeyPatternProperty() { return defaultItemProperty; } diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternSuggestionCell.java b/src/main/java/org/jabref/gui/commonfxcontrols/PatternSuggestionCell.java similarity index 80% rename from src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternSuggestionCell.java rename to src/main/java/org/jabref/gui/commonfxcontrols/PatternSuggestionCell.java index f8f2958b272..f9ef8c34a91 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternSuggestionCell.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/PatternSuggestionCell.java @@ -16,13 +16,13 @@ import javafx.scene.control.cell.TextFieldTableCell; import javafx.stage.Window; -import org.jabref.logic.citationkeypattern.CitationKeyPattern; +import org.jabref.logic.citationkeypattern.KeyPattern; import org.jabref.logic.l10n.Localization; -public class CitationKeyPatternSuggestionCell extends TextFieldTableCell { +public class PatternSuggestionCell extends TextFieldTableCell { private final CitationKeyPatternSuggestionTextField searchField; - public CitationKeyPatternSuggestionCell(List citationKeyPatterns) { + public PatternSuggestionCell(List citationKeyPatterns) { this.searchField = new CitationKeyPatternSuggestionTextField(citationKeyPatterns); searchField.setOnAction(event -> commitEdit(searchField.getText())); } @@ -145,10 +145,6 @@ public static double getAvailableSpaceBelow(TextField textField) { } Window window = textField.getScene().getWindow(); - if (window == null) { - return 0; - } - Bounds bounds = textField.localToScreen(textField.getBoundsInLocal()); double screenHeight = window.getHeight(); double textFieldBottom = bounds.getMinY() + textField.getHeight(); @@ -159,26 +155,26 @@ public static double getAvailableSpaceBelow(TextField textField) { private Menu createPatternsSubMenu() { Menu patternsSubMenu = new Menu(Localization.lang("All patterns")); - Map> categorizedPatterns = - CitationKeyPattern.getAllPatterns().stream() - .collect(Collectors.groupingBy(CitationKeyPattern::getCategory)); + Map> categorizedPatterns = + KeyPattern.getAllPatterns().stream() + .collect(Collectors.groupingBy(KeyPattern::getCategory)); - Map categoryNames = Map.of( - CitationKeyPattern.Category.AUTHOR_RELATED, Localization.lang("Author related"), - CitationKeyPattern.Category.EDITOR_RELATED, Localization.lang("Editor related"), - CitationKeyPattern.Category.TITLE_RELATED, Localization.lang("Title related"), - CitationKeyPattern.Category.OTHER_FIELDS, Localization.lang("Other fields"), - CitationKeyPattern.Category.BIBENTRY_FIELDS, Localization.lang("Entry fields") + Map categoryNames = Map.of( + KeyPattern.Category.AUTHOR_RELATED, Localization.lang("Author related"), + KeyPattern.Category.EDITOR_RELATED, Localization.lang("Editor related"), + KeyPattern.Category.TITLE_RELATED, Localization.lang("Title related"), + KeyPattern.Category.OTHER_FIELDS, Localization.lang("Other fields"), + KeyPattern.Category.BIBENTRY_FIELDS, Localization.lang("Entry fields") ); - for (Map.Entry entry : categoryNames.entrySet()) { - CitationKeyPattern.Category category = entry.getKey(); + for (Map.Entry entry : categoryNames.entrySet()) { + KeyPattern.Category category = entry.getKey(); String categoryName = entry.getValue(); Menu categoryMenu = new Menu(categoryName); - List patterns = categorizedPatterns.getOrDefault(category, List.of()); + List patterns = categorizedPatterns.getOrDefault(category, List.of()); - for (CitationKeyPattern pattern : patterns) { + for (KeyPattern pattern : patterns) { MenuItem menuItem = new MenuItem(pattern.stringRepresentation()); menuItem.setOnAction(event -> { setText(pattern.stringRepresentation()); diff --git a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelItemModel.java b/src/main/java/org/jabref/gui/commonfxcontrols/PatternsItemModel.java similarity index 89% rename from src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelItemModel.java rename to src/main/java/org/jabref/gui/commonfxcontrols/PatternsItemModel.java index 86cd170d4ea..65f660d7373 100644 --- a/src/main/java/org/jabref/gui/commonfxcontrols/CitationKeyPatternsPanelItemModel.java +++ b/src/main/java/org/jabref/gui/commonfxcontrols/PatternsItemModel.java @@ -9,11 +9,11 @@ import org.jabref.model.entry.types.EntryType; -public class CitationKeyPatternsPanelItemModel { +public class PatternsItemModel { private final ObjectProperty entryType = new SimpleObjectProperty<>(); private final StringProperty pattern = new SimpleStringProperty(""); - public CitationKeyPatternsPanelItemModel(EntryType entryType, String pattern) { + public PatternsItemModel(EntryType entryType, String pattern) { Objects.requireNonNull(entryType); Objects.requireNonNull(pattern); this.entryType.setValue(entryType); diff --git a/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesViewModel.java index 0ee72445c80..6f916bd230b 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/keypattern/KeyPatternPropertiesViewModel.java @@ -6,8 +6,8 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; -import org.jabref.gui.commonfxcontrols.CitationKeyPatternsPanelItemModel; import org.jabref.gui.commonfxcontrols.CitationKeyPatternsPanelViewModel; +import org.jabref.gui.commonfxcontrols.PatternsItemModel; import org.jabref.gui.libraryproperties.PropertiesTabViewModel; import org.jabref.logic.citationkeypattern.DatabaseCitationKeyPatterns; import org.jabref.logic.preferences.CliPreferences; @@ -17,9 +17,9 @@ public class KeyPatternPropertiesViewModel implements PropertiesTabViewModel { // The list and the default properties are being overwritten by the bound properties of the tableView, but to // prevent an NPE on storing the preferences before lazy-loading of the setValues, they need to be initialized. - private final ListProperty patternListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final ObjectProperty defaultKeyPatternProperty = new SimpleObjectProperty<>( - new CitationKeyPatternsPanelItemModel(new CitationKeyPatternsPanelViewModel.DefaultEntryType(), "")); + private final ListProperty patternListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ObjectProperty defaultKeyPatternProperty = new SimpleObjectProperty<>( + new PatternsItemModel(new CitationKeyPatternsPanelViewModel.DefaultEntryType(), "")); private final CliPreferences preferences; @@ -57,11 +57,11 @@ public void storeSettings() { databaseContext.getMetaData().setCiteKeyPattern(newKeyPattern); } - public ListProperty patternListProperty() { + public ListProperty patternListProperty() { return patternListProperty; } - public ObjectProperty defaultKeyPatternProperty() { + public ObjectProperty defaultKeyPatternProperty() { return defaultKeyPatternProperty; } } diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.fxml b/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.fxml new file mode 100644 index 00000000000..e173ccdf1be --- /dev/null +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.fxml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.java b/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.java new file mode 100644 index 00000000000..1487757822a --- /dev/null +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanel.java @@ -0,0 +1,140 @@ +package org.jabref.gui.linkedfile; + +import java.util.Collection; + +import javafx.beans.property.ListProperty; +import javafx.beans.property.ObjectProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableRow; +import javafx.scene.control.TableView; +import javafx.scene.input.KeyEvent; + +import org.jabref.gui.commonfxcontrols.PatternSuggestionCell; +import org.jabref.gui.commonfxcontrols.PatternsItemModel; +import org.jabref.gui.icon.IconTheme; +import org.jabref.gui.util.ValueTableCellFactory; +import org.jabref.logic.citationkeypattern.KeyPattern; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.linkedfile.AbstractLinkedFileNamePatterns; +import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.types.EntryType; + +import com.airhacks.afterburner.views.ViewLoader; + +public class LinkedFileNamePatternsPanel extends TableView { + + @FXML public TableColumn entryTypeColumn; + @FXML public TableColumn patternColumn; + @FXML public TableColumn actionsColumn; + + private LinkedFileNamePatternsPanelViewModel viewModel; + + private long lastKeyPressTime; + private String tableSearchTerm; + private final ObservableList patterns; + + public LinkedFileNamePatternsPanel() { + super(); + this.patterns = FXCollections.observableArrayList( + KeyPattern.getAllPatterns().stream() + .map(KeyPattern::stringRepresentation) + .toList() + ); + + ViewLoader.view(this) + .root(this) + .load(); + } + + @FXML + private void initialize() { + viewModel = new LinkedFileNamePatternsPanelViewModel(); + + this.setEditable(true); + + entryTypeColumn.setSortable(true); + entryTypeColumn.setReorderable(false); + entryTypeColumn.setCellValueFactory(cellData -> cellData.getValue().entryType()); + new ValueTableCellFactory() + .withText(EntryType::getDisplayName) + .install(entryTypeColumn); + this.setOnSort(event -> + viewModel.patternListProperty().sort(LinkedFileNamePatternsPanelViewModel.defaultOnTopComparator)); + + patternColumn.setSortable(true); + patternColumn.setReorderable(false); + patternColumn.setCellValueFactory(cellData -> cellData.getValue().pattern()); + patternColumn.setCellFactory(a -> new PatternSuggestionCell(patterns)); + patternColumn.setEditable(true); + patternColumn.setOnEditCommit( + (TableColumn.CellEditEvent event) -> + event.getRowValue().setPattern(event.getNewValue())); + + actionsColumn.setSortable(false); + actionsColumn.setReorderable(false); + actionsColumn.setCellValueFactory(cellData -> cellData.getValue().entryType()); + new ValueTableCellFactory() + .withGraphic(entryType -> IconTheme.JabRefIcons.REFRESH.getGraphicNode()) + .withTooltip(entryType -> + Localization.lang("Reset %s to default value").formatted(entryType.getDisplayName())) + .withOnMouseClickedEvent(item -> evt -> + viewModel.setItemToDefaultPattern(this.getFocusModel().getFocusedItem())) + .install(actionsColumn); + + this.setRowFactory(item -> new HighlightTableRow()); + this.setOnKeyTyped(this::jumpToSearchKey); + this.itemsProperty().bindBidirectional(viewModel.patternListProperty()); + } + + public void setValues(Collection entryTypeList, AbstractLinkedFileNamePatterns keyPattern) { + viewModel.setValues(entryTypeList, keyPattern); + } + + public void resetAll() { + viewModel.resetAll(); + } + + public ListProperty patternListProperty() { + return viewModel.patternListProperty(); + } + + public ObjectProperty defaultNamePatternProperty() { + return viewModel.defaultNamePatternProperty(); + } + + private void jumpToSearchKey(KeyEvent keypressed) { + if (keypressed.getCharacter() == null) { + return; + } + + if (System.currentTimeMillis() - lastKeyPressTime < 1000) { + tableSearchTerm += keypressed.getCharacter().toLowerCase(); + } else { + tableSearchTerm = keypressed.getCharacter().toLowerCase(); + } + + lastKeyPressTime = System.currentTimeMillis(); + + this.getItems().stream().filter(item -> item.getEntryType().getName().toLowerCase().startsWith(tableSearchTerm)) + .findFirst().ifPresent(this::scrollTo); + } + + private static class HighlightTableRow extends TableRow { + @Override + public void updateItem(PatternsItemModel item, boolean empty) { + super.updateItem(item, empty); + if (item == null || item.getEntryType() == null) { + setStyle(""); + } else if (isSelected()) { + setStyle("-fx-background-color: -fx-selection-bar"); + } else if (LinkedFileNamePatternsPanelViewModel.ENTRY_TYPE_DEFAULT_NAME.equals(item.getEntryType().getName())) { + setStyle("-fx-background-color: -fx-default-button"); + } else { + setStyle(""); + } + } + } +} diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanelViewModel.java b/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanelViewModel.java new file mode 100644 index 00000000000..f7a10a99a32 --- /dev/null +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFileNamePatternsPanelViewModel.java @@ -0,0 +1,95 @@ +package org.jabref.gui.linkedfile; + +import java.util.Collection; +import java.util.Comparator; + +import javafx.beans.property.ListProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.FXCollections; + +import org.jabref.gui.commonfxcontrols.PatternsItemModel; +import org.jabref.logic.citationkeypattern.KeyPattern; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.linkedfile.AbstractLinkedFileNamePatterns; +import org.jabref.model.entry.BibEntryType; +import org.jabref.model.entry.types.EntryType; + +public class LinkedFileNamePatternsPanelViewModel { + public static final String ENTRY_TYPE_DEFAULT_NAME = "default"; + + public static Comparator defaultOnTopComparator = (o1, o2) -> { + String itemOneName = o1.getEntryType().getName(); + String itemTwoName = o2.getEntryType().getName(); + + if (itemOneName.equals(itemTwoName)) { + return 0; + } else if (ENTRY_TYPE_DEFAULT_NAME.equals(itemOneName)) { + return -1; + } else if (ENTRY_TYPE_DEFAULT_NAME.equals(itemTwoName)) { + return 1; + } + + return 0; + }; + + private final ListProperty patternListProperty = new SimpleListProperty<>(); + private final ObjectProperty defaultItemProperty = new SimpleObjectProperty<>(); + + public LinkedFileNamePatternsPanelViewModel() { } + + public void setValues(Collection entryTypeList, AbstractLinkedFileNamePatterns initialNamePattern) { + String defaultPattern; + if ((initialNamePattern.getDefaultValue() == null) || initialNamePattern.getDefaultValue().equals(KeyPattern.NULL_PATTERN)) { + defaultPattern = ""; + } else { + defaultPattern = initialNamePattern.getDefaultValue().stringRepresentation(); + } + + defaultItemProperty.setValue(new PatternsItemModel(new DefaultEntryType(), defaultPattern)); + patternListProperty.setValue(FXCollections.observableArrayList()); + patternListProperty.add(defaultItemProperty.getValue()); + + entryTypeList.stream() + .map(BibEntryType::getType) + .forEach(entryType -> { + String pattern; + if (initialNamePattern.isDefaultValue(entryType)) { + pattern = ""; + } else { + pattern = initialNamePattern.getPatterns().get(entryType).stringRepresentation(); + } + patternListProperty.add(new PatternsItemModel(entryType, pattern)); + }); + } + + public void setItemToDefaultPattern(PatternsItemModel item) { + item.setPattern(KeyPattern.AUTHOR_YEAR.stringRepresentation()); + } + + public void resetAll() { + patternListProperty.forEach(item -> item.setPattern("")); + defaultItemProperty.getValue().setPattern(ENTRY_TYPE_DEFAULT_NAME); + } + + public ListProperty patternListProperty() { + return patternListProperty; + } + + public ObjectProperty defaultNamePatternProperty() { + return defaultItemProperty; + } + + public static class DefaultEntryType implements EntryType { + @Override + public String getName() { + return ENTRY_TYPE_DEFAULT_NAME; + } + + @Override + public String getDisplayName() { + return Localization.lang("Default pattern"); + } + } +} diff --git a/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTabViewModel.java b/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTabViewModel.java index 2ccfdf85897..61f27fea895 100644 --- a/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/citationkeypattern/CitationKeyPatternTabViewModel.java @@ -10,8 +10,8 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; -import org.jabref.gui.commonfxcontrols.CitationKeyPatternsPanelItemModel; import org.jabref.gui.commonfxcontrols.CitationKeyPatternsPanelViewModel; +import org.jabref.gui.commonfxcontrols.PatternsItemModel; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; import org.jabref.logic.citationkeypattern.GlobalCitationKeyPatterns; @@ -32,9 +32,9 @@ public class CitationKeyPatternTabViewModel implements PreferenceTabViewModel { // The list and the default properties are being overwritten by the bound properties of the tableView, but to // prevent an NPE on storing the preferences before lazy-loading of the setValues, they need to be initialized. - private final ListProperty patternListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final ObjectProperty defaultKeyPatternProperty = new SimpleObjectProperty<>( - new CitationKeyPatternsPanelItemModel(new CitationKeyPatternsPanelViewModel.DefaultEntryType(), "")); + private final ListProperty patternListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final ObjectProperty defaultKeyPatternProperty = new SimpleObjectProperty<>( + new PatternsItemModel(new CitationKeyPatternsPanelViewModel.DefaultEntryType(), "")); private final CitationKeyPatternPreferences keyPatternPreferences; @@ -153,11 +153,11 @@ public StringProperty keyPatternReplacementProperty() { return keyPatternReplacementProperty; } - public ListProperty patternListProperty() { + public ListProperty patternListProperty() { return patternListProperty; } - public ObjectProperty defaultKeyPatternProperty() { + public ObjectProperty defaultKeyPatternProperty() { return defaultKeyPatternProperty; } diff --git a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.fxml b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.fxml index 56600d64e34..651d074bfa1 100644 --- a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTab.fxml @@ -8,12 +8,14 @@ + + @@ -59,23 +61,11 @@