resolve symlinks before opening file
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / menu / MultiLevelMenu.java
index a10dabe..017872f 100755 (executable)
@@ -42,8 +42,9 @@ public class MultiLevelMenu implements MenuListener {
        public boolean addMenu(final File directory) {
                final int newMenuHorizontalIndex = menus.size();
 
-               if (newMenuHorizontalIndex >= VERTICAL_MENUS_COUNT)
+               if (newMenuHorizontalIndex >= VERTICAL_MENUS_COUNT) {
                        return false;
+               }
 
                final Menu menu = new Menu(directory);
                menu.addMenuListener(this);
@@ -85,8 +86,9 @@ public class MultiLevelMenu implements MenuListener {
        public int getMenuIndex(final Menu menu) {
                int i = 0;
                for (final Menu m : menus) {
-                       if (m == menu)
+                       if (m == menu) {
                                return i;
+                       }
                        i++;
                }
                return -1;
@@ -111,17 +113,28 @@ public class MultiLevelMenu implements MenuListener {
 
        @Override
        public void menuItemSelected(final Menu menu, final File chosenFile) {
-               if (chosenFile.isFile())
-                       if (chosenFile.canExecute())
+               if (chosenFile.isFile()) {
+                       if (chosenFile.canExecute()) {
                                executeCommand(chosenFile.getAbsolutePath());
-                       else {
-                               final boolean fileOpened = FileAssociationManager.openFile(chosenFile);
-                               if (fileOpened)
-                                       InstantLauncher.exitProgram();
+                       } else {
+                               boolean fileOpened;
+                               try {
+                                       fileOpened = FileAssociationManager.openFile(chosenFile.getCanonicalFile());
+                                       if (fileOpened) {
+                                               InstantLauncher.exitProgram();
+                                       }
+                               } catch (IOException e) {
+                                       e.printStackTrace();
+                               }
                        }
+               }
 
                if (chosenFile.isDirectory()) {
-                       executeCommand("nautilus", "-n", chosenFile.getAbsolutePath());
+                       try {
+                               executeCommand("nautilus", "-w", chosenFile.getCanonicalFile().getAbsolutePath());
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
                }
        }
 
@@ -137,10 +150,15 @@ public class MultiLevelMenu implements MenuListener {
 
        @Override
        public void menuItemSelectedAlternative(final Menu menu, final File chosenFile) {
-               if (chosenFile.isFile())
+               if (chosenFile.isFile()) {
                        chosenFile.setExecutable(!chosenFile.canExecute());
-               else {
-                       executeCommand("gnome-terminal", "--working-directory=" + chosenFile.getAbsolutePath());
+               } else {
+                       try {
+                               executeCommand("gnome-terminal", "--working-directory="
+                                               + chosenFile.getCanonicalFile().getAbsolutePath());
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
                }
        }
 
@@ -151,14 +169,19 @@ public class MultiLevelMenu implements MenuListener {
                        jPanel.removeAll();
                }
 
-               while (menus.size() > fromIndex)
+               while (menus.size() > fromIndex) {
                        menus.remove(fromIndex);
+               }
        }
 
        @Override
        public void menuItemSelectedAlternative2(Menu menu, File chosenFile) {
                if (chosenFile.isFile()) {
-                       executeCommand("emacs", chosenFile.getAbsolutePath());
+                       try {
+                               executeCommand("emacs", chosenFile.getCanonicalFile().getAbsolutePath());
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
                }
        }