From 4d1738d34dba565a7ab14eeb499995afebca9be7 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 8 Mar 2019 11:09:40 +0100 Subject: [PATCH] Fix default import format pattern (#4731) Remove Display Array Add migration Fixe #4724 --- .../jabref/gui/preferences/ImportSettingsTab.java | 12 +++++------- .../org/jabref/migrations/PreferencesMigrations.java | 8 +++++++- .../jabref/migrations/PreferencesMigrationsTest.java | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java b/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java index 3067882b2c2..80873eab063 100644 --- a/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java +++ b/src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java @@ -9,24 +9,20 @@ import javafx.scene.control.Separator; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; -import javafx.scene.layout.Pane; import org.jabref.logic.l10n.Localization; import org.jabref.preferences.JabRefPreferences; -public class ImportSettingsTab extends Pane implements PrefsTab { +public class ImportSettingsTab implements PrefsTab { public static final String[] DEFAULT_FILENAMEPATTERNS = new String[] {"[bibtexkey]", - "[bibtexkey] - [title]"}; - - private static final String[] DEFAULT_FILENAMEPATTERNS_DISPLAY = new String[] {"bibtexkey", "bibtexkey - title",}; + "[bibtexkey] - [title]"}; private final JabRefPreferences prefs; private final GridPane builder = new GridPane(); private final TextField fileNamePattern; private final ComboBox selectFileNamePattern; - private final TextField fileDirPattern; public ImportSettingsTab(JabRefPreferences prefs) { @@ -35,8 +31,9 @@ public ImportSettingsTab(JabRefPreferences prefs) { fileNamePattern = new TextField(); fileDirPattern = new TextField(); selectFileNamePattern = new ComboBox<>(); - selectFileNamePattern.getItems().addAll(FXCollections.observableArrayList(DEFAULT_FILENAMEPATTERNS_DISPLAY)); + selectFileNamePattern.getItems().addAll(FXCollections.observableArrayList(DEFAULT_FILENAMEPATTERNS)); selectFileNamePattern.setValue(Localization.lang("Choose pattern")); + selectFileNamePattern.setOnAction(e -> { fileNamePattern.setText(selectFileNamePattern.getValue()); }); @@ -60,6 +57,7 @@ public ImportSettingsTab(JabRefPreferences prefs) { builder.add(fileDirPattern, 2, 10); } + @Override public Node getBuilder() { return builder; } diff --git a/src/main/java/org/jabref/migrations/PreferencesMigrations.java b/src/main/java/org/jabref/migrations/PreferencesMigrations.java index f0923915177..70a4357ef3b 100644 --- a/src/main/java/org/jabref/migrations/PreferencesMigrations.java +++ b/src/main/java/org/jabref/migrations/PreferencesMigrations.java @@ -237,10 +237,16 @@ static void upgradeImportFileAndDirePatterns(JabRefPreferences prefs, Preference String[] oldStylePatterns = new String[] {"\\bibtexkey", "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}"}; String[] newStylePatterns = new String[] {"[bibtexkey]", - "[bibtexkey] - [fulltitle]"}; + "[bibtexkey] - [title]"}; + + String[] oldDisplayStylePattern = new String[] {"bibtexkey", "bibtexkey - title",}; + for (int i = 0; i < oldStylePatterns.length; i++) { migrateFileImportPattern(oldStylePatterns[i], newStylePatterns[i], prefs, mainPrefsNode); } + for (int i = 0; i < oldDisplayStylePattern.length; i++) { + migrateFileImportPattern(oldDisplayStylePattern[i], newStylePatterns[i], prefs, mainPrefsNode); + } } // Directory preferences are not yet migrated, since it is not quote clear how to parse and reinterpret // the user defined old-style patterns, and the default pattern is "". diff --git a/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java b/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java index c646bab55bb..6a2ee9bc5e8 100644 --- a/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java +++ b/src/test/java/org/jabref/migrations/PreferencesMigrationsTest.java @@ -20,7 +20,7 @@ class PreferencesMigrationsTest { private final String[] oldStylePatterns = new String[]{"\\bibtexkey", "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}"}; private final String[] newStylePatterns = new String[]{"[bibtexkey]", - "[bibtexkey] - [fulltitle]"}; + "[bibtexkey] - [title]"}; @BeforeEach void setUp() {