forked from dgrijalva/gitx
-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathPBWebHistoryController.m
83 lines (69 loc) · 2.09 KB
/
PBWebHistoryController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// PBWebHistoryController.m
// GitTest
//
// Created by Pieter de Bie on 14-06-08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBWebHistoryController.h"
#import "PBGitDefaults.h"
#import "PBGitHistoryController.h"
@implementation PBWebHistoryController
@synthesize historyController;
- (void) awakeFromNib
{
startFile = @"history";
repository = historyController.repository;
[super awakeFromNib];
[historyController addObserver:self forKeyPath:@"webCommit" options:0 context:@"ChangedCommit"];
}
- (void)closeView
{
[[self script] setValue:nil forKey:@"commit"];
[historyController removeObserver:self forKeyPath:@"webCommit"];
[super closeView];
}
- (void) didLoad
{
[super didLoad];
[self changeContentTo: historyController.webCommit];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([(__bridge NSString *)context isEqualToString: @"ChangedCommit"])
[self changeContentTo: historyController.webCommit];
else
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
- (NSString*) refsForCurrentCommit
{
NSMutableString *refs = [NSMutableString string];
NSArray *refsA = [historyController.webCommit refs];
NSString *currentRef = [[[historyController repository] headRef] simpleRef];
NSString *style = @"";
for(PBGitRef *ref in refsA){
if([currentRef isEqualToString:[ref ref]]){
style = [NSString stringWithFormat:@"currentBranch refs %@",[ref type]];
}else{
style = [NSString stringWithFormat:@"refs %@",[ref type]];
}
[refs appendString:[NSString stringWithFormat:@"<span class='%@'>%@</span>",style,[ref shortName]]];
}
return refs;
}
- (void)selectCommit:(NSString *)sha
{
[historyController selectCommit:sha];
}
- (PBGitRef*) refFromString:(NSString*)refString
{
for (PBGitRef *ref in historyController.webCommit.refs)
if ([[ref shortName] isEqualToString:refString])
return ref;
return nil;
}
- (NSArray*) menuItemsForPath:(NSString*)path
{
return [historyController menuItemsForPaths:[NSArray arrayWithObject:path]];
}
@end