Permalink
Browse files

Sidebar: hook up branch switching

This is far from perfect, but at least you can
use it to navigate the stuff a bit now :)
  • Loading branch information...
pieter committed Sep 9, 2009
1 parent ca479c7 commit 23d5c01a3da9d63919a84f32ebf59fb2002823c6
Showing with 96 additions and 0 deletions.
  1. +6 −0 GitX.xcodeproj/project.pbxproj
  2. +15 −0 NSOutlineViewExt.h
  3. +25 −0 NSOutlineViewExt.m
  4. +36 −0 PBGitSidebarController.m
  5. +1 −0 PBSourceViewItem.h
  6. +13 −0 PBSourceViewItem.m
@@ -65,6 +65,7 @@
F56524F00E02D45200F03B52 /* PBGitCommit.m in Sources */ = {isa = PBXBuildFile; fileRef = F56524EF0E02D45200F03B52 /* PBGitCommit.m */; };
F56526240E03D85900F03B52 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F56526230E03D85900F03B52 /* WebKit.framework */; };
F565262B0E03D89B00F03B52 /* PBWebHistoryController.m in Sources */ = {isa = PBXBuildFile; fileRef = F565262A0E03D89B00F03B52 /* PBWebHistoryController.m */; };
+ F567B88D1057FA9F000DB976 /* NSOutlineViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F567B88C1057FA9F000DB976 /* NSOutlineViewExt.m */; };
F569AE930F2CBD7C00C2FFA7 /* Credits.html in Resources */ = {isa = PBXBuildFile; fileRef = F569AE920F2CBD7C00C2FFA7 /* Credits.html */; };
F56ADDD90ED19F9E002AC78F /* AddBranchTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = F56ADDD70ED19F9E002AC78F /* AddBranchTemplate.png */; };
F56ADDDA0ED19F9E002AC78F /* AddLabelTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = F56ADDD80ED19F9E002AC78F /* AddLabelTemplate.png */; };
@@ -233,6 +234,8 @@
F56526230E03D85900F03B52 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; };
F56526290E03D89B00F03B52 /* PBWebHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBWebHistoryController.h; sourceTree = "<group>"; };
F565262A0E03D89B00F03B52 /* PBWebHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebHistoryController.m; sourceTree = "<group>"; };
+ F567B88B1057FA9F000DB976 /* NSOutlineViewExt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSOutlineViewExt.h; sourceTree = "<group>"; };
+ F567B88C1057FA9F000DB976 /* NSOutlineViewExt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSOutlineViewExt.m; sourceTree = "<group>"; };
F569AE920F2CBD7C00C2FFA7 /* Credits.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = Credits.html; sourceTree = "<group>"; };
F56ADDD70ED19F9E002AC78F /* AddBranchTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = AddBranchTemplate.png; path = Images/AddBranchTemplate.png; sourceTree = "<group>"; };
F56ADDD80ED19F9E002AC78F /* AddLabelTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = AddLabelTemplate.png; path = Images/AddLabelTemplate.png; sourceTree = "<group>"; };
@@ -559,6 +562,8 @@
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */,
F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */,
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */,
+ F567B88B1057FA9F000DB976 /* NSOutlineViewExt.h */,
+ F567B88C1057FA9F000DB976 /* NSOutlineViewExt.m */,
);
name = Aux;
sourceTree = "<group>";
@@ -894,6 +899,7 @@
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */,
F58DB55910566D3500CFDF4A /* PBGitSidebarController.m in Sources */,
F58DB5E8105671B600CFDF4A /* PBSourceViewItem.m in Sources */,
+ F567B88D1057FA9F000DB976 /* NSOutlineViewExt.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -0,0 +1,15 @@
+//
+// NSOutlineViewExit.h
+// GitX
+//
+// Created by Pieter de Bie on 9/9/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSOutlineView (PBExpandParents)
+
+- (void)PBExpandItem:(id)item expandParents:(BOOL)expand;
+@end
View
@@ -0,0 +1,25 @@
+//
+// NSOutlineViewExit.m
+// GitX
+//
+// Created by Pieter de Bie on 9/9/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import "NSOutlineViewExt.h"
+
+
+@implementation NSOutlineView (PBExpandParents)
+
+- (void)PBExpandItem:(id)item expandParents:(BOOL)expand
+{
+ NSMutableArray *parents = [NSMutableArray array];
+ while (item) {
+ [parents insertObject:item atIndex:0];
+ item = [item parent];
+ }
+
+ for (id p in parents)
+ [self expandItem:p];
+}
+@end
View
@@ -8,10 +8,12 @@
#import "PBGitSidebarController.h"
#import "PBSourceViewItem.h"
+#import "NSOutlineViewExt.h"
@interface PBGitSidebarController ()
- (void)populateList;
+- (void)updateSelection;
@end
@@ -32,8 +34,42 @@ - (void)awakeFromNib
[super awakeFromNib];
window.contentView = self.view;
[self populateList];
+
+ [repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"currentBranchChange"];
+ [self updateSelection];
}
+- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ if ([@"currentBranchChange" isEqualTo:context])
+ [self updateSelection];
+}
+
+- (void)updateSelection
+{
+ PBGitRevSpecifier *rev = repository.currentBranch;
+ if (!rev)
+ return;
+
+ PBSourceViewItem *item = nil;
+ for (PBSourceViewItem *it in items)
+ if (item = [it findRev:rev])
+ break;
+
+ // TODO: We should add the current branch, or something :)
+
+ if (!item) {
+ [sourceView deselectAll:self];
+ return;
+ }
+
+ [sourceView PBExpandItem:item expandParents:YES];
+ NSInteger index = [sourceView rowForItem:item];
+
+ [sourceView selectRow:index byExtendingSelection:NO];
+}
+
+
#pragma mark NSOutlineView delegate methods
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
{
View
@@ -30,6 +30,7 @@
// so "refs/heads/pu/pb/sidebar" would have the path [@"pu", @"pb", @"sidebare"]
// to the 'local' branch thing
- (void)addRev:(PBGitRevSpecifier *)revSpecifier toPath:(NSArray *)path;
+- (PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev;
- (NSImage *)icon;
View
@@ -72,6 +72,19 @@ - (void)addRev:(PBGitRevSpecifier *)theRevSpecifier toPath:(NSArray *)path
[node addRev:theRevSpecifier toPath:[path subarrayWithRange:NSMakeRange(1, [path count] - 1)]];
}
+- (PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev
+{
+ if (rev == revSpecifier)
+ return self;
+
+ PBSourceViewItem *item = nil;
+ for (PBSourceViewItem *child in children)
+ if (item = [child findRev:rev])
+ return item;
+
+ return nil;
+}
+
- (NSString *)title
{
if (title)

0 comments on commit 23d5c01

Please sign in to comment.