Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-for-issue-286
Browse files Browse the repository at this point in the history
  • Loading branch information
InAnYan committed Mar 22, 2024
2 parents ca92d6d + 72454e0 commit a12a9a9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where an exception occured when toggling between "Live" or "Locked" in the internal Document Viewer. [#10935](https://github.com/JabRef/jabref/issues/10935)
- Fixed an issue on Windows where the browser extension reported failure to send an entry to JabRef even though it was sent properly. [JabRef-Browser-Extension#493](https://github.com/JabRef/JabRef-Browser-Extension/issues/493)
- Fixed an issue with some articles on IEEE Xplore which had em dash. [#286](https://github.com/koppor/jabref/issues/286)
- Fixed an issue on Windows where TeXworks path was not resolved if it was installed with MiKTeX. [#10977](https://github.com/JabRef/jabref/issues/10977)
- We fixed an issue with where JabRef would throw an error when using MathSciNet search, as it was unable to parse the fetched JSON coreectly. [10996](https://github.com/JabRef/jabref/issues/10996)

### Removed
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ dependencies {
// parse plist files
implementation 'com.googlecode.plist:dd-plist:1.28'

// Parse lnk files
implementation 'com.github.vatbub:mslinks:1.0.6.2'

// YAML formatting
implementation 'org.yaml:snakeyaml:2.2'

Expand Down
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@
requires de.saxsys.mvvmfx.validation;
requires com.jthemedetector;
requires dd.plist;
requires mslinks;
requires org.yaml.snakeyaml;
}
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jabref.Launcher;
import org.jabref.gui.DialogService;
Expand All @@ -16,6 +19,8 @@
import com.sun.jna.platform.win32.Shell32Util;
import com.sun.jna.platform.win32.ShlObj;
import com.sun.jna.platform.win32.Win32Exception;
import mslinks.ShellLink;
import mslinks.ShellLinkException;
import org.slf4j.LoggerFactory;

/**
Expand Down Expand Up @@ -43,6 +48,20 @@ public void openFile(String filePath, String fileType, FilePreferences filePrefe

@Override
public String detectProgramPath(String programName, String directoryName) {
if (Objects.equals(programName, "texworks")) {
Path texworksLinkPath = Path.of(System.getenv("APPDATA") + "\\Microsoft\\Windows\\Start Menu\\Programs\\MiKTeX\\TeXworks.lnk");
if (Files.exists(texworksLinkPath)) {
try {
ShellLink link = new ShellLink(texworksLinkPath);
return link.resolveTarget();
} catch (IOException | ShellLinkException e) {
// Static logger instance cannot be used. See the class comment.
Logger logger = Logger.getLogger(Windows.class.getName());
logger.log(Level.WARNING, "Had an error while reading .lnk file for TeXworks", e);
}
}
}

String progFiles = System.getenv("ProgramFiles(x86)");
String programPath;
if (progFiles != null) {
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,15 @@ public String get(String key) {
return prefs.get(key, (String) defaults.get(key));
}

public String getEmptyIsDefault(String key) {
String defaultValue = (String) defaults.get(key);
String result = prefs.get(key, defaultValue);
if ("".equals(result)) {
return defaultValue;
}
return result;
}

public Optional<String> getAsOptional(String key) {
return Optional.ofNullable(prefs.get(key, (String) defaults.get(key)));
}
Expand Down Expand Up @@ -1774,14 +1783,16 @@ public PushToApplicationPreferences getPushToApplicationPreferences() {
}

Map<String, String> applicationCommands = new HashMap<>();
applicationCommands.put(PushToApplications.EMACS, get(PUSH_EMACS_PATH));
applicationCommands.put(PushToApplications.LYX, get(PUSH_LYXPIPE));
applicationCommands.put(PushToApplications.TEXMAKER, get(PUSH_TEXMAKER_PATH));
applicationCommands.put(PushToApplications.TEXSTUDIO, get(PUSH_TEXSTUDIO_PATH));
applicationCommands.put(PushToApplications.TEXWORKS, get(PUSH_TEXWORKS_PATH));
applicationCommands.put(PushToApplications.VIM, get(PUSH_VIM));
applicationCommands.put(PushToApplications.WIN_EDT, get(PUSH_WINEDT_PATH));
applicationCommands.put(PushToApplications.SUBLIME_TEXT, get(PUSH_SUBLIME_TEXT_PATH));
// 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(PushToApplications.EMACS, getEmptyIsDefault(PUSH_EMACS_PATH));
applicationCommands.put(PushToApplications.LYX, getEmptyIsDefault(PUSH_LYXPIPE));
applicationCommands.put(PushToApplications.TEXMAKER, getEmptyIsDefault(PUSH_TEXMAKER_PATH));
applicationCommands.put(PushToApplications.TEXSTUDIO, getEmptyIsDefault(PUSH_TEXSTUDIO_PATH));
applicationCommands.put(PushToApplications.TEXWORKS, getEmptyIsDefault(PUSH_TEXWORKS_PATH));
applicationCommands.put(PushToApplications.VIM, getEmptyIsDefault(PUSH_VIM));
applicationCommands.put(PushToApplications.WIN_EDT, getEmptyIsDefault(PUSH_WINEDT_PATH));
applicationCommands.put(PushToApplications.SUBLIME_TEXT, getEmptyIsDefault(PUSH_SUBLIME_TEXT_PATH));

pushToApplicationPreferences = new PushToApplicationPreferences(
get(PUSH_TO_APPLICATION),
Expand Down

0 comments on commit a12a9a9

Please sign in to comment.