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.
This commit is contained in:
Ron Olson
2008-09-14 20:47:55 -05:00
committed by Bjorn Winckler
parent 2e22c44eab
commit 232024f71d
2 changed files with 57 additions and 0 deletions
+17
View File
@@ -614,6 +614,23 @@
<key>NSUserData</key>
<string>Window</string>
</dict>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>MacVim/New Document Here</string>
</dict>
<key>NSMessage</key>
<string>newFileHere</string>
<key>NSPortName</key>
<string>MacVim</string>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
<key>NSUserData</key>
<string>Window</string>
</dict>
</array>
<key>SUFeedURL</key>
<string>http://bjorn.winckler.googlepages.com/macvim_latest.xml</string>
+40
View File
@@ -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:@"<C-\\><C-N>"
":tabe|cd %@<CR>", path];
[vc addVimInput:input];
} else {
NSString *input = [NSString stringWithFormat:@":cd %@", path];
[self launchVimProcessWithArguments:[NSArray arrayWithObjects:
@"-c", input, nil]];
}
}
@end // MMAppController (MMServices)