From 7806e649903bc68fe30edf53d183a3c41e439a47 Mon Sep 17 00:00:00 2001 From: David Catmull Date: Sat, 14 May 2011 23:16:57 -0600 Subject: [PATCH] help tags for remotes now work --- PBGitRepository.h | 1 + PBGitRepository.m | 31 ++++++++++++++++++++----------- PBGitSVRemoteItem.h | 2 ++ PBGitSVRemoteItem.m | 1 + PBGitSidebarController.h | 6 +++--- PBGitSidebarController.m | 15 ++++++++++++++- PBSourceViewItem.h | 1 + PBSourceViewItem.m | 5 +++++ 8 files changed, 47 insertions(+), 15 deletions(-) diff --git a/PBGitRepository.h b/PBGitRepository.h index fe5369d..e8bf409 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -127,6 +127,7 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) { - (BOOL) hasRemotes; - (PBGitRef *) remoteRefForBranch:(PBGitRef *)branch error:(NSError **)error; - (NSString *) infoForRemote:(NSString *)remoteName; +- (NSArray*) URLsForRemote:(NSString*)remoteName; - (void) readCurrentBranch; - (PBGitRevSpecifier*) addBranch: (PBGitRevSpecifier*) rev; diff --git a/PBGitRepository.m b/PBGitRepository.m index 2e1f9e6..275bbf8 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -278,23 +278,32 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; [refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha]; } -// Extracts the text that should be shown in a help tag +// Returns the remote's fetch and pull URLs as an array of two strings. +- (NSArray*) URLsForRemote:(NSString*)remoteName +{ + NSArray *arguments = [NSArray arrayWithObjects:@"remote", @"show", @"-n", remoteName, nil]; + NSString *output = [self outputForArguments:arguments]; + + NSArray *remoteLines = [output componentsSeparatedByString:@"\n"]; + NSString *fetchURL = [remoteLines objectAtIndex:1]; + NSString *pushURL = [remoteLines objectAtIndex:2]; + + if ([fetchURL hasPrefix:@" Fetch URL: "] && [pushURL hasPrefix:@" Push URL: "]) + return [NSArray arrayWithObjects: + [fetchURL substringFromIndex:13], + [pushURL substringFromIndex:13], + nil]; + return nil; +} + +// Extracts the text that should be shown in a help tag. - (NSString*) helpTextForRef:(PBGitRef*)ref { NSString *output = nil; NSString *name = [ref shortName]; NSArray *arguments = nil; - if ([ref isRemote]) { - arguments = [NSArray arrayWithObjects:@"remote", @"show", @"-n", name, nil]; - output = [self outputForArguments:arguments]; - - NSArray *remoteLines = [output componentsSeparatedByString:@"\n"]; - - // Second and third lines have Fetch and Push URLs - return [[remoteLines subarrayWithRange:NSMakeRange(1,1)] componentsJoinedByString:@"\n"]; - } - else if ([ref isTag]) { + if ([ref isTag]) { arguments = [NSArray arrayWithObjects:@"tag", @"-ln", name, nil]; output = [self outputForArguments:arguments]; if (![output hasPrefix:name]) diff --git a/PBGitSVRemoteItem.h b/PBGitSVRemoteItem.h index 8f27532..bbae557 100644 --- a/PBGitSVRemoteItem.h +++ b/PBGitSVRemoteItem.h @@ -12,9 +12,11 @@ @interface PBGitSVRemoteItem : PBSourceViewItem { BOOL alert; + NSString *helpText; } @property (assign) BOOL alert; +@property (retain) NSString *helpText; + (id)remoteItemWithTitle:(NSString *)title; diff --git a/PBGitSVRemoteItem.m b/PBGitSVRemoteItem.m index 0947cfd..7bf1bcb 100644 --- a/PBGitSVRemoteItem.m +++ b/PBGitSVRemoteItem.m @@ -13,6 +13,7 @@ @implementation PBGitSVRemoteItem @synthesize alert; +@synthesize helpText; + (id)remoteItemWithTitle:(NSString *)title { diff --git a/PBGitSidebarController.h b/PBGitSidebarController.h index 623c816..c6ff678 100644 --- a/PBGitSidebarController.h +++ b/PBGitSidebarController.h @@ -20,9 +20,9 @@ IBOutlet NSPopUpButton *actionButton; IBOutlet NSSegmentedControl *remoteControls; - IBOutlet NSButton* svnFetchButton; - IBOutlet NSButton* svnRebaseButton; - IBOutlet NSButton* svnDcommitButton; + IBOutlet NSButton* svnFetchButton; + IBOutlet NSButton* svnRebaseButton; + IBOutlet NSButton* svnDcommitButton; NSMutableArray *items; diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index c2d04f4..276fa75 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -344,7 +344,7 @@ static NSString * const kObservingContextSubmodules = @"submodulesChanged"; - (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation { - return [[item revSpecifier] helpText]; + return [item helpText]; } - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item @@ -365,6 +365,17 @@ static NSString * const kObservingContextSubmodules = @"submodulesChanged"; return ![item isUncollapsible]; } +- (NSString*) helpTextForRemoteURLs:(NSArray*)urls +{ + NSString *fetchURL = [urls objectAtIndex:0]; + NSString *pushURL = [urls objectAtIndex:1]; + + if ([fetchURL isEqual:pushURL]) + return fetchURL; + else // Down triangle for fetch, up triangle for push + return [NSString stringWithFormat:@"\u25bc %@\n\u25b2", fetchURL, pushURL]; +} + - (void)populateList { PBSourceViewItem *project = [PBSourceViewItem groupItemWithTitle:[repository projectName]]; @@ -384,6 +395,8 @@ static NSString * const kObservingContextSubmodules = @"submodulesChanged"; for (PBGitRevSpecifier *rev in repository.branches) [self addRevSpec:rev]; + for (PBGitSVRemoteItem *remote in remotes.children) + [remote setHelpText:[self helpTextForRemoteURLs:[[self repository] URLsForRemote:[remote title]]]]; [items addObject:project]; [items addObject:branches]; diff --git a/PBSourceViewItem.h b/PBSourceViewItem.h index 1547fd6..1199802 100644 --- a/PBSourceViewItem.h +++ b/PBSourceViewItem.h @@ -30,6 +30,7 @@ + (id)itemWithTitle:(NSString *)title; - (NSString *)badge; +- (NSString *)helpText; - (void)addChild:(PBSourceViewItem *)child; - (void)removeChild:(PBSourceViewItem *)child; diff --git a/PBSourceViewItem.m b/PBSourceViewItem.m index 8c810c0..530ece8 100644 --- a/PBSourceViewItem.m +++ b/PBSourceViewItem.m @@ -128,6 +128,11 @@ return [[revSpecifier description] lastPathComponent]; } +- (NSString *) helpText +{ + return [revSpecifier helpText]; +} + - (NSString *) stringValue { return self.title;