Skip to content

Add preference migration for keybdingings #3007

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

Merged
merged 1 commit into from
Jul 14, 2017
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 src/main/java/org/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private static void start(String[] args) {
PreferencesMigrations.upgradeFaultyEncodingStrings();
PreferencesMigrations.upgradeLabelPatternToBibtexKeyPattern();
PreferencesMigrations.upgradeStoredCustomEntryTypes();
PreferencesMigrations.upgradeKeyBindingsToJavaFX();

// Update handling of special fields based on preferences
InternalBibtexFields
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/org/jabref/migrations/PreferencesMigrations.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jabref.migrations;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

Expand Down Expand Up @@ -33,7 +35,7 @@ public static void upgradePrefsToOrgJabRef() {
// skip further processing as prefs already have been migrated
LOGGER.debug("New prefs node already exists with content - skipping migration");
} else {
if ( mainPrefsNode.parent().parent().nodeExists("net/sf/jabref")) {
if (mainPrefsNode.parent().parent().nodeExists("net/sf/jabref")) {
LOGGER.info("Migrating old preferences.");
Preferences oldNode = mainPrefsNode.parent().parent().node("net/sf/jabref");
copyPrefsRecursively(oldNode, mainPrefsNode);
Expand Down Expand Up @@ -138,7 +140,7 @@ public static void upgradeStoredCustomEntryTypes() {

try {
if (mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBTEX_TYPES) ||
mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES) ) {
mainPrefsNode.nodeExists(JabRefPreferences.CUSTOMIZED_BIBLATEX_TYPES)) {
// skip further processing as prefs already have been migrated
} else {
LOGGER.info("Migrating old custom entry types.");
Expand Down Expand Up @@ -188,13 +190,29 @@ public static void upgradeLabelPatternToBibtexKeyPattern() {
}
}

public static void upgradeKeyBindingsToJavaFX() {
UnaryOperator<String> replaceKeys = (str) -> {
String result = str.replace("ctrl ", "ctrl+");
result = result.replace("shift ", "shift+");
result = result.replace("alt ", "alt+");
result = result.replace("meta ", "meta+");

return result;
};

JabRefPreferences prefs = Globals.prefs;
List<String> keys = prefs.getStringList(JabRefPreferences.BINDINGS);
keys.replaceAll(replaceKeys);
prefs.putStringList(JabRefPreferences.BINDINGS, keys);

}

private static void migrateTypedKeyPrefs(JabRefPreferences prefs, Preferences oldPatternPrefs)
throws BackingStoreException {
LOGGER.info("Found old Bibtex Key patterns which will be migrated to new version.");

GlobalBibtexKeyPattern keyPattern = GlobalBibtexKeyPattern.fromPattern(
prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)
);
prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN));
for (String key : oldPatternPrefs.keys()) {
keyPattern.addBibtexKeyPattern(key, oldPatternPrefs.get(key, null));
}
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,18 @@ public class JabRefPreferences implements PreferencesService {
// Prefs node for customized entry types
public static final String CUSTOMIZED_BIBTEX_TYPES = "customizedBibtexTypes";
public static final String CUSTOMIZED_BIBLATEX_TYPES = "customizedBiblatexTypes";

// Version
public static final String VERSION_IGNORED_UPDATE = "versionIgnoreUpdate";
//KeyBindings - keys - public because needed for pref migration
public static final String BINDINGS = "bindings";

private static final String BIND_NAMES = "bindNames";
// User
private static final String USER_ID = "userId";
private static final String EXTERNAL_JOURNAL_LISTS = "externalJournalLists";
private static final String PERSONAL_JOURNAL_LIST = "personalJournalList";
private static final String USE_IEEE_ABRV = "useIEEEAbrv";
private static final String BINDINGS = "bindings";
private static final String BIND_NAMES = "bindNames";

// Telemetry collection
private static final String COLLECT_TELEMETRY = "collectTelemetry";
private static final String ALREADY_ASKED_TO_COLLECT_TELEMETRY = "askedCollectTelemetry";
Expand Down Expand Up @@ -761,7 +763,6 @@ private JabRefPreferences() {
defaults.put(USE_CASE_KEEPER_ON_SEARCH, Boolean.TRUE);
defaults.put(USE_UNIT_FORMATTER_ON_SEARCH, Boolean.TRUE);


defaults.put(USE_DEFAULT_CONSOLE_APPLICATION, Boolean.TRUE);
if (OS.WINDOWS) {
defaults.put(CONSOLE_COMMAND, "C:\\Program Files\\ConEmu\\ConEmu64.exe /single /dir \"%DIR\"");
Expand Down Expand Up @@ -1230,7 +1231,7 @@ public List<CustomEntryType> loadCustomEntryTypes(BibDatabaseMode bibDatabaseMod
}

private void clearAllCustomEntryTypes() throws BackingStoreException {
for (BibDatabaseMode mode :BibDatabaseMode.values()) {
for (BibDatabaseMode mode : BibDatabaseMode.values()) {
clearCustomEntryTypes(mode);
}
}
Expand Down Expand Up @@ -1607,8 +1608,7 @@ public AutoLinkPreferences getAutoLinkPreferences() {
getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY),
get(JabRefPreferences.AUTOLINK_REG_EXP_SEARCH_EXPRESSION_KEY),
getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY),
getKeywordDelimiter()
);
getKeywordDelimiter());
}

public AutoCompletePreferences getAutoCompletePreferences() {
Expand All @@ -1618,8 +1618,7 @@ public AutoCompletePreferences getAutoCompletePreferences() {
getBoolean(AUTOCOMPLETER_LAST_FIRST),
getBoolean(AUTOCOMPLETER_FIRST_LAST),
getStringList(AUTOCOMPLETER_COMPLETE_FIELDS),
getJournalAbbreviationPreferences()
);
getJournalAbbreviationPreferences());
}

public void storeAutoCompletePreferences(AutoCompletePreferences autoCompletePreferences) {
Expand Down