X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FFileManager.java;h=a9713429f9538859de250c7a34ae3dfb30ca0db2;hb=060d411e74835c5c2cdf39efde67f23313208e06;hp=c90614a9ff912dbc5be767a54700873c011dc324;hpb=190ec25604e1befa4400b0dc3b0297f55f98397f;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index c90614a..a971342 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -47,7 +47,6 @@ import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -68,6 +67,7 @@ import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.I18nable; import net.pterodactylus.jsite.i18n.gui.I18nAction; import net.pterodactylus.jsite.i18n.gui.I18nLabel; +import net.pterodactylus.jsite.i18n.gui.I18nMenu; import net.pterodactylus.jsite.project.FileOverride; import net.pterodactylus.jsite.project.Project; import net.pterodactylus.jsite.project.ProjectFile; @@ -150,8 +150,14 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /** The context menu for the tree. */ private JPopupMenu treeContextMenu; - /** The “insert” checkbox. */ - private JCheckBoxMenuItem insertCheckBoxMenuItem; + /** The “apply override” menu. */ + private I18nMenu overrideMenu; + + /** The “apply insert override” action. */ + private I18nAction applyInsertOverrideAction; + + /** The “apply mime type override” action. */ + private I18nAction applyMimeTypeOverrideAction; /** * Creates a new file manager. @@ -274,6 +280,26 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr /* TODO */ } }; + applyInsertOverrideAction = new I18nAction("fileManager.menu.item.applyInsertOverride") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + applyInsertOverride(); + } + }; + applyMimeTypeOverrideAction = new I18nAction("fileManager.menu.item.applyMimeTypeOverride") { + + /** + * {@inheritDoc} + */ + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + applyMimeTypeOverride(); + } + }; } /** @@ -282,8 +308,12 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr private void initComponents() { treeContextMenu = new JPopupMenu(); treeContextMenu.add(setDefaultFileAction); - insertCheckBoxMenuItem = new JCheckBoxMenuItem(insertAction); - treeContextMenu.add(insertCheckBoxMenuItem); + + overrideMenu = new I18nMenu("fileManager.menu.override"); + treeContextMenu.add(overrideMenu); + + overrideMenu.add(applyInsertOverrideAction); + overrideMenu.add(applyMimeTypeOverrideAction); JPanel contentPanel = new JPanel(new BorderLayout(12, 12)); contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); @@ -426,13 +456,25 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr return; } Point eventLocation = mouseEvent.getPoint(); - TreePath clickedPath = fileTree.getPathForLocation(eventLocation.x, eventLocation.y); - if (clickedPath == null) { - return; + 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; + } + } + if (selectedPaths.length == 1) { + ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPaths[0].getLastPathComponent(); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + setDefaultFileAction.setEnabled(!isHidden(projectFileWrapper) && projectFile.isFile() && !projectFile.getCompletePath().equals(project.getDefaultFile())); + } else { + setDefaultFileAction.setEnabled(false); } - fileTree.setSelectionPath(clickedPath); - ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) clickedPath.getLastPathComponent(); - insertCheckBoxMenuItem.setSelected(!isHidden(projectFileWrapper)); treeContextMenu.show(fileTree, eventLocation.x, eventLocation.y); } @@ -451,6 +493,44 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr return ((fileOverride == null) && projectFile.isHidden()) || ((fileOverride != null) && (fileOverride.isInsert())); } + /** + * Opens the “apply insert override” dialog and lets the user apply an + * override for the “insert” setting for multiple files. + */ + private void applyInsertOverride() { + JCheckBox insertCheckBox = new JCheckBox(I18n.get("fileManager.checkbox.insertFile.name")); + String okString = I18n.get("general.button.okay.name"); + String cancelString = I18n.get("general.button.cancel.name"); + int choice = JOptionPane.showOptionDialog(this, new Object[] { I18n.get("fileManager.dialog.insertOverride.message"), insertCheckBox }, I18n.get("fileManager.dialog.insertOverride.title"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[] { okString, cancelString }, okString); + logger.log(Level.FINEST, "choice: " + choice); + if ((choice == JOptionPane.CLOSED_OPTION) || (choice == 1)) { + return; + } + logger.log(Level.INFO, "selected insert override: " + insertCheckBox.isSelected()); + TreePath[] selectedPaths = fileTree.getSelectionPaths(); + for (TreePath selectedPath: selectedPaths) { + ProjectFileWrapper projectFileWrapper = (ProjectFileWrapper) selectedPath.getLastPathComponent(); + ProjectFile projectFile = projectFileWrapper.getProjectFile(); + if (!projectFile.isFile()) { + continue; + } + FileOverride fileOverride = project.getFileOverride(projectFile); + if (fileOverride == null) { + fileOverride = new FileOverride(); + project.addFileOverride(projectFile, fileOverride); + } + fileOverride.setInsert(insertCheckBox.isSelected()); + } + } + + /** + * Opens the “apply mime type override” dialog and lets the user apply an + * override for the “mime type” setting for multiple files. + */ + private void applyMimeTypeOverride() { + /* TODO */ + } + // // INTERFACE I18nable // @@ -496,6 +576,8 @@ public class FileManager extends JDialog implements I18nable, ActionListener, Tr fileNameTextField.setText(projectFile.getName()); fileSizeTextField.setText(String.valueOf(projectFile.getSize())); } + } else if ((selectedPaths != null) && (selectedPaths.length > 1)) { + /* TODO */ } }