* make sure permissions dialog is called on EDT
This commit is contained in:
parent
e185fdb990
commit
f22325b3dd
|
@ -28,6 +28,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.RunnableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -38,6 +41,7 @@ import javax.swing.JComponent;
|
|||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.Settings;
|
||||
|
@ -106,20 +110,27 @@ public class DropToUnlock extends JList<File> {
|
|||
}).filter(f -> f != null && isLockedFolder(f)).sorted().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static boolean showUnlockFoldersDialog(Window owner, Collection<File> files) {
|
||||
public static boolean showUnlockFoldersDialog(final Window owner, final Collection<File> files) {
|
||||
final List<File> model = getParentFolders(files);
|
||||
|
||||
// immediately return if there is nothing that needs to be unlocked
|
||||
if (model.isEmpty())
|
||||
if (model.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// try to restore permissions from previously stored security-scoped bookmarks as best as possible
|
||||
unlockBySecurityScopedBookmarks(model);
|
||||
|
||||
// check if we even need to unlock anything at this point
|
||||
if (model.stream().allMatch(f -> !isLockedFolder(f)))
|
||||
if (model.stream().allMatch(f -> !isLockedFolder(f))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// show selection dialog on EDT
|
||||
RunnableFuture<Boolean> showPermissionDialog = new FutureTask<Boolean>(new Callable<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
final JDialog dialog = new JDialog(owner);
|
||||
final AtomicBoolean dialogCancelled = new AtomicBoolean(true);
|
||||
DropToUnlock d = new DropToUnlock(model) {
|
||||
|
@ -165,13 +176,24 @@ public class DropToUnlock extends JList<File> {
|
|||
dialog.setVisible(true);
|
||||
|
||||
// abort if user has closed the window before all folders have been unlocked
|
||||
if (dialogCancelled.get())
|
||||
return false;
|
||||
return !dialogCancelled.get();
|
||||
}
|
||||
});
|
||||
|
||||
// store security-scoped bookmarks
|
||||
// show dialog on EDT and wait for user input
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(showPermissionDialog);
|
||||
|
||||
// store security-scoped bookmark if dialog was accepted
|
||||
if (showPermissionDialog.get()) {
|
||||
storeSecurityScopedBookmarks(model);
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger(DropToUnlock.class.getName()).log(Level.WARNING, "NSURL.bookmarkDataWithOptions: " + e.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public DropToUnlock(Collection<File> model) {
|
||||
super(model.toArray(new File[0]));
|
||||
|
|
Loading…
Reference in New Issue