Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.logic.preferences;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -766,30 +765,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);

Expand All @@ -814,32 +789,34 @@ public void setLanguageDependentDefaultValues() {

// region PushToApplicationPreferences

private PushToApplicationPreferences getPushToApplicationPreferencesFromBackingStore(PushToApplicationPreferences defaults) {
Map<String, String> applicationCommands = new HashMap<>();
Map<String, String> defaultCommands = defaults.getCommandPaths();
applicationCommands.put(PushApplications.EMACS.getDisplayName(), getEmptyIsDefault(PUSH_EMACS_PATH, defaultCommands.get(PushApplications.EMACS.getDisplayName())));
applicationCommands.put(PushApplications.LYX.getDisplayName(), getEmptyIsDefault(PUSH_LYXPIPE, defaultCommands.get(PushApplications.LYX.getDisplayName())));
applicationCommands.put(PushApplications.TEXMAKER.getDisplayName(), getEmptyIsDefault(PUSH_TEXMAKER_PATH, defaultCommands.get(PushApplications.TEXMAKER.getDisplayName())));
applicationCommands.put(PushApplications.TEXSTUDIO.getDisplayName(), getEmptyIsDefault(PUSH_TEXSTUDIO_PATH, defaultCommands.get(PushApplications.TEXSTUDIO.getDisplayName())));
applicationCommands.put(PushApplications.TEXWORKS.getDisplayName(), getEmptyIsDefault(PUSH_TEXWORKS_PATH, defaultCommands.get(PushApplications.TEXWORKS.getDisplayName())));
applicationCommands.put(PushApplications.VIM.getDisplayName(), getEmptyIsDefault(PUSH_VIM, defaultCommands.get(PushApplications.VIM.getDisplayName())));
applicationCommands.put(PushApplications.WIN_EDT.getDisplayName(), getEmptyIsDefault(PUSH_WINEDT_PATH, defaultCommands.get(PushApplications.WIN_EDT.getDisplayName())));
applicationCommands.put(PushApplications.SUBLIME_TEXT.getDisplayName(), getEmptyIsDefault(PUSH_SUBLIME_TEXT_PATH, defaultCommands.get(PushApplications.SUBLIME_TEXT.getDisplayName())));
applicationCommands.put(PushApplications.VSCODE.getDisplayName(), getEmptyIsDefault(PUSH_VSCODE_PATH, defaultCommands.get(PushApplications.VSCODE.getDisplayName())));
return new PushToApplicationPreferences(
get(PUSH_TO_APPLICATION, defaults.getActiveApplicationName()),
applicationCommands,
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()))
);
}

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));
Expand Down Expand Up @@ -937,6 +914,14 @@ public String getEmptyIsDefault(String key) {
return result;
}

public String getEmptyIsDefault(String key, String defaultValue) {
Copy link
Member

Choose a reason for hiding this comment

The 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;
}
return result;
}

public Optional<String> getAsOptional(String key) {
return Optional.ofNullable(PREFS_NODE.get(key, (String) defaults.get(key)));
}
Expand Down Expand Up @@ -1057,6 +1042,7 @@ public void clear() throws BackingStoreException {
new SharedDatabasePreferences().clear();

getProxyPreferences().setAll(ProxyPreferences.getDefault());
getPushToApplicationPreferences().setAll(PushToApplicationPreferences.getDefault());
}

private void clearTruststoreFromCustomCertificates() {
Expand Down Expand Up @@ -1203,6 +1189,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());
}

private static void importPreferencesToBackingStore(Path path) throws JabRefException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.push;

import java.io.File;
import java.util.Map;

import javafx.beans.property.MapProperty;
Expand All @@ -9,6 +10,11 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;

import org.jabref.logic.os.OS;

import static com.google.common.base.StandardSystemProperty.USER_HOME;

public class PushToApplicationPreferences {
private final StringProperty activeApplicationName;
Expand All @@ -19,6 +25,39 @@ public class PushToApplicationPreferences {
private final ObjectProperty<CitationCommandString> citeCommand;
private final ObjectProperty<CitationCommandString> defaultCiteCommand;

private PushToApplicationPreferences() {
this.activeApplicationName = new SimpleStringProperty("Texmaker");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

ObservableMap<String, String> commands = FXCollections.observableHashMap();
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", USER_HOME + File.separator + ".lyx/lyxpipe");
commands.put("VScode", OS.detectProgramPath("Code", "Microsoft VS Code"));
commands.put("Vim", "vim");
commands.put("Emacs", OS.WINDOWS ? "emacsclient.exe" : "emacsclient");
this.commandPaths = new SimpleMapProperty<>(commands);

this.emacsArguments = new SimpleStringProperty("-n -e");
this.vimServer = new SimpleStringProperty("vim");
this.citeCommand = new SimpleObjectProperty<>(CitationCommandString.from("\\cite{key1,key2}"));
this.defaultCiteCommand = new SimpleObjectProperty<>(CitationCommandString.from("\\cite{key1,key2}"));
}

public static PushToApplicationPreferences getDefault() {
return new PushToApplicationPreferences();
}

public void setAll(PushToApplicationPreferences preferences) {
this.activeApplicationName.set(preferences.activeApplicationName.get());
this.commandPaths.set(preferences.commandPaths);
this.vimServer.set(preferences.getVimServer());
this.emacsArguments.set(preferences.getEmacsArguments());
this.citeCommand.set(preferences.getCiteCommand());
this.defaultCiteCommand.set(preferences.getDefaultCiteCommand());
}

public PushToApplicationPreferences(String activeApplicationName,
Map<String, String> commandPaths,
String emacsArguments,
Expand Down
Loading