Skip to content

Commit 2d0f027

Browse files
committed
removing low level api from high level implementaions addressing feedback
1 parent 62303f0 commit 2d0f027

File tree

3 files changed

+43
-50
lines changed

3 files changed

+43
-50
lines changed

jablib/src/main/java/org/jabref/logic/preferences/JabRefCliPreferences.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.util.stream.Collectors;
2828

2929
import javafx.beans.InvalidationListener;
30+
import javafx.beans.property.SimpleMapProperty;
31+
import javafx.collections.FXCollections;
3032
import javafx.collections.ListChangeListener;
3133
import javafx.collections.ObservableSet;
3234
import javafx.collections.SetChangeListener;
@@ -790,14 +792,31 @@ public void setLanguageDependentDefaultValues() {
790792
// region PushToApplicationPreferences
791793

792794
private PushToApplicationPreferences getPushToApplicationPreferencesFromBackingStore(PushToApplicationPreferences defaults) {
795+
Map<String, String> commandPaths = new HashMap<>(defaults.getCommandPaths());
796+
Map<String, String> lookup = new HashMap<>();
797+
lookup.put(PushApplications.EMACS.getDisplayName(), PUSH_EMACS_PATH);
798+
lookup.put(PushApplications.LYX.getDisplayName(), PUSH_LYXPIPE);
799+
lookup.put(PushApplications.TEXMAKER.getDisplayName(), PUSH_TEXMAKER_PATH);
800+
lookup.put(PushApplications.TEXSTUDIO.getDisplayName(), PUSH_TEXSTUDIO_PATH);
801+
lookup.put(PushApplications.TEXWORKS.getDisplayName(), PUSH_TEXWORKS_PATH);
802+
lookup.put(PushApplications.VIM.getDisplayName(), PUSH_VIM);
803+
lookup.put(PushApplications.WIN_EDT.getDisplayName(), PUSH_WINEDT_PATH);
804+
lookup.put(PushApplications.SUBLIME_TEXT.getDisplayName(), PUSH_SUBLIME_TEXT_PATH);
805+
lookup.put(PushApplications.VSCODE.getDisplayName(), PUSH_VSCODE_PATH);
806+
for(Map.Entry<String, String> entry : commandPaths.entrySet()) {
807+
String oldKey = lookup.get(entry.getKey());
808+
String defaultValue = entry.getValue();
809+
entry.setValue(getEmptyIsDefault(oldKey, defaultValue));
810+
}
793811
return new PushToApplicationPreferences(
794812
get(PUSH_TO_APPLICATION, defaults.getActiveApplicationName()),
795-
defaults.getCommandPaths(),
813+
new SimpleMapProperty<>(FXCollections.observableMap(commandPaths)),
796814
get(PUSH_EMACS_ADDITIONAL_PARAMETERS, defaults.getEmacsArguments()),
797815
get(PUSH_VIM_SERVER, defaults.getVimServer()),
798-
defaults.getCiteCommand(),
799-
defaults.getDefaultCiteCommand()
816+
CitationCommandString.from(get(PUSH_CITE_COMMAND, defaults.getCiteCommand().toString())),
817+
CitationCommandString.from(get(PUSH_CITE_COMMAND, defaults.getDefaultCiteCommand().toString()))
800818
);
819+
801820
}
802821

803822
public PushToApplicationPreferences getPushToApplicationPreferences() {
@@ -894,8 +913,7 @@ public String get(String key) {
894913
return PREFS_NODE.get(key, (String) defaults.get(key));
895914
}
896915

897-
public String getEmptyIsDefault(String key) {
898-
String defaultValue = (String) defaults.get(key);
916+
public String getEmptyIsDefault(String key, String defaultValue) {
899917
String result = PREFS_NODE.get(key, defaultValue);
900918
if ("".equals(result)) {
901919
return defaultValue;
@@ -920,12 +938,6 @@ public boolean getBoolean(String key, boolean def) {
920938
}
921939

922940
private boolean getBooleanDefault(String key) {
923-
924-
if (defaults.get(key) == null) {
925-
// Couldn't run the application without this condition.
926-
LOGGER.info("************************* THIS KEY IS NULL {}", key);
927-
return false;
928-
}
929941
return (Boolean) defaults.get(key);
930942
}
931943

jablib/src/main/java/org/jabref/logic/push/PushApplications.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,26 @@
44

55
public enum PushApplications {
66

7-
EMACS("emacs", "Emacs", "emacsPath"),
8-
LYX("lyx", "LyX/Kile", "lyxpipe"),
9-
TEXMAKER("texmaker", "Texmaker", "texmakerPath"),
10-
TEXSTUDIO("texstudio", "TeXstudio", "TeXstudioPath"),
11-
TEXWORKS("texworks", "TeXworks", "TeXworksPath"),
12-
VIM("vim", "Vim", "vim"),
13-
WIN_EDT("winedt", "WinEdt", "winEdtPath"),
14-
SUBLIME_TEXT("sublime", "Sublime Text", "sublimeTextPath"),
7+
EMACS("emacs", "Emacs"),
8+
LYX("lyx", "LyX/Kile"),
9+
TEXMAKER("texmaker", "Texmaker"),
10+
TEXSTUDIO("texstudio", "TeXstudio"),
11+
TEXWORKS("texworks", "TeXworks"),
12+
VIM("vim", "Vim"),
13+
WIN_EDT("winedt", "WinEdt"),
14+
SUBLIME_TEXT("sublime", "Sublime Text"),
1515
TEXSHOP("texshop", "TeXShop"),
16-
VSCODE("vscode", "VScode", "VScodePath");
16+
VSCODE("vscode", "VScode");
1717

1818
private final String id;
1919
private final String displayName;
20-
private String key;
2120

2221

2322
PushApplications(String id, String displayName) {
2423
this.id = id;
2524
this.displayName = displayName;
2625
}
2726

28-
PushApplications(String id, String displayName, String key) {
29-
this.id = id;
30-
this.displayName = displayName;
31-
this.key = key;
32-
}
3327

3428
public static Optional<PushApplications> getApplicationByDisplayName(String key) {
3529
for (PushApplications application : PushApplications.values()) {
@@ -57,8 +51,5 @@ public String getDisplayName() {
5751
return displayName;
5852
}
5953

60-
public String getKey(){
61-
return key;
62-
}
6354

6455
}

jablib/src/main/java/org/jabref/logic/push/PushToApplicationPreferences.java

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.File;
44
import java.util.HashMap;
55
import java.util.Map;
6-
import java.util.prefs.Preferences;
76

87
import javafx.beans.property.MapProperty;
98
import javafx.beans.property.ObjectProperty;
@@ -26,21 +25,21 @@ public class PushToApplicationPreferences {
2625

2726

2827
private PushToApplicationPreferences(){
29-
this.activeApplicationName = new SimpleStringProperty(PushApplications.TEXSTUDIO.getDisplayName());
28+
this.activeApplicationName = new SimpleStringProperty("Texmaker");
3029
Map<String, String> commands = new HashMap<>();
31-
commands.put(PushApplications.TEXMAKER.getDisplayName(), getEmptyIsDefault(PushApplications.TEXMAKER.getKey(), OS.detectProgramPath("texmaker", "Texmaker")));
32-
commands.put(PushApplications.WIN_EDT.getDisplayName(), getEmptyIsDefault(PushApplications.WIN_EDT.getKey(), OS.detectProgramPath("WinEdt", "WinEdt Team\\WinEdt")));
33-
commands.put(PushApplications.TEXSTUDIO.getDisplayName(), getEmptyIsDefault(PushApplications.TEXSTUDIO.getKey(), OS.detectProgramPath("texstudio", "TeXstudio")));
34-
commands.put(PushApplications.TEXWORKS.getDisplayName(), getEmptyIsDefault(PushApplications.TEXWORKS.getKey(), OS.detectProgramPath("texworks", "TeXworks")));
35-
commands.put(PushApplications.SUBLIME_TEXT.getDisplayName(), getEmptyIsDefault(PushApplications.SUBLIME_TEXT.getKey(), OS.detectProgramPath("subl", "Sublime")));
36-
commands.put(PushApplications.LYX.getDisplayName(), getEmptyIsDefault(PushApplications.LYX.getKey(), System.getProperty("user.home") + File.separator + ".lyx/lyxpipe"));
37-
commands.put(PushApplications.VSCODE.getDisplayName(), getEmptyIsDefault(PushApplications.VSCODE.getKey(), OS.detectProgramPath("Code", "Microsoft VS Code")));
38-
commands.put(PushApplications.VIM.getDisplayName(), getEmptyIsDefault(PushApplications.VIM.getKey(), "vim"));
30+
commands.put("Texmaker", OS.detectProgramPath("texmaker", "Texmaker"));
31+
commands.put("WinEdt", OS.detectProgramPath("WinEdt", "WinEdt Team\\WinEdt"));
32+
commands.put("TeXstudio", OS.detectProgramPath("texstudio", "TeXstudio"));
33+
commands.put("TeXworks", OS.detectProgramPath("texworks", "TeXworks"));
34+
commands.put("Sublime Text", OS.detectProgramPath("subl", "Sublime"));
35+
commands.put("LyX/Kile", System.getProperty("user.home") + File.separator + ".lyx/lyxpipe");
36+
commands.put("VScode", OS.detectProgramPath("Code", "Microsoft VS Code"));
37+
commands.put("Vim", "vim");
3938

4039
if(OS.WINDOWS){
41-
commands.put(PushApplications.EMACS.getDisplayName(), "emacsclient.exe");
40+
commands.put("Emacs", "emacsclient.exe");
4241
}else if(OS.OS_X || OS.LINUX){
43-
commands.put(PushApplications.EMACS.getDisplayName(), "emacsclient");
42+
commands.put("Emacs", "emacsclient");
4443
}
4544
this.commandPaths = new SimpleMapProperty<>(FXCollections.observableMap(commands));
4645

@@ -50,15 +49,6 @@ private PushToApplicationPreferences(){
5049
this.defaultCiteCommand = new SimpleObjectProperty<>(CitationCommandString.from("\\cite{key1,key2}"));
5150
}
5251

53-
private String getEmptyIsDefault(String key, String defaultValue) {
54-
final Preferences PREFS_NODE = Preferences.userRoot().node("/org/jabref");
55-
String result = PREFS_NODE.get(key, defaultValue);
56-
if ("".equals(result)) {
57-
return defaultValue;
58-
}
59-
return result;
60-
}
61-
6252

6353
public static PushToApplicationPreferences getDefault(){
6454
return new PushToApplicationPreferences();

0 commit comments

Comments
 (0)