From 8359883c92f0e6e95cf59b6cf2bc749658012600 Mon Sep 17 00:00:00 2001 From: Nathan Kinsinger Date: Thu, 4 Feb 2010 19:25:17 -0700 Subject: [PATCH] Rename removeRef: to showDeleteRefSheet: - move the core of the delete implementation to the repository as deleteRef: - move it to it's own pragma mark section --- PBGitRepository.h | 1 + PBGitRepository.m | 22 ++++++++++++++++++++++ PBRefController.m | 44 +++++++++++++++++++++++++++----------------- PBRefMenuItem.m | 2 +- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/PBGitRepository.h b/PBGitRepository.h index 18294d5..ac57508 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -33,6 +33,7 @@ extern NSString* PBGitRepositoryErrorDomain; - (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id )ref; - (BOOL) createBranch:(NSString *)branchName atRefish:(id )ref; - (BOOL) createTag:(NSString *)tagName message:(NSString *)message atRefish:(id )commitSHA; +- (BOOL) deleteRef:(PBGitRef *)ref; - (NSFileHandle*) handleForCommand:(NSString*) cmd; - (NSFileHandle*) handleForArguments:(NSArray*) args; diff --git a/PBGitRepository.m b/PBGitRepository.m index 4d5413a..87935d9 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -526,6 +526,28 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; return YES; } +- (BOOL) deleteRef:(PBGitRef *)ref +{ + if (!ref) + return NO; + + int retValue = 1; + NSArray *arguments = [NSArray arrayWithObjects:@"update-ref", @"-d", [ref ref], nil]; + NSString * output = [self outputForArguments:arguments retValue:&retValue]; + if (retValue) { + NSString *message = [NSString stringWithFormat:@"There was an error deleting the ref: %@\n\n", [ref shortName]]; + [self.windowController showErrorSheetTitle:@"Delete ref failed!" message:message arguments:arguments output:output]; + return NO; + } + + [self removeBranch:[[PBGitRevSpecifier alloc] initWithRef:ref]]; + PBGitCommit *commit = [self commitForRef:ref]; + [commit removeRef:ref]; + + [self reloadRefs]; + return YES; +} + #pragma mark low level diff --git a/PBRefController.m b/PBRefController.m index 34caaa6..6b25b39 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -111,29 +111,39 @@ } -- (void) removeRefSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo +#pragma mark Remove a branch, remote or tag + +- (void) showDeleteRefSheet:(PBRefMenuItem *)sender { + if ([[sender refish] refishType] == kGitXCommitType) + return; + + PBGitRef *ref = (PBGitRef *)[sender refish]; + NSString *ref_desc = [NSString stringWithFormat:@"%@ '%@'", [ref refishType], [ref shortName]]; + + NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete %@?", ref_desc] + defaultButton:@"Delete" + alternateButton:@"Cancel" + otherButton:nil + informativeTextWithFormat:@"Are you sure you want to remove the %@?", ref_desc]; + + [alert beginSheetModalForWindow:[historyController.repository.windowController window] + modalDelegate:self + didEndSelector:@selector(deleteRefSheetDidEnd:returnCode:contextInfo:) + contextInfo:ref]; +} + +- (void) deleteRefSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo +{ + [[sheet window] orderOut:nil]; + if (returnCode == NSAlertDefaultReturn) { - int ret = 1; - PBRefMenuItem *refMenuItem = contextInfo; - [historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-d", [[refMenuItem refish] refishName], nil] retValue: &ret]; - if (ret) { - NSLog(@"Removing ref failed!"); - return; - } - [historyController.repository removeBranch:[[PBGitRevSpecifier alloc] initWithRef:[refMenuItem refish]]]; - PBGitCommit *commitForRef = [historyController.repository commitForRef:[refMenuItem refish]]; - [commitForRef removeRef:[refMenuItem refish]]; + PBGitRef *ref = (PBGitRef *)contextInfo; + [historyController.repository deleteRef:ref]; [commitController rearrangeObjects]; } } -- (void) removeRef:(PBRefMenuItem *)sender -{ - NSString *ref_desc = [NSString stringWithFormat:@"%@ %@", [(PBGitRef *)[sender refish] type], [[sender refish] shortName]]; - NSString *question = [NSString stringWithFormat:@"Are you sure you want to remove the %@?", ref_desc]; - NSBeginAlertSheet([NSString stringWithFormat:@"Delete %@?", ref_desc], @"Delete", @"Cancel", nil, [[historyController view] window], self, @selector(removeRefSheetDidEnd:returnCode:contextInfo:), NULL, sender, question); -} #pragma mark Contextual menus diff --git a/PBRefMenuItem.m b/PBRefMenuItem.m index 82051b1..dc9e29a 100644 --- a/PBRefMenuItem.m +++ b/PBRefMenuItem.m @@ -61,7 +61,7 @@ // delete ref [items addObject:[PBRefMenuItem separatorItem]]; NSString *deleteTitle = [NSString stringWithFormat:@"Delete %@…", targetRefName]; - [items addObject:[PBRefMenuItem itemWithTitle:deleteTitle action:@selector(removeRef:) enabled:YES]]; + [items addObject:[PBRefMenuItem itemWithTitle:deleteTitle action:@selector(showDeleteRefSheet:) enabled:YES]]; for (PBRefMenuItem *item in items) { [item setTarget:target];