X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FFileManager.java;h=cdfc9d1d6e2475efbfe9b0ee14c4b80ff52fcb11;hb=c60034ea2b17fcd3d835de8e854c460325baa031;hp=9a3a758279faf35fdfe72313d72559e4b2eefe90;hpb=ee76b8ccdc96c88a6d24094cfe06306de3f66381;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index 9a3a758..cdfc9d1 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; @@ -107,9 +106,6 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The “set default file” action. */ private I18nAction setDefaultFileAction; - /** The “insert” action. */ - private I18nAction insertAction; - /** The “project files” label. */ private I18nLabel projectFilesLabel; @@ -141,13 +137,7 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private JTextField fileSizeTextField; /** The “override” label. */ - private I18nLabel overrideLabel; - - /** The “override active” action. */ - private I18nAction overrideAction; - - /** The “override action” checkbox. */ - private JCheckBox overrideCheckBox; + private I18nLabel fileSettingsLabel; /** The context menu for the tree. */ private JPopupMenu treeContextMenu; @@ -267,24 +257,6 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr project.setDefaultFile(completePath); } }; - insertAction = new I18nAction("fileManager.menu.item.insert") { - - /** - * {@inheritDoc} - */ - public void actionPerformed(ActionEvent e) { - /* TODO */ - } - }; - overrideAction = new I18nAction("fileManager.checkbox.overrideActive") { - - /** - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - public void actionPerformed(ActionEvent actionEvent) { - /* TODO */ - } - }; applyInsertOverrideAction = new I18nAction("fileManager.menu.item.applyInsertOverride") { /** @@ -399,15 +371,12 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr propertiesPanel.add(fileSizeTextField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); /* override settings. */ - overrideLabel = new I18nLabel("fileManager.label.override"); - overrideLabel.setFont(overrideLabel.getFont().deriveFont(Font.BOLD)); - propertiesPanel.add(overrideLabel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); - - overrideCheckBox = new JCheckBox(overrideAction); - propertiesPanel.add(overrideCheckBox, new GridBagConstraints(0, 5, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 24, 0, 0), 0, 0)); + fileSettingsLabel = new I18nLabel("fileManager.label.fileSettings"); + fileSettingsLabel.setFont(fileSettingsLabel.getFont().deriveFont(Font.BOLD)); + propertiesPanel.add(fileSettingsLabel, new GridBagConstraints(0, 4, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(24, 0, 0, 0), 0, 0)); /* glue panel. */ - propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 6, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); + propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 7, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); /* action button panel */ JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12)); @@ -472,27 +441,22 @@ 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); + selectedProjectFileWrappers = getSelectedProjectFileWrappers(false); } - 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); + overrideMenu.setVisible(selectedProjectFileWrappers.size() > 1); + treeContextMenu.show(fileTree, mouseEvent.getX(), mouseEvent.getY()); } /** @@ -591,12 +555,14 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private List getSelectedProjectFileWrappers(boolean filesOnly) { List selectedProjectFileWrappers = new ArrayList(); TreePath[] selectedPaths = fileTree.getSelectionPaths(); - for (TreePath selectedPath : selectedPaths) { - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent(); - if (filesOnly && !projectFileWrapper.getProjectFile().isFile()) { - continue; + if (selectedPaths != null) { + for (TreePath selectedPath : selectedPaths) { + ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent(); + if (filesOnly && !projectFileWrapper.getProjectFile().isFile()) { + continue; + } + selectedProjectFileWrappers.add(projectFileWrapper); } - selectedProjectFileWrappers.add(projectFileWrapper); } return selectedProjectFileWrappers; } @@ -627,7 +593,6 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr filePathTextField.setText(""); fileNameTextField.setText(""); fileSizeTextField.setText(""); - overrideAction.setEnabled(false); if ((selectedPaths != null) && (selectedPaths.length == 1)) { Object lastPathComponent = selectedPaths[0].getLastPathComponent(); if (!(lastPathComponent instanceof ProjectFileWrapper)) { @@ -647,8 +612,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr fileNameTextField.setText(projectFile.getName()); fileSizeTextField.setText(String.valueOf(projectFile.getSize())); } - overrideAction.setEnabled(true); } else if ((selectedPaths != null) && (selectedPaths.length > 1)) { + /* TODO */ } }