Skip to content

Commit

Permalink
Improved panel presenting
Browse files Browse the repository at this point in the history
- you can now present a new modal panel right after dismissing a previous one.
  • Loading branch information
odrobnik committed Feb 14, 2013
1 parent d606786 commit cc32131
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Core/Source/OSX/NSWindowController+DTPanelControllerPresenting.m
Expand Up @@ -16,13 +16,12 @@ @implementation NSWindowController (DTPanelControllerPresenting)


#pragma mark - Private Methods #pragma mark - Private Methods


// called as a result of the sheed ending notification // called as a result of the sheed ending
- (void)_didFinishDismissingPanel:(NSNotification *)notification - (void)_didFinishDismissingSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
{ {
// remove notification NSAssert(contextInfo == &DTPresentedViewControllerDismissalQueueKey, @"Incorrect context info");
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidEndSheetNotification object:self.window];


// dismiss the panel controller // release the panel controller
objc_setAssociatedObject(self, &DTPresentedViewControllerDismissalQueueKey, nil, OBJC_ASSOCIATION_RETAIN); objc_setAssociatedObject(self, &DTPresentedViewControllerDismissalQueueKey, nil, OBJC_ASSOCIATION_RETAIN);
} }


Expand All @@ -37,11 +36,12 @@ - (void)presentModalPanelController:(NSWindowController *)panelController
NSLog(@"Already presenting %@, cannot modally present another panel", NSStringFromClass([windowController class])); NSLog(@"Already presenting %@, cannot modally present another panel", NSStringFromClass([windowController class]));
return; return;
} }


[NSApp beginSheet:panelController.window modalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil];

// retain the panel view controller // retain the panel view controller
objc_setAssociatedObject(self, &DTPresentedViewControllerKey, panelController, OBJC_ASSOCIATION_RETAIN); objc_setAssociatedObject(self, &DTPresentedViewControllerKey, panelController, OBJC_ASSOCIATION_RETAIN);

// begin the sheet and set our own custom didEndElector which frees the controller
[NSApp beginSheet:panelController.window modalForWindow:self.window modalDelegate:self didEndSelector:@selector(_didFinishDismissingSheet:returnCode:contextInfo:) contextInfo:&DTPresentedViewControllerDismissalQueueKey];
} }


- (void)dismissModalPanelController - (void)dismissModalPanelController
Expand All @@ -57,14 +57,11 @@ - (void)dismissModalPanelController
// retain it in the dismissal queue so that we can present a new one right after the out animation has finished // retain it in the dismissal queue so that we can present a new one right after the out animation has finished
objc_setAssociatedObject(self, &DTPresentedViewControllerDismissalQueueKey, windowController, OBJC_ASSOCIATION_RETAIN); objc_setAssociatedObject(self, &DTPresentedViewControllerDismissalQueueKey, windowController, OBJC_ASSOCIATION_RETAIN);


// get notified if panel has been dismissed
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didFinishDismissingPanel:) name:NSWindowDidEndSheetNotification object:self.window];

// dismiss the panel // dismiss the panel
[windowController.window close]; [windowController.window close];
[NSApp endSheet:windowController.window]; [NSApp endSheet:windowController.window];


// free the reference // free the controller reference
objc_setAssociatedObject(self, &DTPresentedViewControllerKey, nil, OBJC_ASSOCIATION_RETAIN); objc_setAssociatedObject(self, &DTPresentedViewControllerKey, nil, OBJC_ASSOCIATION_RETAIN);
} }


Expand Down

0 comments on commit cc32131

Please sign in to comment.