//// BWSheetController.m// BWToolkit//// Created by Brandon Walkin (www.brandonwalkin.com)// All code is provided under the New BSD license.//#import "BWSheetController.h"#import "NSWindow-NSTimeMachineSupport.h"@implementationBWSheetController@synthesizeparentWindow,sheet,delegate;-(void)awakeFromNib{// Hack so the sheet doesn't appear at launch in Cocoa Simulator (or in the actual app if "Visible at Launch" is checked)[sheetsetAlphaValue:0];[sheetperformSelector:@selector(orderOut:)withObject:nilafterDelay:0];// If the sheet has a toolbar or a bottom bar, make sure those elements can't move the window (private API)if([sheetrespondsToSelector:@selector(setMovable:)])[sheetsetMovable:NO];}-(id)initWithCoder:(NSCoder*)decoder;{if((self=[superinit])!=nil){NSWindowController*tempSheetController=[decoderdecodeObjectForKey:@"BWSCSheet"];NSWindowController*tempParentWindowController=[decoderdecodeObjectForKey:@"BWSCParentWindow"];sheet=[tempSheetControllerwindow];parentWindow=[tempParentWindowControllerwindow];}returnself;}-(void)encodeWithCoder:(NSCoder*)coder{NSWindowController*tempSheetController=[[[NSWindowControlleralloc]initWithWindow:sheet]autorelease];NSWindowController*tempParentWindowController=[[[NSWindowControlleralloc]initWithWindow:parentWindow]autorelease];[coderencodeObject:tempSheetControllerforKey:@"BWSCSheet"];[coderencodeObject:tempParentWindowControllerforKey:@"BWSCParentWindow"];}-(IBAction)openSheet:(id)sender{[sheetsetAlphaValue:1];[NSAppbeginSheet:sheetmodalForWindow:parentWindowmodalDelegate:nildidEndSelector:nilcontextInfo:nil];}-(IBAction)closeSheet:(id)sender{[sheetorderOut:nil];[NSAppendSheet:sheet];}-(IBAction)messageDelegateAndCloseSheet:(id)sender{if(delegate!=nil&&[delegaterespondsToSelector:@selector(shouldCloseSheet:)]){if([delegateperformSelector:@selector(shouldCloseSheet:)withObject:sender])[selfcloseSheet:self];}else{[selfcloseSheet:self];}}@end