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
This commit is contained in:
Nathan Kinsinger
2010-02-04 19:25:17 -07:00
parent dceabb6702
commit 8359883c92
4 changed files with 51 additions and 18 deletions
+1
View File
@@ -33,6 +33,7 @@ extern NSString* PBGitRepositoryErrorDomain;
- (BOOL) checkoutFiles:(NSArray *)files fromRefish:(id <PBGitRefish>)ref;
- (BOOL) createBranch:(NSString *)branchName atRefish:(id <PBGitRefish>)ref;
- (BOOL) createTag:(NSString *)tagName message:(NSString *)message atRefish:(id <PBGitRefish>)commitSHA;
- (BOOL) deleteRef:(PBGitRef *)ref;
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
- (NSFileHandle*) handleForArguments:(NSArray*) args;
+22
View File
@@ -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
+27 -17
View File
@@ -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
+1 -1
View File
@@ -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];