10
10
#import " PBGitRepository.h"
11
11
#import " PBCommand.h"
12
12
13
+ static NSString * const kCommandKey = @" command" ;
14
+
13
15
@implementation PBGitResetController
14
16
15
17
- (id ) initWithRepository : (PBGitRepository *) repo {
@@ -20,11 +22,23 @@ - (id) initWithRepository:(PBGitRepository *) repo {
20
22
}
21
23
22
24
- (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
+
23
31
NSArray *arguments = [NSArray arrayWithObjects: @" reset" , @" --hard" , @" HEAD" , nil ];
24
32
PBCommand *cmd = [[PBCommand alloc ] initWithDisplayName: @" Reset hard to HEAD" parameters: arguments repository: repository];
25
33
cmd.commandTitle = cmd.displayName ;
26
34
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];
28
42
}
29
43
30
44
- (void ) reset {
@@ -56,5 +70,18 @@ - (void) dealloc {
56
70
[super dealloc ];
57
71
}
58
72
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
+
59
86
60
87
@end
0 commit comments