-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Handling resetting of PushToApplicationPreferences #14691
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
Changes from 2 commits
62303f0
2d0f027
4cf0d9d
b171c12
6cefbfd
fae10a3
c6e5a64
e8dc609
d110ae3
896cba3
7029a35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ | |
| import java.util.stream.Collectors; | ||
|
|
||
| import javafx.beans.InvalidationListener; | ||
| import javafx.beans.property.SimpleMapProperty; | ||
| import javafx.collections.FXCollections; | ||
| import javafx.collections.ListChangeListener; | ||
| import javafx.collections.ObservableSet; | ||
| import javafx.collections.SetChangeListener; | ||
|
|
@@ -764,29 +766,6 @@ public JabRefCliPreferences() { | |
| defaults.put(AI_CITATION_PARSING_USER_MESSAGE_TEMPLATE, AiDefaultPreferences.TEMPLATES.get(AiTemplate.CITATION_PARSING_USER_MESSAGE)); | ||
| // endregion | ||
|
|
||
| // region PushToApplicationPreferences | ||
| defaults.put(PUSH_TEXMAKER_PATH, OS.detectProgramPath("texmaker", "Texmaker")); | ||
| defaults.put(PUSH_WINEDT_PATH, OS.detectProgramPath("WinEdt", "WinEdt Team\\WinEdt")); | ||
| defaults.put(PUSH_TO_APPLICATION, "TeXstudio"); | ||
| defaults.put(PUSH_TEXSTUDIO_PATH, OS.detectProgramPath("texstudio", "TeXstudio")); | ||
| defaults.put(PUSH_TEXWORKS_PATH, OS.detectProgramPath("texworks", "TeXworks")); | ||
| defaults.put(PUSH_SUBLIME_TEXT_PATH, OS.detectProgramPath("subl", "Sublime")); | ||
| defaults.put(PUSH_LYXPIPE, USER_HOME + File.separator + ".lyx/lyxpipe"); | ||
| defaults.put(PUSH_VIM, "vim"); | ||
| defaults.put(PUSH_VIM_SERVER, "vim"); | ||
| defaults.put(PUSH_EMACS_ADDITIONAL_PARAMETERS, "-n -e"); | ||
| defaults.put(PUSH_VSCODE_PATH, OS.detectProgramPath("Code", "Microsoft VS Code")); | ||
| defaults.put(PUSH_CITE_COMMAND, "\\cite{key1,key2}"); | ||
|
|
||
| if (OS.OS_X) { | ||
| defaults.put(PUSH_EMACS_PATH, "emacsclient"); | ||
| } else if (OS.WINDOWS) { | ||
| defaults.put(PUSH_EMACS_PATH, "emacsclient.exe"); | ||
| } else { | ||
| // Linux | ||
| defaults.put(PUSH_EMACS_PATH, "emacsclient"); | ||
| } | ||
| // endregion | ||
|
|
||
| // WalkThrough | ||
| defaults.put(MAIN_FILE_DIRECTORY_WALKTHROUGH_COMPLETED, Boolean.FALSE); | ||
|
|
@@ -812,32 +791,40 @@ public void setLanguageDependentDefaultValues() { | |
|
|
||
| // region PushToApplicationPreferences | ||
|
|
||
| private PushToApplicationPreferences getPushToApplicationPreferencesFromBackingStore(PushToApplicationPreferences defaults) { | ||
| Map<String, String> commandPaths = new HashMap<>(defaults.getCommandPaths()); | ||
| Map<String, String> lookup = new HashMap<>(); | ||
| lookup.put(PushApplications.EMACS.getDisplayName(), PUSH_EMACS_PATH); | ||
| lookup.put(PushApplications.LYX.getDisplayName(), PUSH_LYXPIPE); | ||
| lookup.put(PushApplications.TEXMAKER.getDisplayName(), PUSH_TEXMAKER_PATH); | ||
| lookup.put(PushApplications.TEXSTUDIO.getDisplayName(), PUSH_TEXSTUDIO_PATH); | ||
| lookup.put(PushApplications.TEXWORKS.getDisplayName(), PUSH_TEXWORKS_PATH); | ||
| lookup.put(PushApplications.VIM.getDisplayName(), PUSH_VIM); | ||
| lookup.put(PushApplications.WIN_EDT.getDisplayName(), PUSH_WINEDT_PATH); | ||
| lookup.put(PushApplications.SUBLIME_TEXT.getDisplayName(), PUSH_SUBLIME_TEXT_PATH); | ||
| lookup.put(PushApplications.VSCODE.getDisplayName(), PUSH_VSCODE_PATH); | ||
| for(Map.Entry<String, String> entry : commandPaths.entrySet()) { | ||
| String oldKey = lookup.get(entry.getKey()); | ||
| String defaultValue = entry.getValue(); | ||
| entry.setValue(getEmptyIsDefault(oldKey, defaultValue)); | ||
| } | ||
| return new PushToApplicationPreferences( | ||
| get(PUSH_TO_APPLICATION, defaults.getActiveApplicationName()), | ||
| new SimpleMapProperty<>(FXCollections.observableMap(commandPaths)), | ||
| get(PUSH_EMACS_ADDITIONAL_PARAMETERS, defaults.getEmacsArguments()), | ||
| get(PUSH_VIM_SERVER, defaults.getVimServer()), | ||
| CitationCommandString.from(get(PUSH_CITE_COMMAND, defaults.getCiteCommand().toString())), | ||
| CitationCommandString.from(get(PUSH_CITE_COMMAND, defaults.getDefaultCiteCommand().toString())) | ||
| ); | ||
|
|
||
| } | ||
|
Comment on lines
792
to
812
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are the others not read from the prefs node here? |
||
|
|
||
| public PushToApplicationPreferences getPushToApplicationPreferences() { | ||
| if (pushToApplicationPreferences != null) { | ||
| return pushToApplicationPreferences; | ||
| } | ||
|
|
||
| Map<String, String> applicationCommands = new HashMap<>(); | ||
| // getEmptyIsDefault is used to ensure that an installation of a tool leads to the new path (instead of leaving the empty one) | ||
| // Reason: empty string is returned by org.jabref.gui.desktop.os.Windows.detectProgramPath if program is not found. That path is stored in the preferences. | ||
| applicationCommands.put(PushApplications.EMACS.getDisplayName(), getEmptyIsDefault(PUSH_EMACS_PATH)); | ||
| applicationCommands.put(PushApplications.LYX.getDisplayName(), getEmptyIsDefault(PUSH_LYXPIPE)); | ||
| applicationCommands.put(PushApplications.TEXMAKER.getDisplayName(), getEmptyIsDefault(PUSH_TEXMAKER_PATH)); | ||
| applicationCommands.put(PushApplications.TEXSTUDIO.getDisplayName(), getEmptyIsDefault(PUSH_TEXSTUDIO_PATH)); | ||
| applicationCommands.put(PushApplications.TEXWORKS.getDisplayName(), getEmptyIsDefault(PUSH_TEXWORKS_PATH)); | ||
| applicationCommands.put(PushApplications.VIM.getDisplayName(), getEmptyIsDefault(PUSH_VIM)); | ||
| applicationCommands.put(PushApplications.WIN_EDT.getDisplayName(), getEmptyIsDefault(PUSH_WINEDT_PATH)); | ||
| applicationCommands.put(PushApplications.SUBLIME_TEXT.getDisplayName(), getEmptyIsDefault(PUSH_SUBLIME_TEXT_PATH)); | ||
| applicationCommands.put(PushApplications.VSCODE.getDisplayName(), getEmptyIsDefault(PUSH_VSCODE_PATH)); | ||
|
|
||
| pushToApplicationPreferences = new PushToApplicationPreferences( | ||
| get(PUSH_TO_APPLICATION), | ||
| applicationCommands, | ||
| get(PUSH_EMACS_ADDITIONAL_PARAMETERS), | ||
| get(PUSH_VIM_SERVER), | ||
| CitationCommandString.from(get(PUSH_CITE_COMMAND)), | ||
| CitationCommandString.from((String) defaults.get(PUSH_CITE_COMMAND)) | ||
| ); | ||
| pushToApplicationPreferences = getPushToApplicationPreferencesFromBackingStore(PushToApplicationPreferences.getDefault()); | ||
|
|
||
| EasyBind.listen(pushToApplicationPreferences.activeApplicationNameProperty(), (obs, oldValue, newValue) -> put(PUSH_TO_APPLICATION, newValue)); | ||
| pushToApplicationPreferences.getCommandPaths().addListener((obs, oldValue, newValue) -> storePushToApplicationPath(newValue)); | ||
|
|
@@ -926,8 +913,7 @@ public String get(String key) { | |
| return PREFS_NODE.get(key, (String) defaults.get(key)); | ||
| } | ||
|
|
||
| public String getEmptyIsDefault(String key) { | ||
| String defaultValue = (String) defaults.get(key); | ||
| public String getEmptyIsDefault(String key, String defaultValue) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not be modified. |
||
| String result = PREFS_NODE.get(key, defaultValue); | ||
| if ("".equals(result)) { | ||
| return defaultValue; | ||
|
|
@@ -1055,6 +1041,7 @@ public void clear() throws BackingStoreException { | |
| new SharedDatabasePreferences().clear(); | ||
|
|
||
| getProxyPreferences().setAll(ProxyPreferences.getDefault()); | ||
| getPushToApplicationPreferences().setAll(PushToApplicationPreferences.getDefault()); | ||
| } | ||
|
|
||
| private void clearTruststoreFromCustomCertificates() { | ||
|
|
@@ -1209,6 +1196,7 @@ public void importPreferences(Path path) throws JabRefException { | |
|
|
||
| // in case of incomplete or corrupt xml fall back to current preferences | ||
| getProxyPreferences().setAll(ProxyPreferences.getDefault()); | ||
| getPushToApplicationPreferences().setAll(PushToApplicationPreferences.getDefault()); | ||
| } | ||
| //************************************************************************************************************* | ||
| // ToDo: Cleanup | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,13 @@ public enum PushApplications { | |
| private final String id; | ||
| private final String displayName; | ||
|
|
||
|
|
||
|
||
| PushApplications(String id, String displayName) { | ||
| this.id = id; | ||
| this.displayName = displayName; | ||
| } | ||
|
|
||
|
|
||
|
||
| public static Optional<PushApplications> getApplicationByDisplayName(String key) { | ||
| for (PushApplications application : PushApplications.values()) { | ||
| if (application.getDisplayName().equalsIgnoreCase(key)) { | ||
|
|
@@ -48,4 +50,6 @@ public String getId() { | |
| public String getDisplayName() { | ||
| return displayName; | ||
| } | ||
|
|
||
|
|
||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,7 @@ | ||||||||||||||
| package org.jabref.logic.push; | ||||||||||||||
|
|
||||||||||||||
| import java.io.File; | ||||||||||||||
| import java.util.HashMap; | ||||||||||||||
| import java.util.Map; | ||||||||||||||
|
|
||||||||||||||
| import javafx.beans.property.MapProperty; | ||||||||||||||
|
|
@@ -10,6 +12,8 @@ | |||||||||||||
| import javafx.beans.property.StringProperty; | ||||||||||||||
| import javafx.collections.FXCollections; | ||||||||||||||
|
|
||||||||||||||
| import org.jabref.logic.os.OS; | ||||||||||||||
|
|
||||||||||||||
| public class PushToApplicationPreferences { | ||||||||||||||
| private final StringProperty activeApplicationName; | ||||||||||||||
| private final MapProperty<String, String> commandPaths; | ||||||||||||||
|
|
@@ -19,6 +23,46 @@ public class PushToApplicationPreferences { | |||||||||||||
| private final ObjectProperty<CitationCommandString> citeCommand; | ||||||||||||||
| private final ObjectProperty<CitationCommandString> defaultCiteCommand; | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| private PushToApplicationPreferences(){ | ||||||||||||||
| this.activeApplicationName = new SimpleStringProperty("Texmaker"); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||
| Map<String, String> commands = new HashMap<>(); | ||||||||||||||
|
||||||||||||||
| commands.put("Texmaker", OS.detectProgramPath("texmaker", "Texmaker")); | ||||||||||||||
| commands.put("WinEdt", OS.detectProgramPath("WinEdt", "WinEdt Team\\WinEdt")); | ||||||||||||||
| commands.put("TeXstudio", OS.detectProgramPath("texstudio", "TeXstudio")); | ||||||||||||||
| commands.put("TeXworks", OS.detectProgramPath("texworks", "TeXworks")); | ||||||||||||||
| commands.put("Sublime Text", OS.detectProgramPath("subl", "Sublime")); | ||||||||||||||
| commands.put("LyX/Kile", System.getProperty("user.home") + File.separator + ".lyx/lyxpipe"); | ||||||||||||||
|
||||||||||||||
| commands.put("LyX/Kile", System.getProperty("user.home") + File.separator + ".lyx/lyxpipe"); | |
| commands.put("LyX/Kile", USER_HOME + File.separator + ".lyx/lyxpipe"); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(OS.WINDOWS){ | |
| commands.put("Emacs", "emacsclient.exe"); | |
| }else if(OS.OS_X || OS.LINUX){ | |
| commands.put("Emacs", "emacsclient"); | |
| } | |
| commands.put("Emacs", OS.WINDOWS ? "emacsclient.exe" : "emacsclient"); |

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks incredibly complicated for a very simple task.