Skip to content

Commit

Permalink
Merge pull request brotherbard#61 from Uncommon/helptags
Browse files Browse the repository at this point in the history
Help tags for remotes and tags
  • Loading branch information
laullon committed May 19, 2011
2 parents 96a8794 + 7806e64 commit e00f734
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions PBGitRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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;
Expand Down
36 changes: 36 additions & 0 deletions PBGitRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,41 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
[refs setObject:[NSMutableArray arrayWithObject:ref] forKey:sha];
}

// 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 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;
Expand Down Expand Up @@ -321,6 +356,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];
Expand Down
2 changes: 2 additions & 0 deletions PBGitRevSpecifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@interface PBGitRevSpecifier : NSObject <NSCopying> {
NSString *description;
NSString *helpText;
NSArray *parameters;
NSURL *workingDirectory;
BOOL isSimpleRef;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion PBGitRevSpecifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@implementation PBGitRevSpecifier

@synthesize parameters, description, workingDirectory;
@synthesize parameters, description, helpText, workingDirectory;
@synthesize isSimpleRef;
@synthesize behind,ahead;

Expand Down
2 changes: 2 additions & 0 deletions PBGitSVRemoteItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

@interface PBGitSVRemoteItem : PBSourceViewItem {
BOOL alert;
NSString *helpText;
}

@property (assign) BOOL alert;
@property (retain) NSString *helpText;

+ (id)remoteItemWithTitle:(NSString *)title;

Expand Down
1 change: 1 addition & 0 deletions PBGitSVRemoteItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@implementation PBGitSVRemoteItem

@synthesize alert;
@synthesize helpText;

+ (id)remoteItemWithTitle:(NSString *)title
{
Expand Down
6 changes: 3 additions & 3 deletions PBGitSidebarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 18 additions & 0 deletions PBGitSidebarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -360,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]];
Expand All @@ -379,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];
Expand Down
1 change: 1 addition & 0 deletions PBSourceViewItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
+ (id)itemWithTitle:(NSString *)title;

- (NSString *)badge;
- (NSString *)helpText;

- (void)addChild:(PBSourceViewItem *)child;
- (void)removeChild:(PBSourceViewItem *)child;
Expand Down
5 changes: 5 additions & 0 deletions PBSourceViewItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ - (NSString *)title
return [[revSpecifier description] lastPathComponent];
}

- (NSString *) helpText
{
return [revSpecifier helpText];
}

- (NSString *) stringValue
{
return self.title;
Expand Down

0 comments on commit e00f734

Please sign in to comment.