Skip to content

Commit b8d69df

Browse files
committed
Ask for confirmation before trashing files
Fixes #98
1 parent 9c4534e commit b8d69df

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

Classes/Controllers/PBGitCommitController.m

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -299,24 +299,35 @@ - (IBAction)moveToTrash:(id)sender
299299

300300
NSURL *workingDirectoryURL = self.repository.workingDirectoryURL;
301301

302-
BOOL anyTrashed = NO;
303-
for (PBChangedFile *file in selectedFiles)
304-
{
305-
NSURL* fileURL = [workingDirectoryURL URLByAppendingPathComponent:[file path]];
302+
NSAlert *confirmTrash = [[NSAlert alloc] init];
303+
confirmTrash.alertStyle = NSAlertStyleWarning;
304+
confirmTrash.messageText = NSLocalizedString(@"Move to trash", @"Move to trash alert - title");
305+
confirmTrash.informativeText = NSLocalizedString(@"Do you want to move the following files to the trash ?", @"Move to trash alert - message");
306+
[confirmTrash addButtonWithTitle:NSLocalizedString(@"OK", @"Move to trash alert - OK button")];
307+
[confirmTrash addButtonWithTitle:NSLocalizedString(@"Cancel", @"Move to trash alert - Cancel button")];
308+
309+
[confirmTrash beginSheetModalForWindow:self.windowController.window completionHandler:^(NSModalResponse returnCode) {
310+
if (returnCode != NSAlertFirstButtonReturn) return;
306311

307-
NSError* error = nil;
308-
NSURL* resultURL = nil;
309-
if ([[NSFileManager defaultManager] trashItemAtURL:fileURL
310-
resultingItemURL:&resultURL
311-
error:&error])
312+
BOOL anyTrashed = NO;
313+
for (PBChangedFile *file in selectedFiles)
312314
{
313-
anyTrashed = YES;
315+
NSURL* fileURL = [workingDirectoryURL URLByAppendingPathComponent:[file path]];
316+
317+
NSError* error = nil;
318+
NSURL* resultURL = nil;
319+
if ([[NSFileManager defaultManager] trashItemAtURL:fileURL
320+
resultingItemURL:&resultURL
321+
error:&error])
322+
{
323+
anyTrashed = YES;
324+
}
314325
}
315-
}
316-
if (anyTrashed)
317-
{
318-
[self.repository.index refresh];
319-
}
326+
if (anyTrashed)
327+
{
328+
[self.repository.index refresh];
329+
}
330+
}];
320331
}
321332

322333
- (IBAction)ignoreFiles:(id) sender

0 commit comments

Comments
 (0)