Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved panel presenting

- you can now present a new modal panel right after dismissing a previous one.
  • Loading branch information...
commit cc3213134b4b729334dcc79ed3af762b4369887e 1 parent d606786
@Cocoanetics authored
Showing with 9 additions and 12 deletions.
  1. +9 −12 Core/Source/OSX/NSWindowController+DTPanelControllerPresenting.m
View
21 Core/Source/OSX/NSWindowController+DTPanelControllerPresenting.m
@@ -16,13 +16,12 @@ @implementation NSWindowController (DTPanelControllerPresenting)
#pragma mark - Private Methods
-// called as a result of the sheed ending notification
-- (void)_didFinishDismissingPanel:(NSNotification *)notification
+// called as a result of the sheed ending
+- (void)_didFinishDismissingSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
{
- // remove notification
- [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidEndSheetNotification object:self.window];
+ NSAssert(contextInfo == &DTPresentedViewControllerDismissalQueueKey, @"Incorrect context info");
- // dismiss the panel controller
+ // release the panel controller
objc_setAssociatedObject(self, &DTPresentedViewControllerDismissalQueueKey, nil, OBJC_ASSOCIATION_RETAIN);
}
@@ -37,11 +36,12 @@ - (void)presentModalPanelController:(NSWindowController *)panelController
NSLog(@"Already presenting %@, cannot modally present another panel", NSStringFromClass([windowController class]));
return;
}
-
- [NSApp beginSheet:panelController.window modalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil];
-
+
// retain the panel view controller
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
@@ -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
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
[windowController.window close];
[NSApp endSheet:windowController.window];
- // free the reference
+ // free the controller reference
objc_setAssociatedObject(self, &DTPresentedViewControllerKey, nil, OBJC_ASSOCIATION_RETAIN);
}
Please sign in to comment.
Something went wrong with that request. Please try again.