Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}
Copy link
Member

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.

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
Copy link
Member

Choose a reason for hiding this comment

The 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));
Expand Down Expand Up @@ -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) {
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;
Expand Down Expand Up @@ -1055,6 +1041,7 @@ public void clear() throws BackingStoreException {
new SharedDatabasePreferences().clear();

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

private void clearTruststoreFromCustomCertificates() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public enum PushApplications {
private final String id;
private final String displayName;


Copy link
Member

Choose a reason for hiding this comment

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

checkstyle

PushApplications(String id, String displayName) {
this.id = id;
this.displayName = displayName;
}


Copy link
Member

Choose a reason for hiding this comment

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

checkstyle

public static Optional<PushApplications> getApplicationByDisplayName(String key) {
for (PushApplications application : PushApplications.values()) {
if (application.getDisplayName().equalsIgnoreCase(key)) {
Expand All @@ -48,4 +50,6 @@ public String getId() {
public String getDisplayName() {
return displayName;
}


Copy link
Member

Choose a reason for hiding this comment

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

checkstyle

}
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;
Expand All @@ -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;
Expand All @@ -19,6 +23,46 @@ 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

Map<String, String> commands = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

Why not FXCollections.observableMap here already?

Copy link
Member

Choose a reason for hiding this comment

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

AI generated code

Copy link
Member

Choose a reason for hiding this comment

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

AI generated code

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");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
commands.put("LyX/Kile", System.getProperty("user.home") + File.separator + ".lyx/lyxpipe");
commands.put("LyX/Kile", USER_HOME + File.separator + ".lyx/lyxpipe");

commands.put("VScode", OS.detectProgramPath("Code", "Microsoft VS Code"));
commands.put("Vim", "vim");

if(OS.WINDOWS){
commands.put("Emacs", "emacsclient.exe");
}else if(OS.OS_X || OS.LINUX){
commands.put("Emacs", "emacsclient");
}
Copy link
Member

@calixtus calixtus Dec 26, 2025

Choose a reason for hiding this comment

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

Suggested change
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");

this.commandPaths = new SimpleMapProperty<>(FXCollections.observableMap(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