From b0090ce0048534dc503f35af6c27aab712ed2a2d Mon Sep 17 00:00:00 2001 From: David Catmull Date: Mon, 9 May 2011 08:03:48 -0600 Subject: [PATCH 1/4] help text member --- PBGitSidebarController.m | 5 +++++ PBSourceViewItem.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index dad7de1b7..930a47c4a 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -342,6 +342,11 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCe [cell setImage:[item icon]]; } +- (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation +{ + return [item helpText]; +} + - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item { return ![item isGroupItem]; diff --git a/PBSourceViewItem.h b/PBSourceViewItem.h index 1547fd6c1..ec3bd4d5c 100644 --- a/PBSourceViewItem.h +++ b/PBSourceViewItem.h @@ -14,7 +14,7 @@ @interface PBSourceViewItem : NSObject { NSMutableArray *children; - NSString *title; + NSString *title, *helpText; PBGitRevSpecifier *revSpecifier; PBSourceViewItem *parent; @@ -43,6 +43,7 @@ - (PBGitRef *) ref; @property(retain) NSString *title; +@property(retain) NSString *helpText; @property(readonly) NSMutableArray *children; @property(assign) BOOL isGroupItem, isUncollapsible; @property(retain) PBGitRevSpecifier *revSpecifier; From 43e3d46b1376129ec6e517d39e136d4aa83fdf8b Mon Sep 17 00:00:00 2001 From: David Catmull Date: Sat, 14 May 2011 10:42:30 -0600 Subject: [PATCH 2/4] helpTextForRef --- PBGitRepository.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/PBGitRepository.m b/PBGitRepository.m index 41bc6f037..5dcb9dcfc 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -278,6 +278,32 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components [refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha]; } +// 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]) { + arguments = [NSArray arrayWithObjects:@"tag", @"-ln", name, nil]; + output = [self outputForArguments:arguments]; + if (![output hasPrefix:name]) + return nil; + return [[output substringFromIndex:[name length]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + } + return nil; +} + - (void) reloadRefs { _headRef = nil; From 1d24c1dff374c332bbc1a5e3112f7c057c4fd7a4 Mon Sep 17 00:00:00 2001 From: David Catmull Date: Sat, 14 May 2011 10:53:42 -0600 Subject: [PATCH 3/4] hook up helpText; works with tags --- PBGitRepository.m | 1 + PBGitRevSpecifier.h | 2 ++ PBGitRevSpecifier.m | 2 +- PBGitSidebarController.m | 2 +- PBSourceViewItem.h | 3 +-- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/PBGitRepository.m b/PBGitRepository.m index 5dcb9dcfc..2e1f9e662 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -326,6 +326,7 @@ - (void) reloadRefs PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]]; PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef]; + [revSpec setHelpText:[self helpTextForRef:newRef]]; [self addBranch:revSpec]; [self addRef:newRef fromParameters:components]; [oldBranches removeObject:revSpec]; diff --git a/PBGitRevSpecifier.h b/PBGitRevSpecifier.h index 32e96c491..735627420 100644 --- a/PBGitRevSpecifier.h +++ b/PBGitRevSpecifier.h @@ -11,6 +11,7 @@ @interface PBGitRevSpecifier : NSObject { NSString *description; + NSString *helpText; NSArray *parameters; NSURL *workingDirectory; BOOL isSimpleRef; @@ -36,6 +37,7 @@ + (PBGitRevSpecifier *)localBranchesRevSpec; @property(retain) NSString *description; +@property(retain) NSString *helpText; @property(readonly) NSArray *parameters; @property(retain) NSURL *workingDirectory; @property(readonly) BOOL isSimpleRef; diff --git a/PBGitRevSpecifier.m b/PBGitRevSpecifier.m index 1adc9ed8c..f4c5e3825 100644 --- a/PBGitRevSpecifier.m +++ b/PBGitRevSpecifier.m @@ -11,7 +11,7 @@ @implementation PBGitRevSpecifier -@synthesize parameters, description, workingDirectory; +@synthesize parameters, description, helpText, workingDirectory; @synthesize isSimpleRef; @synthesize behind,ahead; diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index 930a47c4a..c2d04f467 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -344,7 +344,7 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCe - (NSString *)outlineView:(NSOutlineView *)outlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation { - return [item helpText]; + return [[item revSpecifier] helpText]; } - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item diff --git a/PBSourceViewItem.h b/PBSourceViewItem.h index ec3bd4d5c..1547fd6c1 100644 --- a/PBSourceViewItem.h +++ b/PBSourceViewItem.h @@ -14,7 +14,7 @@ @interface PBSourceViewItem : NSObject { NSMutableArray *children; - NSString *title, *helpText; + NSString *title; PBGitRevSpecifier *revSpecifier; PBSourceViewItem *parent; @@ -43,7 +43,6 @@ - (PBGitRef *) ref; @property(retain) NSString *title; -@property(retain) NSString *helpText; @property(readonly) NSMutableArray *children; @property(assign) BOOL isGroupItem, isUncollapsible; @property(retain) PBGitRevSpecifier *revSpecifier; From 7806e649903bc68fe30edf53d183a3c41e439a47 Mon Sep 17 00:00:00 2001 From: David Catmull Date: Sat, 14 May 2011 23:16:57 -0600 Subject: [PATCH 4/4] 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 fe5369dd0..e8bf409ce 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 2e1f9e662..275bbf877 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -278,23 +278,32 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components [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 8f27532f2..bbae55703 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 0947cfd01..7bf1bcb9f 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 623c816a0..c6ff678f9 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 c2d04f467..276fa758c 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -344,7 +344,7 @@ - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(PBSourceViewCe - (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 @@ - (BOOL) outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:( 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 @@ - (void)populateList 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 1547fd6c1..1199802d1 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 8c810c0c2..530ece8b2 100644 --- a/PBSourceViewItem.m +++ b/PBSourceViewItem.m @@ -128,6 +128,11 @@ - (NSString *)title return [[revSpecifier description] lastPathComponent]; } +- (NSString *) helpText +{ + return [revSpecifier helpText]; +} + - (NSString *) stringValue { return self.title;