From e6a1df5c808d6bf695bf0fdaed70a7e3417a6610 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Tue, 16 Feb 2010 19:04:47 +0100 Subject: [PATCH] Do not open files in "unused windows" A window is "unused" if it has just been opened with Cmd+n. Previously a file opened from Finder would be opened in an unused window if one was available. This leads to problems with some Vim options, e.g. trying to open an encrypted file from Spotlight will fail. The code that has been removed also had some quite ugly hacks and it is not entirely clear whether the reuse of unused windows was entirely intuitive. (The "Open files from applications" option is not affected by this change.) --- src/MacVim/MMAppController.m | 22 +--------------------- src/MacVim/MMBackend.m | 1 - src/MacVim/MMVimController.m | 11 ----------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 3a55ffe5..53e7a800 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -117,7 +117,6 @@ typedef struct #endif - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event replyEvent:(NSAppleEventDescriptor *)reply; -- (MMVimController *)findUnusedEditor; - (NSMutableDictionary *)extractArgumentsFromOdocEvent: (NSAppleEventDescriptor *)desc; - (void)scheduleVimControllerPreloadAfterDelay:(NSTimeInterval)delay; @@ -1716,18 +1715,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef, } } -- (MMVimController *)findUnusedEditor -{ - NSEnumerator *e = [vimControllers objectEnumerator]; - id vc; - while ((vc = [e nextObject])) { - if ([[vc objectForVimStateKey:@"unusedEditor"] boolValue]) - return vc; - } - - return nil; -} - - (NSMutableDictionary *)extractArgumentsFromOdocEvent: (NSAppleEventDescriptor *)desc { @@ -2009,15 +1996,8 @@ fsEventCallback(ConstFSEventStreamRef streamRef, - (BOOL)openVimControllerWithArguments:(NSDictionary *)arguments { - MMVimController *vc = [self findUnusedEditor]; + MMVimController *vc = [self takeVimControllerFromCache]; if (vc) { - // Open files in an already open window. - // TODO: If the file is encrypted (with -x) then opening in an unused - // window will fail if there are more arguments than just the filename - // (the same goes with cached Vim controllers). - [[[vc windowController] window] makeKeyAndOrderFront:self]; - [vc passArguments:arguments]; - } else if ((vc = [self takeVimControllerFromCache])) { // Open files in a new window using a cached vim controller. This // requires virtually no loading time so the new window will pop up // instantaneously. diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 17b03864..4c6291e6 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1713,7 +1713,6 @@ static void netbeansReadCallback(CFSocketRef s, NSDictionary *vimState = [NSDictionary dictionaryWithObjectsAndKeys: [[NSFileManager defaultManager] currentDirectoryPath], @"pwd", [NSNumber numberWithInt:p_mh], @"p_mh", - [NSNumber numberWithBool:[self unusedEditor]], @"unusedEditor", [NSNumber numberWithBool:mmta], @"p_mmta", [NSNumber numberWithInt:numTabs], @"numTabs", nil]; diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index ae376219..279cf8f8 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -324,17 +324,6 @@ static BOOL isUnsafeMessage(int msgid); ASLogDebug(@"args=%@", args); [self sendMessage:OpenWithArgumentsMsgID data:[args dictionaryAsData]]; - - // HACK! Fool findUnusedEditor into thinking that this controller is not - // unused anymore, in case it is called before the arguments have reached - // the Vim process. This should be a "safe" hack since the next time the - // Vim process flushes its output queue the state will be updated again (at - // which time the "unusedEditor" state will have been properly set). - NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary: - vimState]; - [dict setObject:[NSNumber numberWithBool:NO] forKey:@"unusedEditor"]; - [vimState release]; - vimState = [dict copy]; } - (void)sendMessage:(int)msgid data:(NSData *)data -- 2.11.4.GIT