From 232024f71d816debd0d67dc8aa8bc6333221da6b Mon Sep 17 00:00:00 2001 From: Ron Olson Date: Sun, 14 Sep 2008 20:47:55 -0500 Subject: [PATCH] Add "New Document Here" Service The "New Document Here" service will create a blank document in the currently selected directory. If new files are set to open in the current window, then the blank document opens in a new tab in the topmost window, otherwise a new window is opened. --- src/MacVim/Info.plist | 17 +++++++++++++++ src/MacVim/MMAppController.m | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/MacVim/Info.plist b/src/MacVim/Info.plist index 9474e5da20..2a681fc971 100644 --- a/src/MacVim/Info.plist +++ b/src/MacVim/Info.plist @@ -614,6 +614,23 @@ NSUserData Window + + NSMenuItem + + default + MacVim/New Document Here + + NSMessage + newFileHere + NSPortName + MacVim + NSSendTypes + + NSStringPboardType + + NSUserData + Window + SUFeedURL http://bjorn.winckler.googlepages.com/macvim_latest.xml diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 4b94982503..b80cd256c7 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -94,6 +94,8 @@ static int executeInLoginShell(NSString *path, NSArray *args); error:(NSString **)error; - (void)openFile:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error; +- (void)newFileHere:(NSPasteboard *)pboard userData:(NSString *)userData + error:(NSString **)error; @end @@ -1181,6 +1183,44 @@ fsEventCallback(ConstFSEventStreamRef streamRef, } } +- (void)newFileHere:(NSPasteboard *)pboard userData:(NSString *)userData + error:(NSString **)error +{ + if (![[pboard types] containsObject:NSStringPboardType]) { + NSLog(@"WARNING: Pasteboard contains no object of type " + "NSStringPboardType"); + return; + } + + NSString *path = [pboard stringForType:NSStringPboardType]; + + BOOL dirIndicator; + if (![[NSFileManager defaultManager] fileExistsAtPath:path + isDirectory:&dirIndicator]) { + NSLog(@"Invalid path. Cannot open new document at: %@", path); + return; + } + + if (!dirIndicator) + path = [path stringByDeletingLastPathComponent]; + + path = [path stringByReplacingOccurrencesOfString:@" " withString:@"\\ "]; + + MMVimController *vc = [self topmostVimController]; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + BOOL openInCurrentWindow = [ud boolForKey:MMOpenInCurrentWindowKey]; + + if (vc && openInCurrentWindow) { + NSString *input = [NSString stringWithFormat:@"" + ":tabe|cd %@", path]; + [vc addVimInput:input]; + } else { + NSString *input = [NSString stringWithFormat:@":cd %@", path]; + [self launchVimProcessWithArguments:[NSArray arrayWithObjects: + @"-c", input, nil]]; + } +} + @end // MMAppController (MMServices)