// // PanelController.m // Perforce // // Created by Adam Czubernat on 11.07.2013. // Copyright (c) 2013 Perforce Software, Inc. All rights reserved. // #import "PanelController.h" @implementation PanelController { __strong id retain; } @synthesize parentWindow; - (id)init { return self = [super initWithWindowNibName:NSStringFromClass([self class])]; } - (void)windowDidLoad { [super windowDidLoad]; [self.window setPreventsApplicationTerminationWhenModal:NO]; } - (void)presentWithMainWindow { NSWindow *window = [[NSApplication sharedApplication] mainWindow]; [self presentWithWindow:window]; } - (void)presentWithWindow:(NSWindow *)window { parentWindow = window; retain = self; if (![window isVisible]) [window makeKeyAndOrderFront:nil]; while ([window attachedSheet]) window = [window attachedSheet]; // Traverse through sheets [[NSApplication sharedApplication] beginSheet:self.window modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:NULL]; } - (void)dismiss { [[NSApplication sharedApplication] endSheet:self.window]; [self close]; retain = nil; } - (void)setPresentedView:(NSView *)view { [self setPresentedView:view animated:NO]; } - (void)setPresentedView:(NSView *)view animated:(BOOL)animated { [presentedView removeFromSuperview]; presentedView = view; CGRect viewFrame = view.frame; CGRect windowFrame = self.window.frame; windowFrame.origin.x += (NSInteger)(windowFrame.size.width - viewFrame.size.width)/2; windowFrame.origin.y += windowFrame.size.height - viewFrame.size.height; windowFrame.size = viewFrame.size; [self.window.contentView setFrame:viewFrame]; [self.window setFrame:windowFrame display:YES animate:animated]; [self.window.contentView addSubview:view]; } - (void)dismissAfter:(NSTimeInterval)delay { [self performSelector:@selector(dismiss) withObject:nil afterDelay:delay]; } - (void)presentExclusiveWithWindow:(NSWindow *)window { NSWindow *attachedSheet = [window attachedSheet]; if (attachedSheet) { [[NSApplication sharedApplication] endSheet:attachedSheet]; [attachedSheet close]; } [self presentWithWindow:window]; } @end