0

I have an NSOpenPanel Where I can select directory or multiply files (single file as well).

However some evil spirits took over my app when I press OK button on the panel. If I pick less than 10 files the NSOpenPanel doesn't close immediately however when I pick 11 or more it does. Perhaps those spirits are afraid of large amounts of files...

Here is how I Implemented the routine:

NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:YES];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:YES];
[panel setTitle:@"Open/Add"];

NSInteger clicked = [panel runModal];
if (clicked == NSFileHandlingPanelOKButton)
{
        NSArray * urls = [panel URLs];
    [panel orderOut:[self window]];

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
    {
          //My routine here
    });

Do you have any ideas ? or perhaps you know a good exorcist?! Of course I want it to close immediately!

P.S. I also tried to dispatch after some period of time -> same behaviour

Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
  • 1
    What's the context in which the code you show runs? That is, does it return to a normal run loop immediately after your asynchronous block is dispatched? – JWWalker Jul 18 '15 at 23:26
  • @JWWalker Yes it grabs the data from the file assigns it to an array and then returning to the run loop – Coldsteel48 Jul 18 '15 at 23:59
  • Does the code that you've replaced with "My routine here" reference `panel`? – Ken Thomases Jul 19 '15 at 00:08
  • @WWalker but inside the dispatch I am geting back to the main queue and assigning the array to the collection view and call wants display ... – Coldsteel48 Jul 19 '15 at 00:13
  • @Ken Thomases No, I took the URLs in to temp array and working with it only, I am not calling panel inside the dispatch – Coldsteel48 Jul 19 '15 at 00:14
  • Guys it is a bit lengthy and very ugly routine there but if it will help I can post it – Coldsteel48 Jul 19 '15 at 00:21
  • Is this code being called from a block that was submitted to `dispatch_get_main_queue()`? Or is it just in response to, say, a button click or a menu item being selected? – Ken Thomases Jul 19 '15 at 00:41
  • @Ken Thomases yes it called from a block – Coldsteel48 Jul 19 '15 at 09:42
  • 1
    Try using `-performSelectorOnMainThread:withObject:waitUntilDone:` or `CFRunLoopPerformBlock()` instead of GCD. The main dispatch queue is serial. That means that while it's running your block, it can't run any others. However, `NSOpenPanel` does some stuff where it schedules its own work on the main dispatch queue. So, if you're running it modally from the main queue, its own work can't get done. See [here](https://stackoverflow.com/a/26170606/1312143) and [here](https://stackoverflow.com/a/23856486/1312143). – Ken Thomases Jul 19 '15 at 17:07
  • @Ken Thomases I will try your suggestions and let you know thanks – Coldsteel48 Jul 19 '15 at 19:24

0 Answers0