Show warning when undo deletes non-empty folder

Closes issue #782.
This commit is contained in:
Allan Odgaard
2013-03-26 17:41:51 +01:00
parent fe487c1a66
commit 4937b51d02

View File

@@ -62,6 +62,15 @@ NSString* const OakFileManagerPathKey = @"directory";
- (void)doRemoveDirectory:(NSURL*)dirURL window:(NSWindow*)window
{
NSError* error;
NSArray* contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:dirURL includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsHiddenFiles error:&error];
if([contents count] != 0)
{
NSInteger choice = NSRunCriticalAlertPanel(@"Folder Not Empty!", [self expandFormat:@"Do you wish to delete “%@” and all the contained items?" withURL:dirURL], @"Delete Folder", @"Cancel", nil);
if(choice == NSAlertAlternateReturn) // "Cancel"
return;
}
if([[NSFileManager defaultManager] removeItemAtURL:dirURL error:&error])
{
[[[window undoManager] prepareWithInvocationTarget:self] doCreateDirectory:dirURL window:window];