From: David ‘Bombe’ Roden Date: Sun, 1 Jun 2008 03:09:43 +0000 (+0200) Subject: change context menu behaviour X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f468c04e54dd4b9c503cce3021dea62ee50ee65d;p=jSite2.git change context menu behaviour --- 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()); } /**