From b2c03bc97bccde146b49f0ea164d4bbc7e2ce176 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Wed, 19 Nov 2008 02:12:03 +0100 Subject: [PATCH] HistoryView: Correctly update branches when changing them I stupidly used "observe.." instead of register.. so KVC didn't even work --- PBRefController.h | 5 +++++ PBRefController.m | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/PBRefController.h b/PBRefController.h index 880ad19..4ec8990 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -29,4 +29,9 @@ - (IBAction)saveSheet:(id) sender; - (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit; + +- (void) changeBranch:(NSMenuItem *)sender; +- (void) selectCurrentBranch; +- (void) updateBranchMenu; + @end diff --git a/PBRefController.m b/PBRefController.m index d2b7c2d..9656aa1 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -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