right click on directory opens it in terminal
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / menu / MultiLevelMenu.java
index fa200da..700f842 100755 (executable)
@@ -20,7 +20,7 @@ public class MultiLevelMenu implements MenuListener {
 
     private final InstantLauncher instantLauncher;
 
-    private static final int VERTICAL_MENUS_COUNT = 5;
+    private static final int VERTICAL_MENUS_COUNT = 7;
 
     public static final Dimension CONTENT_PANEL_SIZE = new Dimension(1024, 900);
 
@@ -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();
@@ -120,20 +123,14 @@ public class MultiLevelMenu implements MenuListener {
                     Runtime.getRuntime().exec(c);
                     InstantLauncher.exitProgram();
                 } catch (final IOException e) {
-                    ExceptionDialog.showException(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();
@@ -147,10 +144,29 @@ public class MultiLevelMenu implements MenuListener {
                 InstantLauncher.exitProgram();
 
             } catch (final IOException e) {
-                ExceptionDialog.showException(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);
-        }
     }
 
 }