mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
WIP: Use a nicer branches menu
This commit is contained in:
+15
-38
@@ -8,8 +8,8 @@
|
||||
<string key="IBDocument.HIToolboxVersion">352.00</string>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="236"/>
|
||||
<integer value="11"/>
|
||||
<integer value="236"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
@@ -1847,39 +1847,6 @@
|
||||
</object>
|
||||
<int key="connectionID">198</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">contentValues: arrangedObjects.description</string>
|
||||
<reference key="source" ref="630469851"/>
|
||||
<reference key="destination" ref="886549521"/>
|
||||
<object class="NSNibBindingConnector" key="connector" id="68454909">
|
||||
<reference key="NSSource" ref="630469851"/>
|
||||
<reference key="NSDestination" ref="886549521"/>
|
||||
<string key="NSLabel">contentValues: arrangedObjects.description</string>
|
||||
<string key="NSBinding">contentValues</string>
|
||||
<string key="NSKeyPath">arrangedObjects.description</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">199</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">selectedIndex: selectionIndex</string>
|
||||
<reference key="source" ref="630469851"/>
|
||||
<reference key="destination" ref="886549521"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="630469851"/>
|
||||
<reference key="NSDestination" ref="886549521"/>
|
||||
<string key="NSLabel">selectedIndex: selectionIndex</string>
|
||||
<string key="NSBinding">selectedIndex</string>
|
||||
<string key="NSKeyPath">selectionIndex</string>
|
||||
<reference key="NSPreviousConnector" ref="68454909"/>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">203</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">predicate: filterPredicate</string>
|
||||
@@ -2109,8 +2076,8 @@
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="0" id="6"/>
|
||||
<reference ref="6"/>
|
||||
<integer value="0" id="8"/>
|
||||
<reference ref="8"/>
|
||||
</object>
|
||||
</object>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
@@ -2118,6 +2085,14 @@
|
||||
</object>
|
||||
<int key="connectionID">266</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">branchPopUp</string>
|
||||
<reference key="source" ref="892732705"/>
|
||||
<reference key="destination" ref="630469851"/>
|
||||
</object>
|
||||
<int key="connectionID">268</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
@@ -2895,7 +2870,7 @@
|
||||
<string>{{521, 707}, {346, 133}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>{{521, 707}, {346, 133}}</string>
|
||||
<integer value="0" id="8"/>
|
||||
<reference ref="8"/>
|
||||
<string>{3.40282e+38, 3.40282e+38}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
@@ -2978,7 +2953,7 @@
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">266</int>
|
||||
<int key="maxID">268</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
@@ -3131,6 +3106,7 @@
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSMutableArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>branchPopUp</string>
|
||||
<string>commitController</string>
|
||||
<string>commitList</string>
|
||||
<string>historyController</string>
|
||||
@@ -3139,6 +3115,7 @@
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>NSPopUpButton</string>
|
||||
<string>NSArrayController</string>
|
||||
<string>PBCommitList</string>
|
||||
<string>PBGitHistoryController</string>
|
||||
|
||||
+2
-3
@@ -210,9 +210,8 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
|
||||
// First do the ref matching. If this ref is new, add it to our ref list
|
||||
PBGitRef *newRef = [PBGitRef refFromString:[components objectAtIndex:0]];
|
||||
PBGitRevSpecifier* revSpec = [[PBGitRevSpecifier alloc] initWithRef:newRef];
|
||||
if ([[newRef type] isEqualToString:@"head"] || [[newRef type] isEqualToString:@"remote"])
|
||||
if ([self addBranch:revSpec] != revSpec)
|
||||
ret = YES;
|
||||
if ([self addBranch:revSpec] != revSpec)
|
||||
ret = YES;
|
||||
|
||||
// Also add this ref to the refs list
|
||||
[self addRef:newRef fromParameters:components];
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
IBOutlet NSWindow *newBranchSheet;
|
||||
IBOutlet NSTextField *newBranchName;
|
||||
|
||||
IBOutlet NSPopUpButton *branchPopUp;
|
||||
}
|
||||
|
||||
- (IBAction)addRef:(id)sender;
|
||||
|
||||
@@ -15,8 +15,20 @@
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]];
|
||||
[self observeValueForKeyPath:@"repository.branches" ofObject:historyController change:NULL context:@"branchChange"];
|
||||
}
|
||||
|
||||
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(id)context
|
||||
{
|
||||
if ([context isEqualToString: @"branchChange"]) {
|
||||
[self updateBranchMenu];
|
||||
}
|
||||
else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) removeRef:(PBRefMenuItem *) sender
|
||||
{
|
||||
int ret = 1;
|
||||
@@ -170,4 +182,110 @@
|
||||
[newBranchSheet orderOut:self];
|
||||
}
|
||||
|
||||
# pragma mark Branches menu
|
||||
|
||||
- (void) updateBranchMenu
|
||||
{
|
||||
NSLog(@"Updating branch");
|
||||
if (!branchPopUp)
|
||||
return;
|
||||
|
||||
NSMutableArray *localBranches = [NSMutableArray array];
|
||||
NSMutableArray *remoteBranches = [NSMutableArray array];
|
||||
NSMutableArray *tags = [NSMutableArray array];
|
||||
NSMutableArray *other = [NSMutableArray array];
|
||||
|
||||
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Branch menu"];
|
||||
for (PBGitRevSpecifier *rev in historyController.repository.branches)
|
||||
{
|
||||
if (![rev isSimpleRef])
|
||||
{
|
||||
[other addObject:rev];
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *ref = [rev simpleRef];
|
||||
|
||||
if ([ref hasPrefix:@"refs/heads"])
|
||||
[localBranches addObject:rev];
|
||||
else if ([ref hasPrefix:@"refs/tags"])
|
||||
[tags addObject:rev];
|
||||
else if ([ref hasPrefix:@"refs/remote"])
|
||||
[remoteBranches addObject:rev];
|
||||
}
|
||||
|
||||
for (PBGitRevSpecifier *rev in localBranches)
|
||||
{
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[rev description] action:@selector(changeBranch:) keyEquivalent:@""];
|
||||
[item setRepresentedObject:rev];
|
||||
[item setTarget:self];
|
||||
[menu addItem:item];
|
||||
}
|
||||
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// Remotes
|
||||
NSMenu *remoteMenu = [[NSMenu alloc] initWithTitle:@"Remotes"];
|
||||
NSMenu *currentMenu = NULL;
|
||||
for (PBGitRevSpecifier *rev in remoteBranches)
|
||||
{
|
||||
NSString *ref = [rev simpleRef];
|
||||
NSArray *components = [ref componentsSeparatedByString:@"/"];
|
||||
|
||||
NSString *remoteName = [components objectAtIndex:2];
|
||||
NSString *branchName = [[components subarrayWithRange:NSMakeRange(3, [components count] - 3)] componentsJoinedByString:@"/"];
|
||||
|
||||
if (![[currentMenu title] isEqualToString:remoteName])
|
||||
{
|
||||
currentMenu = [[NSMenu alloc] initWithTitle:remoteName];
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:remoteName action:NULL keyEquivalent:@""];
|
||||
[item setSubmenu:currentMenu];
|
||||
[remoteMenu addItem:item];
|
||||
}
|
||||
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:branchName action:@selector(changeBranch:) keyEquivalent:@""];
|
||||
[item setTarget:self];
|
||||
[item setRepresentedObject:rev];
|
||||
[currentMenu addItem:item];
|
||||
}
|
||||
|
||||
NSMenuItem *remoteItem = [[NSMenuItem alloc] initWithTitle:@"Remotes" action:NULL keyEquivalent:@""];
|
||||
[remoteItem setSubmenu:remoteMenu];
|
||||
[menu addItem:remoteItem];
|
||||
|
||||
// Tags
|
||||
NSMenu *tagMenu = [[NSMenu alloc] initWithTitle:@"Tags"];
|
||||
for (PBGitRevSpecifier *rev in tags)
|
||||
{
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[rev description] action:@selector(changeBranch:) keyEquivalent:@""];
|
||||
[item setTarget:self];
|
||||
[item setRepresentedObject:rev];
|
||||
[tagMenu addItem:item];
|
||||
}
|
||||
|
||||
NSMenuItem *tagItem = [[NSMenuItem alloc] initWithTitle:@"Tags" action:NULL keyEquivalent:@""];
|
||||
[tagItem setSubmenu:tagMenu];
|
||||
[menu addItem:tagItem];
|
||||
|
||||
|
||||
// Others
|
||||
[menu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
for (PBGitRevSpecifier *rev in other)
|
||||
{
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[rev description] action:@selector(changeBranch:) keyEquivalent:@""];
|
||||
[item setRepresentedObject:rev];
|
||||
[item setTarget:self];
|
||||
[menu addItem:item];
|
||||
}
|
||||
|
||||
[[branchPopUp cell] setMenu: menu];
|
||||
}
|
||||
|
||||
- (void) changeBranch:(NSMenuItem *)sender
|
||||
{
|
||||
PBGitRevSpecifier *rev = [sender representedObject];
|
||||
[historyController.repository selectBranch:rev];
|
||||
[branchPopUp selectItem:nil];
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user