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:
parent
a7e67974a2
commit
cc4f257a8b
@ -111,4 +111,6 @@ public class MediaTypes {
|
||||
public static final ExtensionFileFilter VERIFICATION_FILES = getDefaultFilter("verification");
|
||||
public static final ExtensionFileFilter NFO_FILES = getDefaultFilter("application/nfo");
|
||||
public static final ExtensionFileFilter LIST_FILES = getDefaultFilter("application/list");
|
||||
public static final ExtensionFileFilter TORRENT_FILES = getDefaultFilter("application/torrent");
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.filebot;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static net.filebot.Settings.*;
|
||||
import static net.filebot.util.ui.SwingUI.*;
|
||||
|
||||
@ -8,11 +9,12 @@ import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||
|
||||
public class UserFiles {
|
||||
|
||||
private static FileChooser defaultFileChooser = getPreferredFileChooser();
|
||||
@ -21,12 +23,20 @@ public class UserFiles {
|
||||
defaultFileChooser = fileChooser;
|
||||
}
|
||||
|
||||
public static List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, final FilenameFilter filter, String title, Object parent) {
|
||||
return defaultFileChooser.showLoadDialogSelectFiles(folderMode, multiSelection, defaultFile, filter, title, parent);
|
||||
public static List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object 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) {
|
||||
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) {
|
||||
@ -34,30 +44,40 @@ public class UserFiles {
|
||||
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 {
|
||||
|
||||
Swing {
|
||||
@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();
|
||||
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.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.getSelectedFiles().length > 0)
|
||||
@ -71,9 +91,9 @@ public class UserFiles {
|
||||
@Override
|
||||
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
chooser.setSelectedFile(defaultFile);
|
||||
chooser.setFileSelectionMode(folderMode ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
|
||||
chooser.setMultiSelectionEnabled(false);
|
||||
chooser.setFileSelectionMode(folderMode ? JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES);
|
||||
chooser.setSelectedFile(defaultFile);
|
||||
|
||||
if (chooser.showSaveDialog(getWindow(parent)) != JFileChooser.APPROVE_OPTION) {
|
||||
return null;
|
||||
@ -84,39 +104,38 @@ public class UserFiles {
|
||||
|
||||
AWT {
|
||||
@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);
|
||||
|
||||
if (defaultFile != null) {
|
||||
fileDialog.setFile(defaultFile.getPath());
|
||||
}
|
||||
fileDialog.setMultipleMode(multiSelection);
|
||||
if (filter != null) {
|
||||
fileDialog.setFilenameFilter(filter);
|
||||
}
|
||||
fileDialog.setMultipleMode(multiSelection);
|
||||
fileDialog.setVisible(true);
|
||||
if (defaultFile != null) {
|
||||
fileDialog.setFile(defaultFile.getPath());
|
||||
}
|
||||
|
||||
fileDialog.setVisible(true);
|
||||
return asList(fileDialog.getFiles());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
|
||||
FileDialog fileDialog = createFileDialog(getWindow(parent), title, FileDialog.SAVE, folderMode);
|
||||
|
||||
fileDialog.setMultipleMode(false);
|
||||
if (defaultFile != null) {
|
||||
if (defaultFile.getParentFile() != null) {
|
||||
fileDialog.setDirectory(defaultFile.getParentFile().getPath());
|
||||
}
|
||||
fileDialog.setFile(defaultFile.getName());
|
||||
}
|
||||
fileDialog.setMultipleMode(false);
|
||||
fileDialog.setVisible(true);
|
||||
|
||||
fileDialog.setVisible(true);
|
||||
File[] files = fileDialog.getFiles();
|
||||
return files.length > 0 ? files[0] : null;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if (parent instanceof Frame) {
|
||||
@ -133,17 +152,47 @@ public class UserFiles {
|
||||
|
||||
JavaFX {
|
||||
@Override
|
||||
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, FilenameFilter filter, String title, Object parent) {
|
||||
throw new UnsupportedOperationException();
|
||||
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
|
||||
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
|
||||
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);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.filebot.ui.analyze;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static net.filebot.ui.NotificationLogging.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
@ -94,4 +95,9 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy<TreeNo
|
||||
return "Folders";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileFilterExtensions() {
|
||||
return asList("*");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.filebot.ui.list;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
@ -7,7 +9,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.filebot.MediaTypes;
|
||||
import net.filebot.torrent.Torrent;
|
||||
import net.filebot.ui.FileBotList;
|
||||
import net.filebot.ui.transfer.FileTransferablePolicy;
|
||||
@ -39,7 +40,7 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
|
||||
// clear selection
|
||||
list.getListComponent().clearSelection();
|
||||
|
||||
if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
|
||||
if (containsOnly(files, TORRENT_FILES)) {
|
||||
loadTorrents(files);
|
||||
} else {
|
||||
// if only one folder was dropped, use its name as title
|
||||
@ -77,4 +78,9 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
|
||||
return "Files, Folders and Torrents";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileFilterExtensions() {
|
||||
return asList("*");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.filebot.ui.rename;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.ui.NotificationLogging.*;
|
||||
import static net.filebot.ui.transfer.FileTransferable.*;
|
||||
@ -103,6 +104,11 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
|
||||
return "Files and Folders";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileFilterExtensions() {
|
||||
return asList("*");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<File> chunks) {
|
||||
model.addAll(FastFile.create(chunks));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.filebot.ui.rename;
|
||||
|
||||
import static java.awt.Font.*;
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static java.util.regex.Pattern.*;
|
||||
import static javax.swing.JOptionPane.*;
|
||||
@ -621,6 +622,11 @@ class HistoryDialog extends JDialog {
|
||||
public String getFileFilterDescription() {
|
||||
return "History Files (.xml)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileFilterExtensions() {
|
||||
return asList("xml");
|
||||
}
|
||||
};
|
||||
|
||||
private final FileExportHandler exportHandler = new FileExportHandler() {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.filebot.ui.rename;
|
||||
|
||||
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.ui.transfer.FileTransferable.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
@ -14,7 +16,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import net.filebot.MediaTypes;
|
||||
import net.filebot.hash.HashType;
|
||||
import net.filebot.hash.VerificationFileReader;
|
||||
import net.filebot.torrent.Torrent;
|
||||
@ -85,13 +86,13 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
||||
protected void load(List<File> files) throws IOException {
|
||||
List<Object> values = new ArrayList<Object>();
|
||||
|
||||
if (containsOnly(files, MediaTypes.getDefaultFilter("application/list"))) {
|
||||
if (containsOnly(files, LIST_FILES)) {
|
||||
// list files
|
||||
loadListFiles(files, values);
|
||||
} else if (containsOnly(files, MediaTypes.getDefaultFilter("verification"))) {
|
||||
} else if (containsOnly(files, VERIFICATION_FILES)) {
|
||||
// verification files
|
||||
loadVerificationFiles(files, values);
|
||||
} else if (containsOnly(files, MediaTypes.getDefaultFilter("application/torrent"))) {
|
||||
} else if (containsOnly(files, TORRENT_FILES)) {
|
||||
// torrent files
|
||||
loadTorrentFiles(files, values);
|
||||
} else {
|
||||
@ -155,4 +156,9 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
||||
return "Text Files, Verification Files, Torrent Files";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileFilterExtensions() {
|
||||
return asList(combineFilter(LIST_FILES, TORRENT_FILES, VERIFICATION_FILES).extensions());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.filebot.ui.sfv;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.hash.VerificationUtilities.*;
|
||||
import static net.filebot.ui.NotificationLogging.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
@ -171,6 +173,11 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy<C
|
||||
return "Files, Folders and SFV Files";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileFilterExtensions() {
|
||||
return asList(VERIFICATION_FILES.extensions());
|
||||
}
|
||||
|
||||
private static class VerificationTracker {
|
||||
|
||||
private final Map<File, Integer> seen = new HashMap<File, Integer>();
|
||||
|
@ -3,6 +3,7 @@ package net.filebot.ui.sfv;
|
||||
import static java.lang.Math.*;
|
||||
import static net.filebot.ui.sfv.ChecksumTableModel.*;
|
||||
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
@ -228,14 +229,9 @@ public class SfvPanel extends JComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultFileName() {
|
||||
return getExportHandler().getDefaultFileName(selectedColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File getDefaultFolder() {
|
||||
protected File getDefaultFile() {
|
||||
// use the column root as default folder in the file dialog
|
||||
return selectedColumn;
|
||||
return new File(selectedColumn, validateFileName(getExportHandler().getDefaultFileName(selectedColumn)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,8 +46,8 @@ public abstract class FileTransferablePolicy extends TransferablePolicy {
|
||||
|
||||
protected abstract void clear();
|
||||
|
||||
public String getFileFilterDescription() {
|
||||
return null;
|
||||
}
|
||||
public abstract String getFileFilterDescription();
|
||||
|
||||
public abstract List<String> getFileFilterExtensions();
|
||||
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.Settings;
|
||||
import net.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
||||
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected File getDefaultFolder() {
|
||||
String lastLocation = Settings.forPackage(LoadAction.class).get("load.location");
|
||||
|
||||
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());
|
||||
protected File getDefaultFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
@ -56,7 +47,7 @@ public class LoadAction extends AbstractAction {
|
||||
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()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.Settings;
|
||||
|
||||
public class SaveAction extends AbstractAction {
|
||||
|
||||
@ -42,31 +41,16 @@ public class SaveAction extends AbstractAction {
|
||||
getExportHandler().export(file);
|
||||
}
|
||||
|
||||
protected String getDefaultFileName() {
|
||||
return 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());
|
||||
protected File getDefaultFile() {
|
||||
return new File(validateFileName(getExportHandler().getDefaultFileName()));
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
try {
|
||||
if (canExport()) {
|
||||
File defaultFile = new File(getDefaultFolder(), validateFileName(getDefaultFileName()));
|
||||
File file = showSaveDialogSelectFile(false, defaultFile, (String) getValue(Action.NAME), evt.getSource());
|
||||
File file = showSaveDialogSelectFile(false, getDefaultFile(), (String) getValue(Action.NAME), evt.getSource());
|
||||
|
||||
if (file != null) {
|
||||
setDefaultFolder(file.getParentFile());
|
||||
export(file);
|
||||
}
|
||||
}
|
||||
@ -74,5 +58,4 @@ public class SaveAction extends AbstractAction {
|
||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user