right click on directory opens it in terminal
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / menu / MultiLevelMenu.java
index 308f5ba..700f842 100755 (executable)
@@ -93,7 +93,7 @@ public class MultiLevelMenu implements MenuListener {
     }
 
     @Override
-    public void menuItemSelected(final Menu menu, final File chosenFile) {
+    public void menuItemHighlighted(final Menu menu, final File chosenFile) {
 
         if (chosenFile.isDirectory()) {
             final int menuIndex = getMenuIndex(menu);
@@ -107,9 +107,12 @@ public class MultiLevelMenu implements MenuListener {
             }
         }
 
-        if (chosenFile.isFile()) {
+    }
 
-            if (chosenFile.canExecute()) {
+    @Override
+    public void menuItemSelected(final Menu menu, final File chosenFile) {
+        if (chosenFile.isFile())
+            if (chosenFile.canExecute())
                 try {
                     // Execute a command without arguments
                     final String command = chosenFile.getAbsolutePath();
@@ -122,18 +125,12 @@ public class MultiLevelMenu implements MenuListener {
                 } catch (final IOException e) {
                     new ExceptionDialog(e);
                 }
-
-            } else {
+            else {
                 final boolean fileOpened = FileAssociationManager.openFile(chosenFile);
-                if (fileOpened) {
+                if (fileOpened)
                     InstantLauncher.exitProgram();
-                }
             }
-        }
-    }
 
-    @Override
-    public void menuItemSelectedAlternative(final Menu menu, final File chosenFile) {
         if (chosenFile.isDirectory()) {
             // Execute a command without arguments
             final String directoryPath = chosenFile.getAbsolutePath();
@@ -149,8 +146,27 @@ public class MultiLevelMenu implements MenuListener {
             } catch (final IOException e) {
                 new ExceptionDialog(e);
             }
-        } else {
+        }
+    }
+
+    @Override
+    public void menuItemSelectedAlternative(final Menu menu, final File chosenFile) {
+        if (chosenFile.isFile())
             chosenFile.setExecutable(!chosenFile.canExecute());
+        else {
+            // Execute a command without arguments
+            final String[] c = new String[2];
+
+            c[0] = "gnome-terminal";
+            c[1] = "--working-directory=" + chosenFile.getAbsolutePath();
+
+            try {
+                Runtime.getRuntime().exec(c);
+                InstantLauncher.exitProgram();
+
+            } catch (final IOException e) {
+                new ExceptionDialog(e);
+            }
         }
     }
 
@@ -161,9 +177,8 @@ public class MultiLevelMenu implements MenuListener {
             jPanel.removeAll();
         }
 
-        while (menus.size() > fromIndex) {
+        while (menus.size() > fromIndex)
             menus.remove(fromIndex);
-        }
     }
 
 }