Skip to content

Commit

Permalink
Change ideas for discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Jan 25, 2016
1 parent 90484aa commit 64b848a
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,27 @@ public void putData(String key, Vector<String> 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<String> getFileDirectory(String fieldName) {
List<String> dirs = new ArrayList<>();

String key = Globals.prefs.get(JabRefPreferences.USER_FILE_DIR_INDIVIDUAL);

Vector<String> vec = getData(key);
if (vec == null) {
key = Globals.prefs.get(JabRefPreferences.USER_FILE_DIR);
vec = getData(key);
List<String> 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<String> 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)) {
Expand All @@ -192,33 +195,34 @@ public List<String> 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:
if (new File(relDir).exists()) {
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;
}

/**
Expand Down

0 comments on commit 64b848a

Please sign in to comment.