1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

* directly use NSOpenPanel for via Objective-C bridge for FILES_AND_DIRECTORIES mode

This commit is contained in:
Reinhard Pointner 2014-11-07 13:26:54 +00:00
parent 2ed4c50be0
commit 98e3df40a1
5 changed files with 52 additions and 6 deletions

View File

@ -276,7 +276,7 @@
<option value="-Dapplication.cache=./Library/Caches/ehcache.disk.store" />
<option value="-Djava.io.tmpdir=./Library/Caches/java.io.tmpdir" />
<option value="-Dnet.filebot.UserFiles.fileChooser=AWT" />
<option value="-Dnet.filebot.UserFiles.fileChooser=COCOA" />
<option value="-Dapplication.deployment=mas" />
<option value="-Dapplication.update=skip" />

View File

@ -20,6 +20,7 @@ import java.util.logging.Logger;
import javax.swing.JFileChooser;
import net.filebot.mac.MacAppUtilities;
import net.filebot.mac.NativeFileDialog;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
public class UserFiles {
@ -189,6 +190,39 @@ public class UserFiles {
}
},
COCOA {
@Override
public List<File> showLoadDialogSelectFiles(boolean folderMode, boolean multiSelection, File defaultFile, ExtensionFileFilter filter, String title, Object parent) {
// directly use NSOpenPanel for via Objective-C bridge for FILES_AND_DIRECTORIES mode
if (folderMode && filter != null) {
try {
NativeFileDialog nsOpenPanel = new NativeFileDialog(title, FileDialog.LOAD);
nsOpenPanel.setMultipleMode(true);
nsOpenPanel.setCanChooseDirectories(true);
nsOpenPanel.setCanChooseFiles(true);
if (!filter.acceptAny()) {
nsOpenPanel.setAllowedFileTypes(asList(filter.extensions()));
}
nsOpenPanel.setVisible(true);
return asList(nsOpenPanel.getFiles());
} catch (Throwable e) {
Logger.getLogger(UserFiles.class.getName()).log(Level.WARNING, e.toString());
}
}
// default to AWT implementation
return AWT.showLoadDialogSelectFiles(folderMode, multiSelection, defaultFile, filter, title, parent);
}
@Override
public File showSaveDialogSelectFile(boolean folderMode, File defaultFile, String title, Object parent) {
// default to AWT implementation
return AWT.showSaveDialogSelectFile(folderMode, defaultFile, title, parent);
}
},
JavaFX {
@Override

View File

@ -1,6 +1,5 @@
package net.filebot.ui.list;
import static java.util.Arrays.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.util.FileUtilities.*;
@ -13,6 +12,7 @@ import net.filebot.torrent.Torrent;
import net.filebot.ui.FileBotList;
import net.filebot.ui.transfer.FileTransferablePolicy;
import net.filebot.util.FileUtilities;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
class FileListTransferablePolicy extends FileTransferablePolicy {
@ -80,7 +80,7 @@ class FileListTransferablePolicy extends FileTransferablePolicy {
@Override
public List<String> getFileFilterExtensions() {
return asList("*");
return ExtensionFileFilter.WILDCARD;
}
}

View File

@ -1,6 +1,5 @@
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.util.FileUtilities.*;
@ -18,6 +17,7 @@ import net.filebot.media.MediaDetection;
import net.filebot.ui.transfer.BackgroundFileTransferablePolicy;
import net.filebot.util.ExceptionUtilities;
import net.filebot.util.FastFile;
import net.filebot.util.FileUtilities.ExtensionFileFilter;
class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File> {
@ -102,7 +102,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy<File>
@Override
public List<String> getFileFilterExtensions() {
return asList("*");
return ExtensionFileFilter.WILDCARD;
}
@Override

View File

@ -1,6 +1,7 @@
package net.filebot.util;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.BufferedInputStream;
import java.io.File;
@ -718,6 +719,8 @@ public final class FileUtilities {
public static class ExtensionFileFilter implements FileFilter, FilenameFilter {
public static final List<String> WILDCARD = singletonList("*");
private final String[] extensions;
public ExtensionFileFilter(String... extensions) {
@ -742,10 +745,19 @@ public final class FileUtilities {
return hasExtension(name, extensions);
}
public boolean acceptAny() {
return extensions.length == 1 && WILDCARD.get(0).equals(extensions[0]);
}
public boolean acceptExtension(String extension) {
if (acceptAny()) {
return true;
}
for (String other : extensions) {
if (other.equalsIgnoreCase(extension))
if (other.equalsIgnoreCase(extension)) {
return true;
}
}
return false;