1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* revert, DnD issues are caused by Finder/OSX waiting for previous ongoing drop event to be accepted/rejected

This commit is contained in:
Reinhard Pointner 2016-02-03 19:32:32 +00:00
parent 87125a98a9
commit 0d1f6cfac6

View File

@ -18,8 +18,6 @@ import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.SecondaryLoop;
import java.awt.Toolkit;
import java.awt.Window; import java.awt.Window;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -27,6 +25,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import java.util.Collection; import java.util.Collection;
@ -34,6 +33,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -133,13 +136,13 @@ public class DropToUnlock extends JList<File> {
return true; return true;
} }
// show dialog on EDT and wait for user input // show selection dialog on EDT
final SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop(); RunnableFuture<Boolean> showPermissionDialog = new FutureTask<Boolean>(new Callable<Boolean>() {
final AtomicBoolean dialogCancelled = new AtomicBoolean(true);
SwingUtilities.invokeLater(() -> { @Override
try { public Boolean call() throws Exception {
JDialog dialog = new JDialog(owner); final JDialog dialog = new JDialog(owner);
final AtomicBoolean dialogCancelled = new AtomicBoolean(true);
DropToUnlock d = new DropToUnlock(model) { DropToUnlock d = new DropToUnlock(model) {
@Override @Override
@ -191,20 +194,29 @@ public class DropToUnlock extends JList<File> {
// show and wait for user input // show and wait for user input
dialog.setVisible(true); dialog.setVisible(true);
} finally {
secondaryLoop.exit(); // abort if user has closed the window before all folders have been unlocked
return !dialogCancelled.get();
} }
}); });
if (!secondaryLoop.enter()) { // show dialog on EDT and wait for user input
throw new IllegalStateException("SecondaryLoop.enter()"); try {
} if (SwingUtilities.isEventDispatchThread()) {
if (dialogCancelled.get()) { showPermissionDialog.run();
return false; } else {
} SwingUtilities.invokeAndWait(showPermissionDialog);
}
storeSecurityScopedBookmarks(model); // store security-scoped bookmark if dialog was accepted
return true; if (showPermissionDialog.get()) {
storeSecurityScopedBookmarks(model);
return true;
}
return false;
} catch (InterruptedException | InvocationTargetException | ExecutionException e) {
throw new RuntimeException("Failed to request permissions: " + e.getMessage(), e);
}
} }
public DropToUnlock(Collection<File> model) { public DropToUnlock(Collection<File> model) {