From 0d1f6cfac6b7cc784d1b39daddc2a8729e1d65ca Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 3 Feb 2016 19:32:32 +0000 Subject: [PATCH] * revert, DnD issues are caused by Finder/OSX waiting for previous ongoing drop event to be accepted/rejected --- source/net/filebot/mac/DropToUnlock.java | 48 +++++++++++++++--------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/source/net/filebot/mac/DropToUnlock.java b/source/net/filebot/mac/DropToUnlock.java index 7cbf1290..ee36ecc5 100644 --- a/source/net/filebot/mac/DropToUnlock.java +++ b/source/net/filebot/mac/DropToUnlock.java @@ -18,8 +18,6 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; -import java.awt.SecondaryLoop; -import java.awt.Toolkit; import java.awt.Window; import java.awt.datatransfer.Transferable; import java.awt.event.ActionEvent; @@ -27,6 +25,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.RoundRectangle2D; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.attribute.PosixFilePermissions; import java.util.Collection; @@ -34,6 +33,10 @@ 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.ExecutionException; +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; @@ -133,13 +136,13 @@ public class DropToUnlock extends JList { return true; } - // show dialog on EDT and wait for user input - final SecondaryLoop secondaryLoop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop(); - final AtomicBoolean dialogCancelled = new AtomicBoolean(true); + // show selection dialog on EDT + RunnableFuture showPermissionDialog = new FutureTask(new Callable() { - SwingUtilities.invokeLater(() -> { - try { - JDialog dialog = new JDialog(owner); + @Override + public Boolean call() throws Exception { + final JDialog dialog = new JDialog(owner); + final AtomicBoolean dialogCancelled = new AtomicBoolean(true); DropToUnlock d = new DropToUnlock(model) { @Override @@ -191,20 +194,29 @@ public class DropToUnlock extends JList { // show and wait for user input 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()) { - throw new IllegalStateException("SecondaryLoop.enter()"); - } - if (dialogCancelled.get()) { - return false; - } + // show dialog on EDT and wait for user input + try { + if (SwingUtilities.isEventDispatchThread()) { + showPermissionDialog.run(); + } else { + SwingUtilities.invokeAndWait(showPermissionDialog); + } - storeSecurityScopedBookmarks(model); - return true; + // store security-scoped bookmark if dialog was accepted + 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 model) {