From 617c93e31fc6f020323b503fe0028a8e10c746b6 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 20 Nov 2016 23:10:18 +0200 Subject: [PATCH] Possibility to configure terminal emulator. --- .../instantlauncher/InstantLauncher.java | 13 ++++-------- .../eu/svjatoslav/instantlauncher/Utils.java | 19 ++++++++++------- .../configuration/Configuration.java | 1 + .../configuration/ConfigurationManager.java | 1 + .../svjatoslav/instantlauncher/menu/Menu.java | 6 +++--- .../instantlauncher/menu/MultiLevelMenu.java | 21 +++++++------------ 6 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/main/java/eu/svjatoslav/instantlauncher/InstantLauncher.java b/src/main/java/eu/svjatoslav/instantlauncher/InstantLauncher.java index bb8681e..ae6ce50 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/InstantLauncher.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/InstantLauncher.java @@ -40,16 +40,11 @@ public class InstantLauncher { } public void openDirectory(File chosenFile) { - executeCommand(configurationManager.getConfiguration().directoryOpenCommand, chosenFile.getAbsolutePath()); + runOpeningApplication(configurationManager.getConfiguration().directoryOpenCommand, chosenFile); } - public void executeCommand(String... c) { - try { - Runtime.getRuntime().exec(c); - exitProgram(); - - } catch (final IOException e) { - new ExceptionDialog(e); - } + public void openDirectoryInTerminal(File chosenFile) { + runOpeningApplication(configurationManager.getConfiguration().directoryTerminalOpenCommand, chosenFile); } + } diff --git a/src/main/java/eu/svjatoslav/instantlauncher/Utils.java b/src/main/java/eu/svjatoslav/instantlauncher/Utils.java index 297f010..506feaa 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/Utils.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/Utils.java @@ -19,19 +19,24 @@ public class Utils { } public static void runOpeningApplication(String commands, final File file) { - runOpeningApplication(commands.split("\\s+"), file); - } + try { + String[] commandsArray = commands.split("\\s+"); + for (int i=0; i< commandsArray.length; i++) + commandsArray[i] = commandsArray[i].replaceAll("\\{file\\}", file.getAbsolutePath()); - private static void runOpeningApplication(final String[] commands, final File file) { - for (int i = 0; i < commands.length; i++) - if (commands[i].equals(FILE_INDICATOR)) - commands[i] = file.getAbsolutePath(); + Runtime.getRuntime().exec(commandsArray); + } catch (final IOException e) { + new ExceptionDialog(e); + } + } + public static void executeCommand(String... c) { try { - Runtime.getRuntime().exec(commands); + Runtime.getRuntime().exec(c); } catch (final IOException e) { new ExceptionDialog(e); } } + } diff --git a/src/main/java/eu/svjatoslav/instantlauncher/configuration/Configuration.java b/src/main/java/eu/svjatoslav/instantlauncher/configuration/Configuration.java index 4a5b0dd..9b320ed 100644 --- a/src/main/java/eu/svjatoslav/instantlauncher/configuration/Configuration.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/configuration/Configuration.java @@ -7,6 +7,7 @@ public class Configuration { public Set fileAssociations; public String navigationRootPath; public String directoryOpenCommand; + public String directoryTerminalOpenCommand; public FileAssociation findFileAssociation(File file) { for (FileAssociation association : fileAssociations) diff --git a/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java b/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java index 8e13042..3d2988b 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java @@ -56,6 +56,7 @@ public class ConfigurationManager { configuration.navigationRootPath = System.getProperty("user.home") + "/"; configuration.directoryOpenCommand = "nautilus -w {file}"; + configuration.directoryTerminalOpenCommand = "gnome-terminal --working-directory={file}"; registerFileAssociation(".*\\.jpeg$", "eog {file}"); registerFileAssociation(".*\\.jpg$", "eog {file}"); diff --git a/src/main/java/eu/svjatoslav/instantlauncher/menu/Menu.java b/src/main/java/eu/svjatoslav/instantlauncher/menu/Menu.java index 8456745..252abbf 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/menu/Menu.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/menu/Menu.java @@ -183,11 +183,11 @@ class Menu { public void mouseClicked(final MouseEvent e) { try { - if (e.getButton() == 1) + if (e.getButton() == 1) // left mouse click parentMenu.menuItemSelected(file); - if (e.getButton() == 2) + if (e.getButton() == 2) // middle mouse click parentMenu.menuItemSelectedAlternative2(file); - if (e.getButton() == 3) + if (e.getButton() == 3) //right mouse click parentMenu.menuItemSelectedAlternative(file); } catch (final Exception ex) { new ExceptionDialog(ex); diff --git a/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java b/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java index 3297259..de2e4c5 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/menu/MultiLevelMenu.java @@ -9,6 +9,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import static eu.svjatoslav.instantlauncher.Utils.executeCommand; + public class MultiLevelMenu implements MenuListener { private static final int VERTICAL_MENUS_COUNT = 7; @@ -105,7 +107,7 @@ public class MultiLevelMenu implements MenuListener { public void menuItemSelected(final File chosenFile) { if (chosenFile.isFile()) { if (chosenFile.canExecute()) { - instantLauncher.executeCommand(chosenFile.getAbsolutePath()); + executeCommand(chosenFile.getAbsolutePath()); } else { boolean fileOpened; try { @@ -122,6 +124,7 @@ public class MultiLevelMenu implements MenuListener { if (chosenFile.isDirectory()) { try { instantLauncher.openDirectory(chosenFile.getCanonicalFile()); + InstantLauncher.exitProgram(); } catch (IOException e) { e.printStackTrace(); } @@ -133,12 +136,8 @@ public class MultiLevelMenu implements MenuListener { if (chosenFile.isFile()) chosenFile.setExecutable(!chosenFile.canExecute()); else { - try { - instantLauncher.executeCommand("gnome-terminal", "--working-directory=" - + chosenFile.getCanonicalFile().getAbsolutePath()); - } catch (IOException e) { - e.printStackTrace(); - } + instantLauncher.openDirectoryInTerminal(chosenFile); + InstantLauncher.exitProgram(); } } @@ -156,13 +155,7 @@ public class MultiLevelMenu implements MenuListener { @Override public void menuItemSelectedAlternative2(File chosenFile) { - if (chosenFile.isFile()) { - try { - instantLauncher.executeCommand("emacs", chosenFile.getCanonicalFile().getAbsolutePath()); - } catch (IOException e) { - e.printStackTrace(); - } - } + // TODO: define some middle mouse click functions } -- 2.20.1