mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-02 08:25:02 -04:00
* refactor
This commit is contained in:
parent
a8aeee2193
commit
f97b040dda
@ -18,6 +18,10 @@ public class ExpressionFileFilter implements FileFilter {
|
||||
this.errorResult = errorResult;
|
||||
}
|
||||
|
||||
public ExpressionFilter getExpressionFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
try {
|
||||
|
@ -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<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() {
|
||||
EpisodeListProvider sdb = WebServices.getEpisodeListProvider(database);
|
||||
if (sdb != null) {
|
||||
|
@ -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());
|
||||
|
@ -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<File> getFiles(ActionEvent evt) {
|
||||
List<File> input = new ArrayList<File>();
|
||||
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<File> input = preset.selectInputFiles(evt);
|
||||
|
||||
if (input != null) {
|
||||
renameModel.clear();
|
||||
renameModel.files().addAll(input);
|
||||
} else {
|
||||
input.addAll(super.getFiles(evt));
|
||||
input = new ArrayList<File>(super.getFiles(evt));
|
||||
}
|
||||
|
||||
if (input.isEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user