HistoryView: Correctly update branches when changing them

I stupidly used "observe.." instead of register.. so KVC
didn't even work
This commit is contained in:
Pieter de Bie
2008-11-19 02:12:03 +01:00
parent 6038c20d7d
commit b2c03bc97b
2 changed files with 18 additions and 3 deletions
+5
View File
@@ -29,4 +29,9 @@
- (IBAction)saveSheet:(id) sender;
- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit;
- (void) changeBranch:(NSMenuItem *)sender;
- (void) selectCurrentBranch;
- (void) updateBranchMenu;
@end
+13 -3
View File
@@ -15,7 +15,9 @@
- (void)awakeFromNib
{
[commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]];
[self observeValueForKeyPath:@"repository.branches" ofObject:historyController change:NULL context:@"branchChange"];
[historyController addObserver:self forKeyPath:@"repository.branches" options:0 context:@"branchChange"];
[historyController addObserver:self forKeyPath:@"repository.currentBranch" options:0 context:@"currentBranchChange"];
[self updateBranchMenu];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(id)context
@@ -23,6 +25,9 @@
if ([context isEqualToString: @"branchChange"]) {
[self updateBranchMenu];
}
else if ([context isEqualToString:@"currentBranchChange"]) {
[self selectCurrentBranch];
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
@@ -186,7 +191,6 @@
- (void) updateBranchMenu
{
NSLog(@"Updating branch");
if (!branchPopUp)
return;
@@ -286,6 +290,12 @@
{
PBGitRevSpecifier *rev = [sender representedObject];
historyController.repository.currentBranch = rev;
[branchPopUp setTitle:[sender title]];
}
- (void) selectCurrentBranch
{
PBGitRevSpecifier *rev = historyController.repository.currentBranch;
[branchPopUp setTitle:[rev description]];
}
@end