cocoa get sheet state

209 Views Asked by At

Is there a way to determine the state of a sheet? I know I can call this method:

- (void) customSheetDidClose : (NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo

but what I want to do is something like this:

- (void) getInfoMethod { 

    //...do a lot of stuff to gather data

    [self openSheetMethod:dictionaryFullOfStuff];


    //I am completely making this up
    while([panFileDataEditor state] == open) { 
        //do nothing
    } 

}

- (void) openSheetMethod : (NSDictionary*) stuff { 

    //...do something with stuff

    [NSApp beginSheet: panFileDataEditor modalForWindow: window modalDelegate: self didEndSelector: @selector(customSheetDidClose:returnCode:contextInfo:) contextInfo: nil];

}

I'm using a NSPanel for my sheet, I was thinking I could get its frame and check the y location to determine its status but I wanted to check to see if there was an accepted way of doing this...

2

There are 2 best solutions below

0
jscs On
BOOL hasSheet = ([window attachedSheet] != nil);

is only meant to test whether the sheet exists; -[NSWindow attachedSheet] will return the sheet if it's there, or nil if not. I'm not clear on what "state" you're trying to get, but

NSWindow * theSheet = [window attachedSheet];

does give you the sheet itself. From there you can do whatever you like: [theSheet frame], e.g.

0
Nathan Kinsinger On

Cocoa is an event based system so you don't wait for things to happen in a while loop, instead methods you write are called by the system when things happen. So no while loops.

You implement the customSheetDidClose:returnCode:contextInfo: method (not call it) in your class and it will be called when the sheet closes.

If you want custom things to happen when the sheet is open create a subclass of NSWindowController to handle the sheet.