From f97b040dda9cfd9d3a189f7d1d5326fb934fdc8a Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 27 Jul 2015 12:40:55 +0000 Subject: [PATCH] * refactor --- .../ui/rename/ExpressionFileFilter.java | 4 +++ source/net/filebot/ui/rename/Preset.java | 33 +++++++++++++++++-- .../net/filebot/ui/rename/PresetEditor.java | 2 +- source/net/filebot/ui/rename/RenamePanel.java | 18 +++------- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/source/net/filebot/ui/rename/ExpressionFileFilter.java b/source/net/filebot/ui/rename/ExpressionFileFilter.java index 8c642e82..0e1b447b 100644 --- a/source/net/filebot/ui/rename/ExpressionFileFilter.java +++ b/source/net/filebot/ui/rename/ExpressionFileFilter.java @@ -18,6 +18,10 @@ public class ExpressionFileFilter implements FileFilter { this.errorResult = errorResult; } + public ExpressionFilter getExpressionFilter() { + return filter; + } + @Override public boolean accept(File f) { try { diff --git a/source/net/filebot/ui/rename/Preset.java b/source/net/filebot/ui/rename/Preset.java index 0335c25b..0f060b5d 100644 --- a/source/net/filebot/ui/rename/Preset.java +++ b/source/net/filebot/ui/rename/Preset.java @@ -1,13 +1,21 @@ package net.filebot.ui.rename; +import static java.util.Collections.*; +import static net.filebot.util.ui.SwingUI.*; + +import java.awt.event.ActionEvent; import java.io.File; +import java.util.List; import java.util.Locale; import net.filebot.Language; +import net.filebot.Settings; import net.filebot.StandardRenameAction; import net.filebot.WebServices; import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFormat; +import net.filebot.mac.MacAppUtilities; +import net.filebot.util.FileUtilities; import net.filebot.web.Datasource; import net.filebot.web.EpisodeListProvider; import net.filebot.web.MovieIdentificationService; @@ -46,9 +54,9 @@ public class Preset { return path == null || path.isEmpty() ? null : new File(path); } - public ExpressionFilter getIncludeFilter() { + public ExpressionFileFilter getIncludeFilter() { try { - return includes == null || includes.isEmpty() ? null : new ExpressionFilter(includes); + return path == null || path.isEmpty() || includes == null || includes.isEmpty() ? null : new ExpressionFileFilter(new ExpressionFilter(includes), false); } catch (Exception e) { return null; } @@ -62,6 +70,27 @@ public class Preset { } } + public List selectInputFiles(ActionEvent evt) { + File folder = getInputFolder(); + ExpressionFileFilter filter = getIncludeFilter(); + + if (folder == null) { + return null; + } + + if (Settings.isMacSandbox()) { + if (!MacAppUtilities.askUnlockFolders(getWindow(evt.getSource()), singleton(getInputFolder()))) { + throw new IllegalStateException("Unable to access folder: " + folder); + } + } + + List files = FileUtilities.listFiles(getInputFolder()); + if (filter != null) { + files = FileUtilities.filter(files, filter); + } + return files; + } + public AutoCompleteMatcher getAutoCompleteMatcher() { EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database); if (sdb != null) { diff --git a/source/net/filebot/ui/rename/PresetEditor.java b/source/net/filebot/ui/rename/PresetEditor.java index 00929e19..8e7bec1c 100644 --- a/source/net/filebot/ui/rename/PresetEditor.java +++ b/source/net/filebot/ui/rename/PresetEditor.java @@ -155,7 +155,7 @@ public class PresetEditor extends JDialog { public void setPreset(Preset p) { presetNameHeader.getTitleLabel().setText(p.getName()); pathInput.setText(p.getInputFolder() == null ? "" : p.getInputFolder().getPath()); - filterEditor.setText(p.getIncludeFilter() == null ? "" : p.getIncludeFilter().getExpression()); + filterEditor.setText(p.getIncludeFilter() == null ? "" : p.getIncludeFilter().getExpressionFilter().getExpression()); formatEditor.setText(p.getFormat() == null ? "" : p.getFormat().getExpression()); providerCombo.setSelectedItem(p.getDatasource() == null ? WebServices.TheTVDB : p.getDatasource()); sortOrderCombo.setSelectedItem(p.getSortOrder() == null ? SortOrder.Airdate : p.getSortOrder()); diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index e22ab6a3..29becf59 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -430,7 +430,6 @@ public class RenamePanel extends JComponent { case SET: preset = presetEditor.getPreset(); persistentPresets.put(selection, JsonWriter.objectToJson(preset)); - new ApplyPresetAction(preset).actionPerformed(evt); break; case DELETE: persistentPresets.remove(selection); @@ -698,22 +697,13 @@ public class RenamePanel extends JComponent { @Override public List getFiles(ActionEvent evt) { - List input = new ArrayList(); - if (preset.getInputFolder() != null) { - if (isMacSandbox()) { - if (!MacAppUtilities.askUnlockFolders(getWindow(RenamePanel.this), singleton(preset.getInputFolder()))) { - throw new IllegalStateException("Unable to access folder: " + preset.getInputFolder()); - } - } - input.addAll(FileUtilities.listFiles(preset.getInputFolder())); - ExpressionFilter filter = preset.getIncludeFilter(); - if (filter != null) { - input = FileUtilities.filter(input, new ExpressionFileFilter(filter, false)); - } + List input = preset.selectInputFiles(evt); + + if (input != null) { renameModel.clear(); renameModel.files().addAll(input); } else { - input.addAll(super.getFiles(evt)); + input = new ArrayList(super.getFiles(evt)); } if (input.isEmpty()) {