From 034b47ccdba41c3f087eb82d2fb27769511920d2 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 27 Jul 2015 13:44:40 +0000 Subject: [PATCH] * allow users to test custom file filter right away from within the Preset Editor --- .../net/filebot/ui/rename/BindingDialog.java | 26 +++++++++-- .../net/filebot/ui/rename/PresetEditor.java | 46 +++++++++++++++++-- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/ui/rename/BindingDialog.java b/source/net/filebot/ui/rename/BindingDialog.java index 1766e625..86250aba 100644 --- a/source/net/filebot/ui/rename/BindingDialog.java +++ b/source/net/filebot/ui/rename/BindingDialog.java @@ -98,8 +98,12 @@ class BindingDialog extends JDialog { root.add(new JLabel("Preview:"), "gap 5px, wrap 2px"); root.add(new JScrollPane(createBindingTable(bindingModel)), "growx, wrap paragraph:push"); - root.add(new JButton(approveAction), "tag apply"); - root.add(new JButton(cancelAction), "tag cancel"); + if (editable) { + root.add(new JButton(approveAction), "tag apply"); + root.add(new JButton(cancelAction), "tag cancel"); + } else { + root.add(new JButton(okAction), "tag apply"); + } // update preview on change DocumentListener changeListener = new LazyDocumentListener(1000) { @@ -244,6 +248,14 @@ class BindingDialog extends JDialog { return file.isAbsolute() ? file : null; } + protected final Action hideAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { + + @Override + public void actionPerformed(ActionEvent evt) { + finish(true); + } + }; + protected final Action approveAction = new AbstractAction("Use Bindings", ResourceManager.getIcon("dialog.continue")) { @Override @@ -262,7 +274,7 @@ class BindingDialog extends JDialog { } }; - protected final Action cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { + protected final Action okAction = new AbstractAction("OK") { @Override public void actionPerformed(ActionEvent evt) { @@ -270,6 +282,14 @@ class BindingDialog extends JDialog { } }; + protected final Action cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { + + @Override + public void actionPerformed(ActionEvent evt) { + finish(false); + } + }; + protected final Action mediaInfoAction = new AbstractAction("Open MediaInfo", ResourceManager.getIcon("action.properties")) { private Map>> getMediaInfo(File file) { diff --git a/source/net/filebot/ui/rename/PresetEditor.java b/source/net/filebot/ui/rename/PresetEditor.java index 8e7bec1c..5c0e29f8 100644 --- a/source/net/filebot/ui/rename/PresetEditor.java +++ b/source/net/filebot/ui/rename/PresetEditor.java @@ -12,6 +12,7 @@ import java.awt.event.ActionEvent; import java.io.File; import java.util.EnumSet; import java.util.List; +import java.util.logging.Level; import javax.swing.AbstractAction; import javax.swing.Action; @@ -23,7 +24,9 @@ import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JList; +import javax.swing.JMenuItem; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.ListCellRenderer; @@ -98,8 +101,9 @@ public class PresetEditor extends JDialog { inputPanel.add(new JLabel("Input Folder:"), "gap indent"); inputPanel.add(pathInput, "growx, gap rel"); inputPanel.add(createImageButton(selectInputFolder), "gap 0px, wrap"); - inputPanel.add(new JLabel("Includes:"), "gap indent, skip 1, split 2"); - inputPanel.add(wrapEditor(filterEditor), "growx, gap rel, gap after 40px"); + inputPanel.add(new JLabel("Includes:"), "gap indent, skip 1, split 3"); + inputPanel.add(wrapEditor(filterEditor), "growx, gap rel"); + inputPanel.add(createImageButton(listFiles), "gap rel"); JPanel inputGroup = createGroupPanel("Files"); inputGroup.add(selectRadio); @@ -361,6 +365,42 @@ public class PresetEditor extends JDialog { } }; + private final Action listFiles = new AbstractAction("List Files", ResourceManager.getIcon("action.list")) { + + private JMenuItem createListItem(ActionEvent evt, File f) { + JMenuItem m = new JMenuItem(f.getPath()); + m.addActionListener((e) -> { + BindingDialog dialog = new BindingDialog(getWindow(evt.getSource()), "File Bindings", FormatDialog.Mode.File.getFormat(), false); + dialog.setLocation(getOffsetLocation(getWindow(evt.getSource()))); + dialog.setInfoObject(f); + dialog.setMediaFile(f); + dialog.setVisible(true); + }); + return m; + } + + @Override + public void actionPerformed(ActionEvent evt) { + try { + List selectInputFiles = getPreset().selectInputFiles(evt); + + JPopupMenu popup = new JPopupMenu(); + if (selectInputFiles == null || selectInputFiles.isEmpty()) { + popup.add("No files selected").setEnabled(false); + } else { + for (File file : selectInputFiles) { + popup.add(createListItem(evt, file)); + } + } + + JComponent source = (JComponent) evt.getSource(); + popup.show(source, -3, source.getHeight() + 4); + } catch (Exception e) { + UILogger.log(Level.WARNING, "Invalid preset settings: " + e.getMessage(), e); + } + } + }; + private final Action ok = new AbstractAction("Preset", ResourceManager.getIcon("dialog.continue")) { @Override @@ -372,7 +412,7 @@ public class PresetEditor extends JDialog { setVisible(false); } } catch (Exception e) { - UILogger.severe("Invalid preset settings: " + e.getMessage()); + UILogger.log(Level.WARNING, "Invalid preset settings: " + e.getMessage(), e); } } };