change context menu behaviour
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 1 Jun 2008 03:09:43 +0000 (05:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 1 Jun 2008 03:09:43 +0000 (05:09 +0200)
src/net/pterodactylus/jsite/gui/FileManager.java

index 34b07a3..dc0becd 100644 (file)
@@ -28,7 +28,6 @@ import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
-import java.awt.Point;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
@@ -472,27 +471,20 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr
                if (!mouseEvent.isPopupTrigger()) {
                        return;
                }
-               Point eventLocation = mouseEvent.getPoint();
-               TreePath[] selectedPaths = fileTree.getSelectionPaths();
-               if ((selectedPaths == null) || (selectedPaths.length == 0)) {
-                       /* try to find item under click. */
-                       TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
-                       if (clickedPath != null) {
-                               fileTree.setSelectionPath(clickedPath);
-                               selectedPaths = new TreePath[] { clickedPath };
-                       } else {
-                               logger.log(Level.FINER, "nothing selected for context menu");
-                               return;
-                       }
+               List<ProjectFileWrapper> selectedProjectFileWrappers = getSelectedProjectFileWrappers(false);
+               TreePath clickedPath = fileTree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
+               ProjectFileWrapper clickedProjectFileWrapper = (ProjectFileWrapper) clickedPath.getLastPathComponent();
+               if (!selectedProjectFileWrappers.contains(clickedProjectFileWrapper)) {
+                       fileTree.setSelectionPath(clickedPath);
                }
-               if (selectedPaths.length == 1) {
-                       ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPaths[0].getLastPathComponent();
+               if (selectedProjectFileWrappers.size() == 1) {
+                       ProjectFileWrapper projectFileWrapper = selectedProjectFileWrappers.get(0);
                        ProjectFile projectFile = projectFileWrapper.getProjectFile();
                        setDefaultFileAction.setEnabled(!isHidden(projectFileWrapper) && projectFile.isFile() && !projectFile.getCompletePath().equals(project.getDefaultFile()));
                } else {
                        setDefaultFileAction.setEnabled(false);
                }
-               treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y);
+               treeContextMenu.show(fileTree, mouseEvent.getX(), mouseEvent.getY());
        }
 
        /**