mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Add file manager support for ‘new file’
This commit is contained in:
@@ -7,6 +7,7 @@ PUBLIC extern NSString* const OakFileManagerPathKey;
|
||||
PUBLIC @interface OakFileManager : NSObject
|
||||
+ (OakFileManager*)sharedInstance;
|
||||
- (NSURL*)createUntitledDirectoryAtURL:(NSURL*)anURL window:(NSWindow*)window;
|
||||
- (BOOL)createFileAtURL:(NSURL*)anURL window:(NSWindow*)window;
|
||||
- (NSURL*)createDuplicateOfURL:(NSURL*)srcURL window:(NSWindow*)window;
|
||||
- (void)createSymbolicLinkAtURL:(NSURL*)anURL withDestinationURL:(NSURL*)dstURL window:(NSWindow*)window;
|
||||
- (BOOL)renameItemAtURL:(NSURL*)srcURL toURL:(NSURL*)dstURL window:(NSWindow*)window;
|
||||
|
||||
@@ -73,6 +73,33 @@ NSString* const OakFileManagerPathKey = @"directory";
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)doCreateFile:(NSURL*)fileURL window:(NSWindow*)window
|
||||
{
|
||||
int fd = open([[fileURL path] fileSystemRepresentation], O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
|
||||
if(fd != -1)
|
||||
{
|
||||
close(fd);
|
||||
[[[window undoManager] prepareWithInvocationTarget:self] doRemoveFile:fileURL window:window];
|
||||
[self postDidChangeContentsOfDirectory:[[fileURL path] stringByDeletingLastPathComponent]];
|
||||
}
|
||||
return fd != -1;
|
||||
}
|
||||
|
||||
- (void)doRemoveFile:(NSURL*)fileURL window:(NSWindow*)window
|
||||
{
|
||||
NSError* error;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:OakFileManagerWillDeleteItemAtPath object:self userInfo:@{ OakFileManagerPathKey : [[fileURL filePathURL] path] }];
|
||||
if([[NSFileManager defaultManager] removeItemAtURL:fileURL error:&error])
|
||||
{
|
||||
[[[window undoManager] prepareWithInvocationTarget:self] doCreateFile:fileURL window:window];
|
||||
[self postDidChangeContentsOfDirectory:[[fileURL path] stringByDeletingLastPathComponent]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[window presentError:error];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)doCreateCopy:(NSURL*)dstURL ofURL:(NSURL*)srcURL window:(NSWindow*)window
|
||||
{
|
||||
BOOL res;
|
||||
@@ -229,6 +256,16 @@ NSString* const OakFileManagerPathKey = @"directory";
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)createFileAtURL:(NSURL*)anURL window:(NSWindow*)window
|
||||
{
|
||||
if([self doCreateFile:anURL window:window])
|
||||
{
|
||||
[[window undoManager] setActionName:@"New Document"];
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSURL*)createDuplicateOfURL:(NSURL*)srcURL window:(NSWindow*)window
|
||||
{
|
||||
NSURL* dst = [NSURL fileURLWithPath:[NSString stringWithCxxString:path::unique([[srcURL path] fileSystemRepresentation], " copy")]];
|
||||
|
||||
Reference in New Issue
Block a user