Skip to content

Commit 23d5c01

Browse files
committed
Sidebar: hook up branch switching
This is far from perfect, but at least you can use it to navigate the stuff a bit now :)
1 parent ca479c7 commit 23d5c01

6 files changed

+96
-0
lines changed

GitX.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
F56524F00E02D45200F03B52 /* PBGitCommit.m in Sources */ = {isa = PBXBuildFile; fileRef = F56524EF0E02D45200F03B52 /* PBGitCommit.m */; };
6666
F56526240E03D85900F03B52 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F56526230E03D85900F03B52 /* WebKit.framework */; };
6767
F565262B0E03D89B00F03B52 /* PBWebHistoryController.m in Sources */ = {isa = PBXBuildFile; fileRef = F565262A0E03D89B00F03B52 /* PBWebHistoryController.m */; };
68+
F567B88D1057FA9F000DB976 /* NSOutlineViewExt.m in Sources */ = {isa = PBXBuildFile; fileRef = F567B88C1057FA9F000DB976 /* NSOutlineViewExt.m */; };
6869
F569AE930F2CBD7C00C2FFA7 /* Credits.html in Resources */ = {isa = PBXBuildFile; fileRef = F569AE920F2CBD7C00C2FFA7 /* Credits.html */; };
6970
F56ADDD90ED19F9E002AC78F /* AddBranchTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = F56ADDD70ED19F9E002AC78F /* AddBranchTemplate.png */; };
7071
F56ADDDA0ED19F9E002AC78F /* AddLabelTemplate.png in Resources */ = {isa = PBXBuildFile; fileRef = F56ADDD80ED19F9E002AC78F /* AddLabelTemplate.png */; };
@@ -233,6 +234,8 @@
233234
F56526230E03D85900F03B52 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = /System/Library/Frameworks/WebKit.framework; sourceTree = "<absolute>"; };
234235
F56526290E03D89B00F03B52 /* PBWebHistoryController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBWebHistoryController.h; sourceTree = "<group>"; };
235236
F565262A0E03D89B00F03B52 /* PBWebHistoryController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebHistoryController.m; sourceTree = "<group>"; };
237+
F567B88B1057FA9F000DB976 /* NSOutlineViewExt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSOutlineViewExt.h; sourceTree = "<group>"; };
238+
F567B88C1057FA9F000DB976 /* NSOutlineViewExt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSOutlineViewExt.m; sourceTree = "<group>"; };
236239
F569AE920F2CBD7C00C2FFA7 /* Credits.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = Credits.html; sourceTree = "<group>"; };
237240
F56ADDD70ED19F9E002AC78F /* AddBranchTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = AddBranchTemplate.png; path = Images/AddBranchTemplate.png; sourceTree = "<group>"; };
238241
F56ADDD80ED19F9E002AC78F /* AddLabelTemplate.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = AddLabelTemplate.png; path = Images/AddLabelTemplate.png; sourceTree = "<group>"; };
@@ -559,6 +562,8 @@
559562
EB2A73490FEE3F09006601CF /* PBCollapsibleSplitView.m */,
560563
F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */,
561564
F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */,
565+
F567B88B1057FA9F000DB976 /* NSOutlineViewExt.h */,
566+
F567B88C1057FA9F000DB976 /* NSOutlineViewExt.m */,
562567
);
563568
name = Aux;
564569
sourceTree = "<group>";
@@ -894,6 +899,7 @@
894899
EB2A734A0FEE3F09006601CF /* PBCollapsibleSplitView.m in Sources */,
895900
F58DB55910566D3500CFDF4A /* PBGitSidebarController.m in Sources */,
896901
F58DB5E8105671B600CFDF4A /* PBSourceViewItem.m in Sources */,
902+
F567B88D1057FA9F000DB976 /* NSOutlineViewExt.m in Sources */,
897903
);
898904
runOnlyForDeploymentPostprocessing = 0;
899905
};

NSOutlineViewExt.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// NSOutlineViewExit.h
3+
// GitX
4+
//
5+
// Created by Pieter de Bie on 9/9/09.
6+
// Copyright 2009 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
12+
@interface NSOutlineView (PBExpandParents)
13+
14+
- (void)PBExpandItem:(id)item expandParents:(BOOL)expand;
15+
@end

NSOutlineViewExt.m

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// NSOutlineViewExit.m
3+
// GitX
4+
//
5+
// Created by Pieter de Bie on 9/9/09.
6+
// Copyright 2009 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "NSOutlineViewExt.h"
10+
11+
12+
@implementation NSOutlineView (PBExpandParents)
13+
14+
- (void)PBExpandItem:(id)item expandParents:(BOOL)expand
15+
{
16+
NSMutableArray *parents = [NSMutableArray array];
17+
while (item) {
18+
[parents insertObject:item atIndex:0];
19+
item = [item parent];
20+
}
21+
22+
for (id p in parents)
23+
[self expandItem:p];
24+
}
25+
@end

PBGitSidebarController.m

+36
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
#import "PBGitSidebarController.h"
1010
#import "PBSourceViewItem.h"
11+
#import "NSOutlineViewExt.h"
1112

1213
@interface PBGitSidebarController ()
1314

1415
- (void)populateList;
16+
- (void)updateSelection;
1517

1618
@end
1719

@@ -32,8 +34,42 @@ - (void)awakeFromNib
3234
[super awakeFromNib];
3335
window.contentView = self.view;
3436
[self populateList];
37+
38+
[repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"currentBranchChange"];
39+
[self updateSelection];
3540
}
3641

42+
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
43+
{
44+
if ([@"currentBranchChange" isEqualTo:context])
45+
[self updateSelection];
46+
}
47+
48+
- (void)updateSelection
49+
{
50+
PBGitRevSpecifier *rev = repository.currentBranch;
51+
if (!rev)
52+
return;
53+
54+
PBSourceViewItem *item = nil;
55+
for (PBSourceViewItem *it in items)
56+
if (item = [it findRev:rev])
57+
break;
58+
59+
// TODO: We should add the current branch, or something :)
60+
61+
if (!item) {
62+
[sourceView deselectAll:self];
63+
return;
64+
}
65+
66+
[sourceView PBExpandItem:item expandParents:YES];
67+
NSInteger index = [sourceView rowForItem:item];
68+
69+
[sourceView selectRow:index byExtendingSelection:NO];
70+
}
71+
72+
3773
#pragma mark NSOutlineView delegate methods
3874
- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item
3975
{

PBSourceViewItem.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// so "refs/heads/pu/pb/sidebar" would have the path [@"pu", @"pb", @"sidebare"]
3131
// to the 'local' branch thing
3232
- (void)addRev:(PBGitRevSpecifier *)revSpecifier toPath:(NSArray *)path;
33+
- (PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev;
3334

3435
- (NSImage *)icon;
3536

PBSourceViewItem.m

+13
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ - (void)addRev:(PBGitRevSpecifier *)theRevSpecifier toPath:(NSArray *)path
7272
[node addRev:theRevSpecifier toPath:[path subarrayWithRange:NSMakeRange(1, [path count] - 1)]];
7373
}
7474

75+
- (PBSourceViewItem *)findRev:(PBGitRevSpecifier *)rev
76+
{
77+
if (rev == revSpecifier)
78+
return self;
79+
80+
PBSourceViewItem *item = nil;
81+
for (PBSourceViewItem *child in children)
82+
if (item = [child findRev:rev])
83+
return item;
84+
85+
return nil;
86+
}
87+
7588
- (NSString *)title
7689
{
7790
if (title)

0 commit comments

Comments
 (0)