Skip to content

Commit 27e490c

Browse files
Reset now asks user for confirmation
1 parent 71e9e2c commit 27e490c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

Controller/PBGitResetController.m

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#import "PBGitRepository.h"
1111
#import "PBCommand.h"
1212

13+
static NSString * const kCommandKey = @"command";
14+
1315
@implementation PBGitResetController
1416

1517
- (id) initWithRepository:(PBGitRepository *) repo {
@@ -20,11 +22,23 @@ - (id) initWithRepository:(PBGitRepository *) repo {
2022
}
2123

2224
- (void) resetHardToHead {
25+
NSAlert *alert = [NSAlert alertWithMessageText:@"Reseting working copy and index"
26+
defaultButton:@"Cancel"
27+
alternateButton:nil
28+
otherButton:@"Reset"
29+
informativeTextWithFormat:@"Are you sure you want to reset your working copy and index? All changes to them will be gone!"];
30+
2331
NSArray *arguments = [NSArray arrayWithObjects:@"reset", @"--hard", @"HEAD", nil];
2432
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset hard to HEAD" parameters:arguments repository:repository];
2533
cmd.commandTitle = cmd.displayName;
2634
cmd.commandDescription = @"Reseting head";
27-
[cmd invoke];
35+
36+
NSMutableDictionary *info = [NSMutableDictionary dictionaryWithObject:cmd forKey:kCommandKey];
37+
38+
[alert beginSheetModalForWindow:[repository.windowController window]
39+
modalDelegate:self
40+
didEndSelector:@selector(confirmResetSheetDidEnd:returnCode:contextInfo:)
41+
contextInfo:info];
2842
}
2943

3044
- (void) reset {
@@ -56,5 +70,18 @@ - (void) dealloc {
5670
[super dealloc];
5771
}
5872

73+
#pragma mark -
74+
#pragma mark Confirm Window
75+
76+
- (void) confirmResetSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
77+
{
78+
[[sheet window] orderOut:nil];
79+
80+
if (returnCode != NSAlertDefaultReturn) {
81+
PBCommand *cmd = [(NSDictionary *)contextInfo objectForKey:kCommandKey];
82+
[cmd invoke];
83+
}
84+
}
85+
5986

6087
@end

0 commit comments

Comments
 (0)