Skip to content

Commit e5d8722

Browse files
authored
Merge pull request #308 from steakknife/fix_256__defer_nsalerts
Defer alerts until the window is shown
2 parents c9b378e + d002b40 commit e5d8722

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/MacVim/MMVimController.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,11 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
839839
if (dict)
840840
[self handleBrowseForFile:dict];
841841
} else if (ShowDialogMsgID == msgid) {
842-
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
843-
if (dict)
844-
[self handleShowDialog:dict];
842+
[windowController runAfterWindowPresentedUsingBlock:^{
843+
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
844+
if (dict)
845+
[self handleShowDialog:dict];
846+
}];
845847
} else if (DeleteSignMsgID == msgid) {
846848
NSDictionary *dict = [NSDictionary dictionaryWithData:data];
847849
if (dict)

src/MacVim/MMWindowController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
NSToolbar *toolbar;
4444
BOOL resizingDueToMove;
4545
int blurRadius;
46+
NSMutableArray *afterWindowPresentedQueue;
4647
}
4748

4849
- (id)initWithVimController:(MMVimController *)controller;
@@ -89,6 +90,7 @@
8990
- (void)setBufferModified:(BOOL)mod;
9091
- (void)setTopLeft:(NSPoint)pt;
9192
- (BOOL)getDefaultTopLeft:(NSPoint*)pt;
93+
- (void)runAfterWindowPresentedUsingBlock:(void (^)(void))block;
9294

9395
- (IBAction)addNewTab:(id)sender;
9496
- (IBAction)toggleToolbar:(id)sender;

src/MacVim/MMWindowController.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ - (void)updateToolbar;
105105
- (BOOL)maximizeWindow:(int)options;
106106
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification;
107107
- (void)enterNativeFullScreen;
108+
- (void)processAfterWindowPresentedQueue;
108109
@end
109110

110111

@@ -236,6 +237,8 @@ - (void)dealloc
236237
[windowAutosaveKey release]; windowAutosaveKey = nil;
237238
[vimView release]; vimView = nil;
238239
[toolbar release]; toolbar = nil;
240+
// in case processAfterWindowPresentedQueue wasn't called
241+
[afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil;
239242

240243
[super dealloc];
241244
}
@@ -344,6 +347,9 @@ - (BOOL)presentWindow:(id)unused
344347
// code to depend on the screen state. (Such as constraining views etc.)
345348
windowPresented = YES;
346349

350+
// Process deferred blocks
351+
[self processAfterWindowPresentedQueue];
352+
347353
if (fullScreenWindow) {
348354
// Delayed entering of full-screen happens here (a ":set fu" in a
349355
// GUIEnter auto command could cause this).
@@ -1329,6 +1335,19 @@ - (void)windowDidFailToExitFullScreen:(NSWindow *)window
13291335

13301336
#endif // (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
13311337

1338+
- (void)runAfterWindowPresentedUsingBlock:(void (^)(void))block
1339+
{
1340+
if (windowPresented) { // no need to defer block, just run it now
1341+
block();
1342+
return;
1343+
}
1344+
1345+
// run block later
1346+
if (afterWindowPresentedQueue == nil)
1347+
afterWindowPresentedQueue = [[NSMutableArray alloc] init];
1348+
[afterWindowPresentedQueue addObject:[block copy]];
1349+
}
1350+
13321351
@end // MMWindowController
13331352

13341353

@@ -1665,5 +1684,12 @@ - (void)enterNativeFullScreen
16651684
[decoratedWindow realToggleFullScreen:self];
16661685
}
16671686

1687+
- (void)processAfterWindowPresentedQueue
1688+
{
1689+
for (void (^block)(void) in afterWindowPresentedQueue)
1690+
block();
1691+
1692+
[afterWindowPresentedQueue release]; afterWindowPresentedQueue = nil;
1693+
}
16681694
@end // MMWindowController (Private)
16691695

0 commit comments

Comments
 (0)