-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract native functions to OS package
- Loading branch information
1 parent
9f897ca
commit b40092c
Showing
4 changed files
with
151 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.sf.jabref.gui.desktop.os; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.external.ExternalFileType; | ||
import net.sf.jabref.external.ExternalFileTypes; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Linux { | ||
public static void openFolderAndSelectFile(String fileLink) throws IOException { | ||
String desktopSession = System.getenv("DESKTOP_SESSION").toLowerCase(); | ||
|
||
String cmd; | ||
|
||
if (desktopSession.contains("gnome")) { | ||
cmd = "nautilus " + fileLink; | ||
} else if (desktopSession.contains("kde")) { | ||
cmd = "dolphin --select " + fileLink; | ||
} else { | ||
cmd = "xdg-open " + fileLink.substring(0, fileLink.lastIndexOf(File.separator)); | ||
} | ||
|
||
Runtime.getRuntime().exec(cmd); | ||
} | ||
|
||
public static void openConsole(String absolutePath) throws IOException { | ||
Runtime runtime = Runtime.getRuntime(); | ||
Process p = runtime.exec("readlink /etc/alternatives/x-terminal-emulator"); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
|
||
String emulatorName = reader.readLine(); | ||
|
||
if (emulatorName != null) { | ||
emulatorName = emulatorName.substring(emulatorName.lastIndexOf(File.separator) + 1); | ||
|
||
if (emulatorName.contains("gnome")) { | ||
runtime.exec("gnome-terminal --working-directory=" + absolutePath); | ||
} else if (emulatorName.contains("xfce4")) { | ||
runtime.exec("xfce4-terminal --working-directory=" + absolutePath); | ||
} else if (emulatorName.contains("konsole")) { | ||
runtime.exec("konsole --workdir=" + absolutePath); | ||
} else { | ||
runtime.exec(emulatorName, null, new File(absolutePath)); | ||
} | ||
} | ||
} | ||
|
||
public static void openFile(String link, String fileType) throws IOException { | ||
ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); | ||
String viewer = type == null ? Globals.prefs.get(JabRefPreferences.PSVIEWER) : type.getOpenWith(); | ||
String[] cmdArray = new String[2]; | ||
cmdArray[0] = viewer; | ||
cmdArray[1] = link; | ||
Runtime.getRuntime().exec(cmdArray); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.sf.jabref.gui.desktop.os; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.external.ExternalFileType; | ||
import net.sf.jabref.external.ExternalFileTypes; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class OSX { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
public static void openFile(String link, String fileType) throws IOException { | ||
ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); | ||
String viewer = type == null ? Globals.prefs.get(JabRefPreferences.PSVIEWER) : type.getOpenWith(); | ||
String[] cmd = {"/usr/bin/open", "-a", viewer, link}; | ||
Runtime.getRuntime().exec(cmd); | ||
} | ||
|
||
public static void openFile(String link) throws IOException { | ||
ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("ps"); | ||
String viewer = type == null ? Globals.prefs.get(JabRefPreferences.PSVIEWER) : type.getOpenWith(); | ||
String[] cmd = {"/usr/bin/open", "-a", viewer, link}; | ||
Runtime.getRuntime().exec(cmd); | ||
} | ||
|
||
public static void openConsole(String absolutePath) throws IOException { | ||
Runtime runtime = Runtime.getRuntime(); | ||
runtime.exec("open -a Terminal " + absolutePath, null, new File(absolutePath)); | ||
} | ||
} |
Oops, something went wrong.
Would it be worth to create an interface, which all three classes have to implement? Then, it would be easier to see which method is available in one OS only and may trigger some documentation why some methods are needed only on Windows etc.