Mac NSOpenPanel - I'm doing something wrong

knightlie

macrumors 6502a
Original poster
Feb 18, 2008
546
0
Something weird is happening with an NSOpenPanel. Here's the code:

Code:
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setAllowedFileTypes:[NSArray arrayWithObject:@"categories"]];
[openPanel beginSheetModalForWindow:[self.document windowForSheet] completionHandler:^(NSInteger result){
    if (result==NSFileHandlingPanelOKButton) {
        // Process the file		
    }
}];
(This is inside a simple class which has access to an NSPersistentDocument via the document property).

When this runs the open panel appears, the selected file is processed and everything seems normal. "Processing" a file in this instance adds objects to the managed object context. But... once this code has run the Quit menu option and various others are disabled - as if the panel is still in place, and I have to force quit. I'm using an NSSavePanel in the same way without the same issue.

I haven't used Blocks very much in this manner - am I doing something wrong?
 

gnasher729

macrumors P6
Nov 25, 2005
16,699
3,440
Something weird is happening with an NSOpenPanel. Here's the code:

Code:
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setAllowedFileTypes:[NSArray arrayWithObject:@"categories"]];
[openPanel beginSheetModalForWindow:[self.document windowForSheet] completionHandler:^(NSInteger result){
    if (result==NSFileHandlingPanelOKButton) {
        // Process the file		
    }
}];
(This is inside a simple class which has access to an NSPersistentDocument via the document property).

When this runs the open panel appears, the selected file is processed and everything seems normal. "Processing" a file in this instance adds objects to the managed object context. But... once this code has run the Quit menu option and various others are disabled - as if the panel is still in place, and I have to force quit. I'm using an NSSavePanel in the same way without the same issue.

I haven't used Blocks very much in this manner - am I doing something wrong?
Quite possible that the code inside the block causes the problem. Things that we can see are always good for causing trouble. Try it with the code as it is. Obviously any files won't get processed in a meaningful way, but do you still get the bad behaviour?
 
Comment

knightlie

macrumors 6502a
Original poster
Feb 18, 2008
546
0
Quite possible that the code inside the block causes the problem. Things that we can see are always good for causing trouble. Try it with the code as it is. Obviously any files won't get processed in a meaningful way, but do you still get the bad behaviour?
Yes, even if the block is empty I get the same behaviour.
 
Comment

knightlie

macrumors 6502a
Original poster
Feb 18, 2008
546
0
I think I found it. The code I posted takes place in a method whose return value indicates success. When the OpenPanel appeared the method exited immediately and returned NO, which resulted in the calling code trying to show an error sheet. It ended up with the document window displaying a sheet which wasn't visible.

I need to get used to how Blocks work - I assumed the beginSheetForModal method would net return until the block had been called, which doesn't appear to be the case.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.