From 94e4efed2d7d174586dffdef1c8df47f43aeee8f Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 8 Nov 2007 20:14:34 +0100 Subject: [PATCH] Don't attempt to open dropped file that is already open When a file is dropped, each Vim process is checked to see if the file is already open. If so, raise the corresponding window and select the tab that holds the opened file. Only works when one file is dropped. --- src/MacVim/MMAppController.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index f6815a7919..652ca91133 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -181,15 +181,20 @@ static NSTimeInterval MMReplyTimeout = 5; for (i = 0; i < count; ++i) { MMVimController *controller = [vimControllers objectAtIndex:i]; id proxy = [controller backendProxy]; + NSString *file = [[files objectAtIndex:0] + stringByEscapingSpecialFilenameCharacters]; @try { NSString *expr = [NSString stringWithFormat: - @"bufloaded(\"%@\")", [files objectAtIndex:0]]; + @"bufloaded(\"%@\")", file]; NSString *eval = [proxy evaluateExpression:expr]; if ([eval isEqual:@"1"]) { // TODO: Select the tab with 'file' open. - [controller addVimInput: - @":cal foreground()"]; + NSString *input = [NSString stringWithFormat:@"" + ":let oldswb=&swb|let &swb=\"useopen,usetab\"|" + "tab sb %@|let &swb=oldswb|unl oldswb|" + "cal foreground()|redr|f", file]; + [controller addVimInput:input]; return; } }