diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 91f908e36d..8ee2626a36 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -839,9 +839,11 @@ static BOOL isUnsafeMessage(int msgid); if (dict) [self handleBrowseForFile:dict]; } else if (ShowDialogMsgID == msgid) { - NSDictionary *dict = [NSDictionary dictionaryWithData:data]; - if (dict) - [self handleShowDialog:dict]; + [windowController runAfterWindowPresentedUsingBlock:^{ + NSDictionary *dict = [NSDictionary dictionaryWithData:data]; + if (dict) + [self handleShowDialog:dict]; + }]; } else if (DeleteSignMsgID == msgid) { NSDictionary *dict = [NSDictionary dictionaryWithData:data]; if (dict) diff --git a/src/MacVim/MMWindowController.h b/src/MacVim/MMWindowController.h index 34c3a95fac..6a9d6b6eba 100644 --- a/src/MacVim/MMWindowController.h +++ b/src/MacVim/MMWindowController.h @@ -43,6 +43,7 @@ NSToolbar *toolbar; BOOL resizingDueToMove; int blurRadius; + NSMutableArray *afterWindowPresentedQueue; } - (id)initWithVimController:(MMVimController *)controller; @@ -89,6 +90,7 @@ - (void)setBufferModified:(BOOL)mod; - (void)setTopLeft:(NSPoint)pt; - (BOOL)getDefaultTopLeft:(NSPoint*)pt; +- (void)runAfterWindowPresentedUsingBlock:(void (^)(void))block; - (IBAction)addNewTab:(id)sender; - (IBAction)toggleToolbar:(id)sender; diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index dbdce57071..d838afbb73 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -105,6 +105,7 @@ - (BOOL)maximizeWindow:(int)options; - (void)applicationDidChangeScreenParameters:(NSNotification *)notification; - (void)enterNativeFullScreen; +- (void)processAfterWindowPresentedQueue; @end @@ -236,6 +237,8 @@ [windowAutosaveKey release]; windowAutosaveKey = nil; [vimView release]; vimView = nil; [toolbar release]; toolbar = nil; + // in case processAfterWindowPresentedQueue wasn't called + [afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil; [super dealloc]; } @@ -344,6 +347,9 @@ // code to depend on the screen state. (Such as constraining views etc.) windowPresented = YES; + // Process deferred blocks + [self processAfterWindowPresentedQueue]; + if (fullScreenWindow) { // Delayed entering of full-screen happens here (a ":set fu" in a // GUIEnter auto command could cause this). @@ -1329,6 +1335,19 @@ #endif // (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) +- (void)runAfterWindowPresentedUsingBlock:(void (^)(void))block +{ + if (windowPresented) { // no need to defer block, just run it now + block(); + return; + } + + // run block later + if (afterWindowPresentedQueue == nil) + afterWindowPresentedQueue = [[NSMutableArray alloc] init]; + [afterWindowPresentedQueue addObject:[block copy]]; +} + @end // MMWindowController @@ -1665,5 +1684,12 @@ [decoratedWindow realToggleFullScreen:self]; } +- (void)processAfterWindowPresentedQueue +{ + for (void (^block)(void) in afterWindowPresentedQueue) + block(); + + [afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil; +} @end // MMWindowController (Private)