From 27e490c405710ddac30f51cab7e1098d2bfe34df Mon Sep 17 00:00:00 2001 From: Tomasz Krasnyk Date: Sun, 28 Nov 2010 22:51:47 +0100 Subject: [PATCH] Reset now asks user for confirmation --- Controller/PBGitResetController.m | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Controller/PBGitResetController.m b/Controller/PBGitResetController.m index f0d199a..773a74d 100644 --- a/Controller/PBGitResetController.m +++ b/Controller/PBGitResetController.m @@ -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