mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
10daa222b5
Since we now have that gorgeous sidebar and commit list with branch filters, command line arguments to gitx should utilize these to greater effect. For example, if I pass: "--local" >> read current branch and set the branch filter to "Local" "--all" >> same as above but set "All" branch filter - partial or full SHA-1 >> should get the branch most likely associated with that SHA, select it in the sidebar and scroll the commit list to the commit with the passed SHA. - partial ref like "xyz/master" >> select the master branch of the "xyz" folder in the sidebar and scroll the commit list to its most recent commit. "--subject=Test" >> filter commit list using a predicate on the commit list's array controller (basically populating the search field programmatically). For other "--..." CLI switches it's the same, just the filter predicate is a bit different each time. You get the idea. To accomplish this we make the following changes: - gitx sets two environment variables via setenv(), one for a concatenated version of the CLI args, and one for the indicator that we launched from gitx. Using setenv() is unfortunate but I couldn't find a way to do it through DO and PBCLIProxy since that proxy will do it's processing far too late into the app's event cycle. - the now shared application controller stores the two env vars in a BOOL 'launchedFromGitx' and an NSString 'cliArgs'. - Because GitX makes heavy use of KVO and context switching during the app launch we introduce the notion of a deferred selection so that we can worry about selecting the branch and commit the user has passed to gitx in some form or another, when the app has finished launching completely and all KVO notifications up to this point have been handled. - ApplicationController does the bulk work. It stores most state changes, handles most command line switches (except for a few still in gitx.m), deals with the deferredSelectObject. - PBGitSidebarController populateList includes logic for fixing up a ref or a partial SHA when appController.launchedFromGitx is true. If it can be resolved we set this as the deferred select object so it can be selected later on. I'll leave the excess NSLogs in there for this commit so another can see what went into this before.
153 lines
3.5 KiB
Objective-C
153 lines
3.5 KiB
Objective-C
//
|
|
// PBSourceViewItem.m
|
|
// GitX
|
|
//
|
|
// Created by Pieter de Bie on 9/8/09.
|
|
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
|
//
|
|
|
|
#import "PBSourceViewItem.h"
|
|
#import "PBSourceViewItems.h"
|
|
#import "PBGitRef.h"
|
|
#import "BMScript.h"
|
|
|
|
@implementation PBSourceViewItem
|
|
@synthesize parent, title, isGroupItem, children, revSpecifier, isUncollapsible;
|
|
@dynamic icon;
|
|
|
|
- (id)init
|
|
{
|
|
if (!(self = [super init]))
|
|
return nil;
|
|
|
|
children = [NSMutableArray array];
|
|
return self;
|
|
}
|
|
|
|
- (NSString *) description {
|
|
return [NSString stringWithFormat:@"<%@ %p> title = %@, rev = %@, children = %@",
|
|
NSStringFromClass([self class]), self, title, revSpecifier, children];
|
|
}
|
|
|
|
- (NSString *) debugDescription {
|
|
return [NSString stringWithFormat:@"%@, p = %@, ch = %@, grp? %@, unc? %@",
|
|
[self description], parent, children, BMStringFromBOOL(isGroupItem), BMStringFromBOOL(isUncollapsible)];
|
|
}
|
|
|
|
|
|
|
|
+ (id)itemWithTitle:(NSString *)title
|
|
{
|
|
PBSourceViewItem *item = [[[self class] alloc] init];
|
|
item.title = title;
|
|
return item;
|
|
}
|
|
|
|
+ (id)groupItemWithTitle:(NSString *)title
|
|
{
|
|
PBSourceViewItem *item = [self itemWithTitle:[title uppercaseString]];
|
|
item.isGroupItem = YES;
|
|
return item;
|
|
}
|
|
|
|
+ (id)itemWithRevSpec:(PBGitRevSpecifier *)revSpecifier
|
|
{
|
|
PBGitRef *ref = [revSpecifier ref];
|
|
|
|
if ([ref isTag])
|
|
return [PBGitSVTagItem tagItemWithRevSpec:revSpecifier];
|
|
else if ([ref isBranch])
|
|
return [PBGitSVBranchItem branchItemWithRevSpec:revSpecifier];
|
|
else if ([ref isRemoteBranch])
|
|
return [PBGitSVRemoteBranchItem remoteBranchItemWithRevSpec:revSpecifier];
|
|
|
|
return [PBGitSVOtherRevItem otherItemWithRevSpec:revSpecifier];
|
|
}
|
|
|
|
- (void)addChild:(PBSourceViewItem *)child
|
|
{
|
|
if (!child)
|
|
return;
|
|
|
|
[self.children addObject:child];
|
|
child.parent = self;
|
|
[self.children sortUsingDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]]];
|
|
}
|
|
|
|
- (void)removeChild:(PBSourceViewItem *)child
|
|
{
|
|
if (!child)
|
|
return;
|
|
|
|
[self.children removeObject:child];
|
|
if (!self.isGroupItem && ([self.children count] == 0))
|
|
[self.parent removeChild:self];
|
|
}
|
|
|
|
- (void)addRev:(PBGitRevSpecifier *)theRevSpecifier toPath:(NSArray *)path
|
|
{
|
|
if ([path count] == 1) {
|
|
PBSourceViewItem *item = [PBSourceViewItem itemWithRevSpec:theRevSpecifier];
|
|
[self addChild:item];
|
|
return;
|
|
}
|
|
|
|
NSString *firstTitle = [path objectAtIndex:0];
|
|
PBSourceViewItem *node = nil;
|
|
for (PBSourceViewItem *child in [self children])
|
|
if ([child.title isEqualToString:firstTitle])
|
|
node = child;
|
|
|
|
if (!node) {
|
|
if ([firstTitle isEqualToString:[[theRevSpecifier ref] remoteName]])
|
|
node = [PBGitSVRemoteItem remoteItemWithTitle:firstTitle];
|
|
else
|
|
node = [PBGitSVFolderItem folderItemWithTitle:firstTitle];
|
|
[self addChild:node];
|
|
}
|
|
|
|
[node addRev:theRevSpecifier toPath:[path subarrayWithRange:NSMakeRange(1, [path count] - 1)]];
|
|
}
|
|
|
|
- (PBSourceViewItem *) findRev:(PBGitRevSpecifier *)rev
|
|
{
|
|
NSLog(@"[%@ %s] rev = %@, revSpecifier = %@", [self class], _cmd, rev, revSpecifier);
|
|
if (rev == revSpecifier || [rev isEqual:revSpecifier])
|
|
return self;
|
|
|
|
PBSourceViewItem *item = nil;
|
|
for (PBSourceViewItem *child in children)
|
|
if (item = [child findRev:rev])
|
|
return item;
|
|
|
|
return nil;
|
|
}
|
|
|
|
- (NSImage *) icon
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
- (NSString *)title
|
|
{
|
|
if (title)
|
|
return title;
|
|
|
|
return [[revSpecifier description] lastPathComponent];
|
|
}
|
|
|
|
- (NSString *) stringValue
|
|
{
|
|
return self.title;
|
|
}
|
|
|
|
- (PBGitRef *) ref
|
|
{
|
|
if (self.revSpecifier)
|
|
return [self.revSpecifier ref];
|
|
|
|
return nil;
|
|
}
|
|
|
|
@end
|