Reset now asks user for confirmation

This commit is contained in:
Tomasz Krasnyk
2010-11-28 22:51:47 +01:00
parent 71e9e2cc43
commit 27e490c405
+28 -1
View File
@@ -10,6 +10,8 @@
#import "PBGitRepository.h"
#import "PBCommand.h"
static NSString * const kCommandKey = @"command";
@implementation PBGitResetController
- (id) initWithRepository:(PBGitRepository *) repo {
@@ -20,11 +22,23 @@
}
- (void) resetHardToHead {
NSAlert *alert = [NSAlert alertWithMessageText:@"Reseting working copy and index"
defaultButton:@"Cancel"
alternateButton:nil
otherButton:@"Reset"
informativeTextWithFormat:@"Are you sure you want to reset your working copy and index? All changes to them will be gone!"];
NSArray *arguments = [NSArray arrayWithObjects:@"reset", @"--hard", @"HEAD", nil];
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset hard to HEAD" parameters:arguments repository:repository];
cmd.commandTitle = cmd.displayName;
cmd.commandDescription = @"Reseting head";
[cmd invoke];
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithObject:cmd forKey:kCommandKey];
[alert beginSheetModalForWindow:[repository.windowController window]
modalDelegate:self
didEndSelector:@selector(confirmResetSheetDidEnd:returnCode:contextInfo:)
contextInfo:info];
}
- (void) reset {
@@ -56,5 +70,18 @@
[super dealloc];
}
#pragma mark -
#pragma mark Confirm Window
- (void) confirmResetSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
[[sheet window] orderOut:nil];
if (returnCode != NSAlertDefaultReturn) {
PBCommand *cmd = [(NSDictionary *)contextInfo objectForKey:kCommandKey];
[cmd invoke];
}
}
@end