From f468c04e54dd4b9c503cce3021dea62ee50ee65d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 1 Jun 2008 05:09:43 +0200 Subject: [PATCH] change context menu behaviour --- src/net/pterodactylus/jsite/gui/FileManager.java | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 34b07a3..dc0becd 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -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 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()); } /** -- 2.7.4