1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-17 23:05:03 -05:00

* refactor

This commit is contained in:
Reinhard Pointner 2015-07-27 12:40:55 +00:00
parent a8aeee2193
commit f97b040dda
4 changed files with 40 additions and 17 deletions

View File

@ -18,6 +18,10 @@ public class ExpressionFileFilter implements FileFilter {
this.errorResult = errorResult; this.errorResult = errorResult;
} }
public ExpressionFilter getExpressionFilter() {
return filter;
}
@Override @Override
public boolean accept(File f) { public boolean accept(File f) {
try { try {

View File

@ -1,13 +1,21 @@
package net.filebot.ui.rename; 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.io.File;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import net.filebot.Language; import net.filebot.Language;
import net.filebot.Settings;
import net.filebot.StandardRenameAction; import net.filebot.StandardRenameAction;
import net.filebot.WebServices; import net.filebot.WebServices;
import net.filebot.format.ExpressionFilter; import net.filebot.format.ExpressionFilter;
import net.filebot.format.ExpressionFormat; import net.filebot.format.ExpressionFormat;
import net.filebot.mac.MacAppUtilities;
import net.filebot.util.FileUtilities;
import net.filebot.web.Datasource; import net.filebot.web.Datasource;
import net.filebot.web.EpisodeListProvider; import net.filebot.web.EpisodeListProvider;
import net.filebot.web.MovieIdentificationService; import net.filebot.web.MovieIdentificationService;
@ -46,9 +54,9 @@ public class Preset {
return path == null || path.isEmpty() ? null : new File(path); return path == null || path.isEmpty() ? null : new File(path);
} }
public ExpressionFilter getIncludeFilter() { public ExpressionFileFilter getIncludeFilter() {
try { 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) { } catch (Exception e) {
return null; return null;
} }
@ -62,6 +70,27 @@ public class Preset {
} }
} }
public List<File> 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<File> files = FileUtilities.listFiles(getInputFolder());
if (filter != null) {
files = FileUtilities.filter(files, filter);
}
return files;
}
public AutoCompleteMatcher getAutoCompleteMatcher() { public AutoCompleteMatcher getAutoCompleteMatcher() {
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database); EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database);
if (sdb != null) { if (sdb != null) {

View File

@ -155,7 +155,7 @@ public class PresetEditor extends JDialog {
public void setPreset(Preset p) { public void setPreset(Preset p) {
presetNameHeader.getTitleLabel().setText(p.getName()); presetNameHeader.getTitleLabel().setText(p.getName());
pathInput.setText(p.getInputFolder() == null ? "" : p.getInputFolder().getPath()); 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()); formatEditor.setText(p.getFormat() == null ? "" : p.getFormat().getExpression());
providerCombo.setSelectedItem(p.getDatasource() == null ? WebServices.TheTVDB : p.getDatasource()); providerCombo.setSelectedItem(p.getDatasource() == null ? WebServices.TheTVDB : p.getDatasource());
sortOrderCombo.setSelectedItem(p.getSortOrder() == null ? SortOrder.Airdate : p.getSortOrder()); sortOrderCombo.setSelectedItem(p.getSortOrder() == null ? SortOrder.Airdate : p.getSortOrder());

View File

@ -430,7 +430,6 @@ public class RenamePanel extends JComponent {
case SET: case SET:
preset = presetEditor.getPreset(); preset = presetEditor.getPreset();
persistentPresets.put(selection, JsonWriter.objectToJson(preset)); persistentPresets.put(selection, JsonWriter.objectToJson(preset));
new ApplyPresetAction(preset).actionPerformed(evt);
break; break;
case DELETE: case DELETE:
persistentPresets.remove(selection); persistentPresets.remove(selection);
@ -698,22 +697,13 @@ public class RenamePanel extends JComponent {
@Override @Override
public List<File> getFiles(ActionEvent evt) { public List<File> getFiles(ActionEvent evt) {
List<File> input = new ArrayList<File>(); List<File> input = preset.selectInputFiles(evt);
if (preset.getInputFolder() != null) {
if (isMacSandbox()) { if (input != null) {
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));
}
renameModel.clear(); renameModel.clear();
renameModel.files().addAll(input); renameModel.files().addAll(input);
} else { } else {
input.addAll(super.getFiles(evt)); input = new ArrayList<File>(super.getFiles(evt));
} }
if (input.isEmpty()) { if (input.isEmpty()) {