|
10 | 10 | #import "PBChangedFile.h"
|
11 | 11 | #import "PBGitRepository.h"
|
12 | 12 | #import "PBGitIndex.h"
|
| 13 | +#import "PBGitDefaults.h" |
13 | 14 |
|
14 | 15 | #define FileChangesTableViewType @"GitFileChangedType"
|
| 16 | +#define kDialogDeleteFiles @"Delete Files" |
15 | 17 |
|
16 | 18 | @interface PBGitIndexController ()
|
17 | 19 | - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force;
|
@@ -105,12 +107,18 @@ - (NSMenu *) menuForTable:(NSTableView *)table
|
105 | 107 | [menu addItem:unstageItem];
|
106 | 108 | }
|
107 | 109 |
|
108 |
| - NSString *title = [selectedFiles count] == 1 ? @"Open file" : @"Open files"; |
109 |
| - NSMenuItem *openItem = [[NSMenuItem alloc] initWithTitle:title action:@selector(openFilesAction:) keyEquivalent:@""]; |
| 110 | + NSString *openTitle = [selectedFiles count] == 1 ? @"Open file" : @"Open files"; |
| 111 | + NSMenuItem *openItem = [[NSMenuItem alloc] initWithTitle:openTitle action:@selector(openFilesAction:) keyEquivalent:@""]; |
110 | 112 | [openItem setTarget:self];
|
111 | 113 | [openItem setRepresentedObject:selectedFiles];
|
112 | 114 | [menu addItem:openItem];
|
113 | 115 |
|
| 116 | + NSString *deleteTitle = [selectedFiles count] == 1 ? @"Delete file…" : @"Delete files…"; |
| 117 | + NSMenuItem *deleteItem = [[NSMenuItem alloc] initWithTitle:deleteTitle action:@selector(showDeleteFilesSheet:) keyEquivalent:@""]; |
| 118 | + [deleteItem setTarget:self]; |
| 119 | + [deleteItem setRepresentedObject:selectedFiles]; |
| 120 | + [menu addItem:deleteItem]; |
| 121 | + |
114 | 122 | // Attempt to ignore
|
115 | 123 | if ([self allSelectedCanBeIgnored:selectedFiles]) {
|
116 | 124 | NSString *ignoreText = [selectedFiles count] == 1 ? @"Ignore File": @"Ignore Files";
|
@@ -178,6 +186,60 @@ - (void) openFilesAction:(id) sender
|
178 | 186 | [[NSWorkspace sharedWorkspace] openFile:[workingDirectory stringByAppendingPathComponent:[file path]]];
|
179 | 187 | }
|
180 | 188 |
|
| 189 | +- (void) doDeleteFiles:(NSArray *)files { |
| 190 | + NSString *workingDirectory = [[commitController.repository workingDirectory] stringByAppendingString:@"/"]; |
| 191 | + NSString *path; |
| 192 | + NSArray *filenamesArray; |
| 193 | + NSWorkspace *ws = [NSWorkspace sharedWorkspace]; |
| 194 | + |
| 195 | + for (PBChangedFile *file in files) { |
| 196 | + path = [workingDirectory stringByAppendingPathComponent:[file path]]; |
| 197 | + filenamesArray = [NSArray arrayWithObject:[path lastPathComponent]]; |
| 198 | + [ws performFileOperation:NSWorkspaceRecycleOperation source:[path stringByDeletingLastPathComponent] destination:@"" files:filenamesArray tag:nil]; |
| 199 | + } |
| 200 | + [commitController.index refresh]; |
| 201 | +} |
| 202 | + |
| 203 | +- (void)showDeleteFilesSheet:(id)sender |
| 204 | +{ |
| 205 | + NSArray *files = [sender representedObject]; |
| 206 | + NSMutableString *filesPathsString = [[NSMutableString alloc] init]; |
| 207 | + |
| 208 | + for (PBChangedFile *file in files) { |
| 209 | + [filesPathsString appendString:[file path]]; |
| 210 | + [filesPathsString appendString:@"\n"]; |
| 211 | + } |
| 212 | + |
| 213 | + if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogDeleteFiles]) { |
| 214 | + [self doDeleteFiles:files]; |
| 215 | + return; |
| 216 | + } |
| 217 | + |
| 218 | + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete files?"] |
| 219 | + defaultButton:@"Delete" |
| 220 | + alternateButton:@"Cancel" |
| 221 | + otherButton:nil |
| 222 | + informativeTextWithFormat:@"Are you sure you want to move the following files to the trash?\n\n%@\nYou cannot undo this operation.", filesPathsString]; |
| 223 | + [alert setShowsSuppressionButton:YES]; |
| 224 | + |
| 225 | + [alert beginSheetModalForWindow:[[commitController view] window] |
| 226 | + modalDelegate:self |
| 227 | + didEndSelector:@selector(deleteFilesSheetDidEnd:returnCode:contextInfo:) |
| 228 | + contextInfo:(__bridge void *) files]; |
| 229 | +} |
| 230 | + |
| 231 | +- (void)deleteFilesSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo |
| 232 | +{ |
| 233 | + if ([[sheet suppressionButton] state] == NSOnState) |
| 234 | + [PBGitDefaults suppressDialogWarningForDialog:kDialogDeleteFiles]; |
| 235 | + |
| 236 | + NSArray *files = (__bridge NSArray*) contextInfo; |
| 237 | + |
| 238 | + if (returnCode == NSAlertDefaultReturn) { |
| 239 | + [self doDeleteFiles:files]; |
| 240 | + } |
| 241 | +} |
| 242 | + |
181 | 243 | - (void) ignoreFilesAction:(id) sender
|
182 | 244 | {
|
183 | 245 | NSArray *selectedFiles = [sender representedObject];
|
|
0 commit comments