Skip to content

Commit b547c26

Browse files
committed
Merge pull request #177 from jspiro/master
improvements for stashes context menu
2 parents fd84719 + 054c76c commit b547c26

File tree

4 files changed

+113
-629
lines changed

4 files changed

+113
-629
lines changed

Commands/PBCommand.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@
1414
PBGitRepository *repository;
1515
NSString *displayName;
1616
NSMutableArray *parameters;
17+
BOOL confirmAction;
1718
BOOL canBeFired;
1819
}
1920

2021
@property BOOL canBeFired;
22+
@property (readonly) BOOL confirmAction;
2123
@property (readonly) PBGitRepository *repository;
2224
@property (strong) NSString *commandTitle;
2325
@property (strong) NSString *commandDescription;
2426
@property (readonly) NSString *displayName;
2527

2628
- (id) initWithDisplayName:(NSString *) aDisplayName parameters:(NSArray *) params repository:(PBGitRepository *) repo;
29+
- (id) initWithDisplayName:(NSString *) aDisplayName parameters:(NSArray *) params repository:(PBGitRepository *) repo confirmAction:(BOOL) confirm;
2730
- (void) invoke;
2831
- (NSArray *) allParameters;
2932
- (void) appendParameters:(NSArray *) params;

Commands/PBCommand.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ @implementation PBCommand
1515
@synthesize commandTitle;
1616
@synthesize repository;
1717
@synthesize canBeFired;
18+
@synthesize confirmAction;
1819

1920
- (id) initWithDisplayName:(NSString *) aDisplayName parameters:(NSArray *) params {
2021
return [self initWithDisplayName:aDisplayName parameters:params repository:nil];
2122
}
2223

2324
- (id) initWithDisplayName:(NSString *) aDisplayName parameters:(NSArray *) params repository:(PBGitRepository *) repo {
25+
return [self initWithDisplayName:aDisplayName parameters:params repository:repo confirmAction:FALSE];
26+
}
27+
28+
- (id) initWithDisplayName:(NSString *) aDisplayName parameters:(NSArray *) params repository:(PBGitRepository *) repo confirmAction:(BOOL) confirm {
2429
self = [super init];
2530
if (self != nil) {
2631
displayName = aDisplayName;
2732
parameters = [[NSMutableArray alloc] initWithArray:params];
2833
commandTitle = @"";
2934
commandDescription = @"";
3035
repository = repo;
36+
confirmAction = confirm;
3137
canBeFired = YES;
3238
}
3339
return self;
@@ -42,7 +48,20 @@ - (void) appendParameters:(NSArray *) params {
4248
}
4349

4450
- (void) invoke {
45-
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:[self allParameters] title:self.commandTitle description:self.commandDescription inRepository:self.repository];
51+
int alertRet = NSAlertDefaultReturn;
52+
53+
if (self.confirmAction) {
54+
alertRet = [[NSAlert alertWithMessageText:self.commandTitle
55+
defaultButton:nil
56+
alternateButton:@"Cancel"
57+
otherButton:nil
58+
informativeTextWithFormat:[NSString stringWithFormat:@"Are you sure you wish to perform this action?\n\n%@?",self.commandDescription]]
59+
runModal];
60+
}
61+
62+
if (alertRet == NSAlertDefaultReturn) {
63+
[PBRemoteProgressSheet beginRemoteProgressSheetForArguments:[self allParameters] title:self.commandTitle description:self.commandDescription inRepository:self.repository];
64+
}
4665
}
4766

4867
@end

Commands/PBStashCommandFactory.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ + (NSArray *) commandsForStash:(PBGitStash *) stash repository:(PBGitRepository
6262
NSMutableArray *commands = [[NSMutableArray alloc] init];
6363

6464
NSArray *args = [NSArray arrayWithObjects:@"stash", @"apply", [stash name], nil];
65-
PBCommand *command = [[PBCommand alloc] initWithDisplayName:@"Apply" parameters:args repository:repository];
65+
PBCommand *command = [[PBCommand alloc] initWithDisplayName:@"Apply" parameters:args repository:repository confirmAction:TRUE];
6666
command.commandTitle = command.displayName;
6767
command.commandDescription = [NSString stringWithFormat:@"Applying stash: '%@'", stash];
6868
[commands addObject:command];
6969

7070
args = [NSArray arrayWithObjects:@"stash", @"pop", [stash name], nil];
71-
command = [[PBCommand alloc] initWithDisplayName:@"Pop" parameters:args repository:repository];
71+
command = [[PBCommand alloc] initWithDisplayName:@"Pop" parameters:args repository:repository confirmAction:TRUE];
7272
command.commandTitle = command.displayName;
7373
command.commandDescription = [NSString stringWithFormat:@"Poping stash: '%@'", stash];
7474
[commands addObject:command];
7575

7676
args = [NSArray arrayWithObjects:@"stash", @"drop", [stash name], nil];
77-
command = [[PBCommand alloc] initWithDisplayName:@"Drop" parameters:args repository:repository];
77+
command = [[PBCommand alloc] initWithDisplayName:@"Drop" parameters:args repository:repository confirmAction:TRUE];
7878
command.commandTitle = command.displayName;
7979
command.commandDescription = [NSString stringWithFormat:@"Dropping stash: '%@'", stash];
8080
[commands addObject:command];

0 commit comments

Comments
 (0)