diff --git a/src/main/java/net/sf/jabref/MetaData.java b/src/main/java/net/sf/jabref/MetaData.java index 67ef5374af8..80de9f8ce64 100644 --- a/src/main/java/net/sf/jabref/MetaData.java +++ b/src/main/java/net/sf/jabref/MetaData.java @@ -166,24 +166,27 @@ public void putData(String key, Vector orderedData) { * The settings are prioritized in the following order and the first defined setting is used: * 1. metadata user-specific directory * 2. metadata general directory - * 3. preferences directory. + * 3. preferences directory + * 4. bib file directory * * @param fieldName The field type * @return The default directory for this field type. */ public List getFileDirectory(String fieldName) { - List dirs = new ArrayList<>(); - - String key = Globals.prefs.get(JabRefPreferences.USER_FILE_DIR_INDIVIDUAL); - - Vector vec = getData(key); - if (vec == null) { - key = Globals.prefs.get(JabRefPreferences.USER_FILE_DIR); - vec = getData(key); + List fileDirs = new ArrayList<>(); + + // 1. metadata user-specific directory + String key = Globals.prefs.get(JabRefPreferences.USER_FILE_DIR_INDIVIDUAL); // USER_SPECIFIC_FILE_DIR_FOR_DB + List metaData = getData(key); + if (metaData == null) { + key = Globals.prefs.get(JabRefPreferences.USER_FILE_DIR); // FILE_DIR_FOR_DIR + metaData = getData(key); } - if ((vec != null) && !vec.isEmpty()) { + + // 2. metadata general directory + if ((metaData != null) && !metaData.isEmpty()) { String dir; - dir = vec.get(0); + dir = metaData.get(0); // If this directory is relative, we try to interpret it as relative to // the file path of this bib file: if (!new File(dir).isAbsolute() && (file != null)) { @@ -192,7 +195,7 @@ public List getFileDirectory(String fieldName) { // if dir is only "current" directory, just use its parent (== real current directory) as path relDir = file.getParent(); } else { - relDir = file.getParent() + System.getProperty("file.separator") + dir; + relDir = file.getParent() + File.separator + dir; } // If this directory actually exists, it is very likely that the // user wants us to use it: @@ -200,25 +203,26 @@ public List getFileDirectory(String fieldName) { dir = relDir; } } - dirs.add(dir); + fileDirs.add(dir); } else { - String dir = Globals.prefs.get(fieldName + Globals.DIR_SUFFIX); + // 3. preferences directory? + String dir = Globals.prefs.get(fieldName + Globals.DIR_SUFFIX); // FILE_DIR if (dir != null) { - dirs.add(dir); + fileDirs.add(dir); } } - // Check if the bib file location should be included, and if so, if it is set: + // 4. bib file directory TODO: remove these options? if (Globals.prefs.getBoolean(JabRefPreferences.BIB_LOCATION_AS_FILE_DIR) && (getFile() != null)) { // Check if we should add it as primary file dir (first in the list) or not: if (Globals.prefs.getBoolean(JabRefPreferences.BIB_LOC_AS_PRIMARY_DIR)) { - dirs.add(0, getFile().getParent()); + fileDirs.add(0, getFile().getParent()); } else { - dirs.add(getFile().getParent()); + fileDirs.add(getFile().getParent()); } } - return dirs; + return fileDirs; } /**