1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00

* properly deal with FileDialog user preferences

This commit is contained in:
Reinhard Pointner 2014-07-29 08:43:54 +00:00
parent a7e67974a2
commit cc4f257a8b
13 changed files with 159 additions and 133 deletions

View File

@ -111,4 +111,6 @@ public class MediaTypes {
public static final ExtensionFileFilter VERIFICATION_FILES = getDefaultFilter("verification"); public static final ExtensionFileFilter VERIFICATION_FILES = getDefaultFilter("verification");
public static final ExtensionFileFilter NFO_FILES = getDefaultFilter("application/nfo"); public static final ExtensionFileFilter NFO_FILES = getDefaultFilter("application/nfo");
public static final ExtensionFileFilter LIST_FILES = getDefaultFilter("application/list"); public static final ExtensionFileFilter LIST_FILES = getDefaultFilter("application/list");
public static final ExtensionFileFilter TORRENT_FILES = getDefaultFilter("application/torrent");
} }

View File

@ -1,6 +1,7 @@
package net.filebot; package net.filebot;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
@ -8,11 +9,12 @@ import java.awt.Dialog;
import java.awt.FileDialog; import java.awt.FileDialog;
import java.awt.Frame; import java.awt.Frame;
import java.io.File; import java.io.File;
import java.io.FilenameFilter;
import java.util.List; import java.util.List;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
public class UserFiles { public class UserFiles {
private static FileChooser defaultFileChooser = getPreferredFileChooser(); private static FileChooser defaultFileChooser = getPreferredFileChooser();
@ -21,12 +23,20 @@ public class UserFiles {
defaultFileChooser = fileChooser; defaultFileChooser = fileChooser;
} }
public static List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, final FilenameFilter filter, String title, Object parent) { public static List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
return defaultFileChooser.showLoadDialogSelectFiles(folderMode, multiSelection, defaultFile, filter, title, parent); List<File> files = defaultFileChooser.showLoadDialogSelectFiles(folderMode, multiSelection, getFileChooserDefaultFile(KEY_OPEN, defaultFile), filter, title, parent);
if (files.size() > 0) {
setFileChooserDefaultFile(KEY_OPEN, files.get(0));
}
return files;
} }
public static File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) { public static File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
return defaultFileChooser.showSaveDialogSelectFile(folderMode, defaultFile, title, parent); File file = defaultFileChooser.showSaveDialogSelectFile(folderMode, getFileChooserDefaultFile(KEY_SAVE, defaultFile), title, parent);
if (file != null) {
setFileChooserDefaultFile(KEY_SAVE, file);
}
return file;
} }
public static File showOpenDialogSelectFolder(File defaultFile, String title, Object parent) { public static File showOpenDialogSelectFolder(File defaultFile, String title, Object parent) {
@ -34,30 +44,40 @@ public class UserFiles {
return folder.size() > 0 ? folder.get(0) : null; return folder.size() > 0 ? folder.get(0) : null;
} }
private static final String PREF_KEY_PREFIX = "file.dialog.";
private static final String KEY_OPEN = "open";
private static final String KEY_SAVE = "save";
protected static File getFileChooserDefaultFile(String name, File userValue) {
if (userValue != null && userValue.getParentFile() != null)
return userValue;
String path = Settings.forPackage(UserFiles.class).get(PREF_KEY_PREFIX + name);
if (path == null || path.isEmpty())
return userValue;
if (userValue != null && userValue.getParentFile() == null)
return new File(new File(path).getParentFile(), userValue.getName());
return new File(path);
}
protected static void setFileChooserDefaultFile(String name, File file) {
Settings.forPackage(UserFiles.class).put(PREF_KEY_PREFIX + name, file.getPath());
}
public enum FileChooser { public enum FileChooser {
Swing { Swing {
@Override @Override
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, FilenameFilter filter, String title, Object parent) { public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
JFileChooser chooser = new JFileChooser(); JFileChooser chooser = new JFileChooser();
if (filter != null) {
chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
@Override
public String getDescription() {
return filter.toString();
}
@Override
public boolean accept(File f) {
return f.isDirectory() || filter.accept(f.getParentFile(), f.getName());
}
});
}
chooser.setSelectedFile(defaultFile);
chooser.setFileSelectionMode(folderMode && filter == null ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(multiSelection); chooser.setMultiSelectionEnabled(multiSelection);
chooser.setFileSelectionMode(folderMode && filter == null ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
chooser.setSelectedFile(defaultFile);
if (filter != null) {
chooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter(filter.toString(), filter.extensions()));
}
if (chooser.showOpenDialog(getWindow(parent)) == JFileChooser.APPROVE_OPTION) { if (chooser.showOpenDialog(getWindow(parent)) == JFileChooser.APPROVE_OPTION) {
if (chooser.getSelectedFiles().length > 0) if (chooser.getSelectedFiles().length > 0)
@ -71,9 +91,9 @@ public class UserFiles {
@Override @Override
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) { public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
JFileChooser chooser = new JFileChooser(); JFileChooser chooser = new JFileChooser();
chooser.setSelectedFile(defaultFile);
chooser.setFileSelectionMode(folderMode ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(false); chooser.setMultiSelectionEnabled(false);
chooser.setFileSelectionMode(folderMode ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
chooser.setSelectedFile(defaultFile);
if (chooser.showSaveDialog(getWindow(parent)) != JFileChooser.APPROVE_OPTION) { if (chooser.showSaveDialog(getWindow(parent)) != JFileChooser.APPROVE_OPTION) {
return null; return null;
@ -84,39 +104,38 @@ public class UserFiles {
AWT { AWT {
@Override @Override
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, FilenameFilter filter, String title, Object parent) { public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
FileDialog fileDialog = createFileDialog(parent, title, FileDialog.LOAD, folderMode); FileDialog fileDialog = createFileDialog(parent, title, FileDialog.LOAD, folderMode);
fileDialog.setMultipleMode(multiSelection);
if (defaultFile != null) {
fileDialog.setFile(defaultFile.getPath());
}
if (filter != null) { if (filter != null) {
fileDialog.setFilenameFilter(filter); fileDialog.setFilenameFilter(filter);
} }
fileDialog.setMultipleMode(multiSelection); if (defaultFile != null) {
fileDialog.setVisible(true); fileDialog.setFile(defaultFile.getPath());
}
fileDialog.setVisible(true);
return asList(fileDialog.getFiles()); return asList(fileDialog.getFiles());
} }
@Override @Override
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) { public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
FileDialog fileDialog = createFileDialog(getWindow(parent), title, FileDialog.SAVE, folderMode); FileDialog fileDialog = createFileDialog(getWindow(parent), title, FileDialog.SAVE, folderMode);
fileDialog.setMultipleMode(false);
if (defaultFile != null) { if (defaultFile != null) {
if (defaultFile.getParentFile() != null) { if (defaultFile.getParentFile() != null) {
fileDialog.setDirectory(defaultFile.getParentFile().getPath()); fileDialog.setDirectory(defaultFile.getParentFile().getPath());
} }
fileDialog.setFile(defaultFile.getName()); fileDialog.setFile(defaultFile.getName());
} }
fileDialog.setMultipleMode(false);
fileDialog.setVisible(true);
fileDialog.setVisible(true);
File[] files = fileDialog.getFiles(); File[] files = fileDialog.getFiles();
return files.length > 0 ? files[0] : null; return files.length > 0 ? files[0] : null;
} }
public FileDialog createFileDialog(Object parent, String title, int mode, boolean fileDialogForDirectories) { public FileDialog createFileDialog(Object parent, String title, int mode, boolean fileDialogForDirectories) {
// By default, the AWT File Dialog lets you choose a file. Under certain circumstances, however, it may be proper for you to choose a directory instead. If that is the case, set this property to allow for directory selection in a file dialog.
System.setProperty("apple.awt.fileDialogForDirectories", String.valueOf(fileDialogForDirectories)); System.setProperty("apple.awt.fileDialogForDirectories", String.valueOf(fileDialogForDirectories));
if (parent instanceof Frame) { if (parent instanceof Frame) {
@ -133,17 +152,47 @@ public class UserFiles {
JavaFX { JavaFX {
@Override @Override
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, FilenameFilter filter, String title, Object parent) { public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
throw new UnsupportedOperationException(); javafx.stage.FileChooser fileChooser = new javafx.stage.FileChooser();
fileChooser.setTitle(title);
// fileChooser.getExtensionFilters().add(new javafx.stage.FileChooser.ExtensionFilter(arg0, arg1))
if (defaultFile != null) {
if (defaultFile.getParentFile() != null) {
fileChooser.setInitialDirectory(defaultFile.getParentFile());
}
fileChooser.setInitialFileName(defaultFile.getName());
}
if (multiSelection) {
List<File> files = fileChooser.showOpenMultipleDialog(null);
if (files != null)
return files;
} else {
File file = fileChooser.showOpenDialog(null);
if (file != null)
return singletonList(file);
}
return emptyList();
} }
@Override @Override
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) { public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
throw new UnsupportedOperationException(); javafx.stage.FileChooser fileChooser = new javafx.stage.FileChooser();
fileChooser.setTitle(title);
if (defaultFile != null) {
if (defaultFile.getParentFile() != null) {
fileChooser.setInitialDirectory(defaultFile.getParentFile());
}
fileChooser.setInitialFileName(defaultFile.getName());
}
return fileChooser.showSaveDialog(null);
} }
}; };
public abstract List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, final FilenameFilter filter, String title, Object parent); public abstract List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent);
public abstract File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent); public abstract File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent);

View File

@ -1,5 +1,6 @@
package net.filebot.ui.analyze; package net.filebot.ui.analyze;
import static java.util.Arrays.*;
import static net.filebot.ui.NotificationLogging.*; import static net.filebot.ui.NotificationLogging.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
@ -94,4 +95,9 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
return "Folders"; return "Folders";
} }
@Override
public List<String> getFileFilterExtensions() {
return asList("*");
}
} }

View File

@ -1,5 +1,7 @@
package net.filebot.ui.list; package net.filebot.ui.list;
import static java.util.Arrays.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import java.io.File; import java.io.File;
@ -7,7 +9,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.filebot.MediaTypes;
import net.filebot.torrent.Torrent; import net.filebot.torrent.Torrent;
import net.filebot.ui.FileBotList; import net.filebot.ui.FileBotList;
import net.filebot.ui.transfer.FileTransferablePolicy; import net.filebot.ui.transfer.FileTransferablePolicy;
@ -39,7 +40,7 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
// clear selection // clear selection
list.getListComponent().clearSelection(); list.getListComponent().clearSelection();
if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) { if (containsOnly(files, TORRENT_FILES)) {
loadTorrents(files); loadTorrents(files);
} else { } else {
// if only one folder was dropped, use its name as title // if only one folder was dropped, use its name as title
@ -77,4 +78,9 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
return "Files, Folders and Torrents"; return "Files, Folders and Torrents";
} }
@Override
public List<String> getFileFilterExtensions() {
return asList("*");
}
} }

View File

@ -1,5 +1,6 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static java.util.Arrays.*;
import static net.filebot.MediaTypes.*; import static net.filebot.MediaTypes.*;
import static net.filebot.ui.NotificationLogging.*; import static net.filebot.ui.NotificationLogging.*;
import static net.filebot.ui.transfer.FileTransferable.*; import static net.filebot.ui.transfer.FileTransferable.*;
@ -103,6 +104,11 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
return "Files and Folders"; return "Files and Folders";
} }
@Override
public List<String> getFileFilterExtensions() {
return asList("*");
}
@Override @Override
protected void process(List<File> chunks) { protected void process(List<File> chunks) {
model.addAll(FastFile.create(chunks)); model.addAll(FastFile.create(chunks));

View File

@ -1,6 +1,7 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static java.awt.Font.*; import static java.awt.Font.*;
import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
import static javax.swing.JOptionPane.*; import static javax.swing.JOptionPane.*;
@ -621,6 +622,11 @@ class HistoryDialog extends JDialog {
public String getFileFilterDescription() { public String getFileFilterDescription() {
return "History Files (.xml)"; return "History Files (.xml)";
} }
@Override
public List<String> getFileFilterExtensions() {
return asList("xml");
}
}; };
private final FileExportHandler exportHandler = new FileExportHandler() { private final FileExportHandler exportHandler = new FileExportHandler() {

View File

@ -1,6 +1,8 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static java.awt.datatransfer.DataFlavor.*; import static java.awt.datatransfer.DataFlavor.*;
import static java.util.Arrays.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.hash.VerificationUtilities.*;
import static net.filebot.ui.transfer.FileTransferable.*; import static net.filebot.ui.transfer.FileTransferable.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
@ -14,7 +16,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import net.filebot.MediaTypes;
import net.filebot.hash.HashType; import net.filebot.hash.HashType;
import net.filebot.hash.VerificationFileReader; import net.filebot.hash.VerificationFileReader;
import net.filebot.torrent.Torrent; import net.filebot.torrent.Torrent;
@ -85,13 +86,13 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
protected void load(List<File> files) throws IOException { protected void load(List<File> files) throws IOException {
List<Object> values = new ArrayList<Object>(); List<Object> values = new ArrayList<Object>();
if (containsOnly(files, MediaTypes.getDefaultFilter("application/list"))) { if (containsOnly(files, LIST_FILES)) {
// list files // list files
loadListFiles(files, values); loadListFiles(files, values);
} else if (containsOnly(files, MediaTypes.getDefaultFilter("verification"))) { } else if (containsOnly(files, VERIFICATION_FILES)) {
// verification files // verification files
loadVerificationFiles(files, values); loadVerificationFiles(files, values);
} else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) { } else if (containsOnly(files, TORRENT_FILES)) {
// torrent files // torrent files
loadTorrentFiles(files, values); loadTorrentFiles(files, values);
} else { } else {
@ -155,4 +156,9 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
return "Text Files, Verification Files, Torrent Files"; return "Text Files, Verification Files, Torrent Files";
} }
@Override
public List<String> getFileFilterExtensions() {
return asList(combineFilter(LIST_FILES, TORRENT_FILES, VERIFICATION_FILES).extensions());
}
} }

View File

@ -1,6 +1,8 @@
package net.filebot.ui.sfv; package net.filebot.ui.sfv;
import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.hash.VerificationUtilities.*; import static net.filebot.hash.VerificationUtilities.*;
import static net.filebot.ui.NotificationLogging.*; import static net.filebot.ui.NotificationLogging.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
@ -171,6 +173,11 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
return "Files, Folders and SFV Files"; return "Files, Folders and SFV Files";
} }
@Override
public List<String> getFileFilterExtensions() {
return asList(VERIFICATION_FILES.extensions());
}
private static class VerificationTracker { private static class VerificationTracker {
private final Map<File, Integer> seen = new HashMap<File, Integer>(); private final Map<File, Integer> seen = new HashMap<File, Integer>();

View File

@ -3,6 +3,7 @@ package net.filebot.ui.sfv;
import static java.lang.Math.*; import static java.lang.Math.*;
import static net.filebot.ui.sfv.ChecksumTableModel.*; import static net.filebot.ui.sfv.ChecksumTableModel.*;
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*; import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
import static net.filebot.util.FileUtilities.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -228,14 +229,9 @@ public class SfvPanel extends JComponent {
} }
@Override @Override
protected String getDefaultFileName() { protected File getDefaultFile() {
return getExportHandler().getDefaultFileName(selectedColumn);
}
@Override
protected File getDefaultFolder() {
// use the column root as default folder in the file dialog // use the column root as default folder in the file dialog
return selectedColumn; return new File(selectedColumn, validateFileName(getExportHandler().getDefaultFileName(selectedColumn)));
} }
@Override @Override

View File

@ -46,8 +46,8 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
protected abstract void clear(); protected abstract void clear();
public String getFileFilterDescription() { public abstract String getFileFilterDescription();
return null;
} public abstract List<String> getFileFilterExtensions();
} }

View File

@ -13,8 +13,8 @@ import javax.swing.Action;
import javax.swing.Icon; import javax.swing.Icon;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.filebot.Settings;
import net.filebot.ui.transfer.TransferablePolicy.TransferAction; import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
public class LoadAction extends AbstractAction { public class LoadAction extends AbstractAction {
@ -35,17 +35,8 @@ public class LoadAction extends AbstractAction {
return ((evt.getModifiers() & ActionEvent.CTRL_MASK) != 0) ? TransferAction.ADD : TransferAction.PUT; return ((evt.getModifiers() & ActionEvent.CTRL_MASK) != 0) ? TransferAction.ADD : TransferAction.PUT;
} }
protected File getDefaultFolder() { protected File getDefaultFile() {
String lastLocation = Settings.forPackage(LoadAction.class).get("load.location"); return null;
if (lastLocation == null || lastLocation.isEmpty())
return null;
return new File(lastLocation);
}
protected void setDefaultFolder(File folder) {
Settings.forPackage(LoadAction.class).put("load.location", folder.getPath());
} }
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
@ -56,7 +47,7 @@ public class LoadAction extends AbstractAction {
return; return;
} }
List<File> files = showLoadDialogSelectFiles(true, true, getDefaultFolder(), new TransferablePolicyFileFilter(transferablePolicy), (String) getValue(Action.NAME), evt.getSource()); List<File> files = showLoadDialogSelectFiles(true, true, getDefaultFile(), getFileFilter(transferablePolicy), (String) getValue(Action.NAME), evt.getSource());
if (files.isEmpty()) { if (files.isEmpty()) {
return; return;
} }
@ -70,4 +61,18 @@ public class LoadAction extends AbstractAction {
} }
} }
protected ExtensionFileFilter getFileFilter(TransferablePolicy transferablePolicy) {
if (transferablePolicy instanceof FileTransferablePolicy) {
final FileTransferablePolicy ftp = ((FileTransferablePolicy) transferablePolicy);
if (ftp.getFileFilterDescription() != null) {
return new ExtensionFileFilter(ftp.getFileFilterExtensions()) {
@Override
public String toString() {
return ftp.getFileFilterDescription();
};
};
}
}
return null;
}
} }

View File

@ -14,7 +14,6 @@ import javax.swing.Action;
import javax.swing.Icon; import javax.swing.Icon;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.filebot.Settings;
public class SaveAction extends AbstractAction { public class SaveAction extends AbstractAction {
@ -42,31 +41,16 @@ public class SaveAction extends AbstractAction {
getExportHandler().export(file); getExportHandler().export(file);
} }
protected String getDefaultFileName() { protected File getDefaultFile() {
return getExportHandler().getDefaultFileName(); return new File(validateFileName(getExportHandler().getDefaultFileName()));
}
protected File getDefaultFolder() {
String lastLocation = Settings.forPackage(SaveAction.class).get("save.location");
if (lastLocation == null || lastLocation.isEmpty())
return null;
return new File(lastLocation);
}
protected void setDefaultFolder(File folder) {
Settings.forPackage(LoadAction.class).put("save.location", folder.getPath());
} }
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
try { try {
if (canExport()) { if (canExport()) {
File defaultFile = new File(getDefaultFolder(), validateFileName(getDefaultFileName())); File file = showSaveDialogSelectFile(false, getDefaultFile(), (String) getValue(Action.NAME), evt.getSource());
File file = showSaveDialogSelectFile(false, defaultFile, (String) getValue(Action.NAME), evt.getSource());
if (file != null) { if (file != null) {
setDefaultFolder(file.getParentFile());
export(file); export(file);
} }
} }
@ -74,5 +58,4 @@ public class SaveAction extends AbstractAction {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
} }
} }
} }

View File

@ -1,46 +0,0 @@
package net.filebot.ui.transfer;
import java.io.File;
import java.io.FilenameFilter;
import javax.swing.filechooser.FileFilter;
public class TransferablePolicyFileFilter extends FileFilter implements FilenameFilter {
private final TransferablePolicy transferablePolicy;
public TransferablePolicyFileFilter(TransferablePolicy transferablePolicy) {
this.transferablePolicy = transferablePolicy;
}
@Override
public boolean accept(File f) {
if (f.isDirectory())
return true;
try {
return transferablePolicy.accept(new FileTransferable(f));
} catch (Exception e) {
return false;
}
}
@Override
public boolean accept(File dir, String name) {
return accept(new File(dir, name));
}
@Override
public String getDescription() {
return this.toString();
}
@Override
public String toString() {
if (transferablePolicy instanceof FileTransferablePolicy) {
return ((FileTransferablePolicy) transferablePolicy).getFileFilterDescription();
}
return super.toString();
}
}