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

Fix default import format pattern #4731

Merged
merged 1 commit into from
Mar 8, 2019
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
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++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a migration here? As this bug was introduced in 5.0 I doubt that many users are affected...

Copy link
Member Author

@Siedlerchr Siedlerchr Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks weird as it will display a wrong value in the field next to the combobox. The combobox has different values then

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