Skip to content

Commit

Permalink
Fix default import format pattern
Browse files Browse the repository at this point in the history
Remove Display Array
Add migration
Fixe #4724
  • Loading branch information
Siedlerchr committed Mar 7, 2019
1 parent 2f7aa7a commit a8d3a2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/main/java/org/jabref/gui/preferences/ImportSettingsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> selectFileNamePattern;


private final TextField fileDirPattern;

public ImportSettingsTab(JabRefPreferences prefs) {
Expand All @@ -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());
});
Expand All @@ -60,6 +57,7 @@ public ImportSettingsTab(JabRefPreferences prefs) {
builder.add(fileDirPattern, 2, 10);
}

@Override
public Node getBuilder() {
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a8d3a2a

Please sign in to comment.