From 9c05de570b3014284d0de3440ec465f7b69e33fb Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 16 Nov 2015 07:48:46 +0000 Subject: [PATCH] * cleanup --- source/net/filebot/mac/MacAppUtilities.java | 56 ++++++++++----------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/source/net/filebot/mac/MacAppUtilities.java b/source/net/filebot/mac/MacAppUtilities.java index 9d970415..94d0e634 100644 --- a/source/net/filebot/mac/MacAppUtilities.java +++ b/source/net/filebot/mac/MacAppUtilities.java @@ -52,40 +52,36 @@ public class MacAppUtilities { final SecondaryLoop secondaryLoop = eventQueue.createSecondaryLoop(); // WARNING: dispatch_sync seems to work on most Mac always causes a deadlock and freezes the application on others (in particular MBP with 2 graphics chips) - dispatch_async(new Runnable() { + dispatch_async(() -> { + Pointer pool = createAutoreleasePool(); + Proxy peer = objc().sendProxy("NSOpenPanel", "openPanel"); + peer.send("retain"); - @Override - public void run() { - Pointer pool = createAutoreleasePool(); - Proxy peer = objc().sendProxy("NSOpenPanel", "openPanel"); - peer.send("retain"); + peer.send("setTitle:", title); + peer.send("setAllowsMultipleSelection:", multipleMode ? 1 : 0); + peer.send("setCanChooseDirectories:", canChooseDirectories ? 1 : 0); + peer.send("setCanChooseFiles:", canChooseFiles ? 1 : 0); - peer.send("setTitle:", title); - peer.send("setAllowsMultipleSelection:", multipleMode ? 1 : 0); - peer.send("setCanChooseDirectories:", canChooseDirectories ? 1 : 0); - peer.send("setCanChooseFiles:", canChooseFiles ? 1 : 0); - - if (allowedFileTypes != null) { - Proxy mutableArray = objc().sendProxy("NSMutableArray", "arrayWithCapacity:", allowedFileTypes.length); - for (String type : allowedFileTypes) { - mutableArray.send("addObject:", type); - } - peer.send("setAllowedFileTypes:", mutableArray); + if (allowedFileTypes != null) { + Proxy mutableArray = objc().sendProxy("NSMutableArray", "arrayWithCapacity:", allowedFileTypes.length); + for (String type : allowedFileTypes) { + mutableArray.send("addObject:", type); } - - if (peer.sendInt("runModal") != 0) { - Proxy nsArray = peer.getProxy("URLs"); - int size = nsArray.sendInt("count"); - for (int i = 0; i < size; i++) { - Proxy url = nsArray.sendProxy("objectAtIndex:", i); - String path = url.sendString("path"); - result.add(new File(path)); - } - } - - drainAutoreleasePool(pool); - secondaryLoop.exit(); + peer.send("setAllowedFileTypes:", mutableArray); } + + if (peer.sendInt("runModal") != 0) { + Proxy nsArray = peer.getProxy("URLs"); + int size = nsArray.sendInt("count"); + for (int i = 0; i < size; i++) { + Proxy url = nsArray.sendProxy("objectAtIndex:", i); + String path = url.sendString("path"); + result.add(new File(path)); + } + } + + drainAutoreleasePool(pool); + secondaryLoop.exit(); }); // Enter the loop to block the current event handler, but leave UI responsive