From 2e7cd5268d665bd833614a5f9d22debe1a8a2be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20Walsh?= Date: Tue, 23 Sep 2008 22:58:53 +0100 Subject: [PATCH] Remember selected view (history or commit) --- English.lproj/RepositoryWindow.xib | 67 ++++++++++++++++++------------ PBGitWindowController.h | 2 - PBGitWindowController.m | 11 ++--- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/English.lproj/RepositoryWindow.xib b/English.lproj/RepositoryWindow.xib index a8aaea2..ccaf8b8 100644 --- a/English.lproj/RepositoryWindow.xib +++ b/English.lproj/RepositoryWindow.xib @@ -2,13 +2,13 @@ 1050 - 9F33 + 9E17 670 - 949.34 + 949.33 352.00 YES - + YES @@ -72,9 +72,10 @@ - + 265 {{0, 14}, {183, 22}} + YES 343014976 @@ -170,9 +171,10 @@ Branch - + 268 {{0, 14}, {134, 26}} + YES -2076049856 @@ -280,9 +282,10 @@ View selector - + 268 {{6, 14}, {66, 23}} + YES 67239424 @@ -818,6 +821,13 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ YES YES + + + YES + selectedViewIndex + + YES + @@ -895,22 +905,6 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ 245 - - - selectedIndex: selectedViewIndex - - - - - - selectedIndex: selectedViewIndex - selectedIndex - selectedViewIndex - 2 - - - 275 - predicate: searchController.filterPredicate @@ -1016,6 +1010,22 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ 292 + + + selectedIndex: values.selectedViewIndex + + + + + + selectedIndex: values.selectedViewIndex + selectedIndex + values.selectedViewIndex + 2 + + + 298 + @@ -1229,6 +1239,11 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ BranchesController + + 296 + + + @@ -1281,9 +1296,9 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ com.apple.InterfaceBuilderKit com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin - {{368, 321}, {850, 418}} + {{43, 321}, {850, 418}} com.apple.InterfaceBuilder.CocoaPlugin - {{368, 321}, {850, 418}} + {{43, 321}, {850, 418}} {{15, 196}, {850, 418}} @@ -1291,7 +1306,7 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ {3.40282e+38, 3.40282e+38} {213, 107} - {{429, 871}, {616, 0}} + {{160, 512}, {616, 227}} com.apple.InterfaceBuilder.CocoaPlugin {{132, 614}, {616, 0}} com.apple.InterfaceBuilder.CocoaPlugin @@ -1338,7 +1353,7 @@ ELIAAAAAAAgACAAIAAgAAQABAAEAAQ - 295 + 298 diff --git a/PBGitWindowController.h b/PBGitWindowController.h index c7f589c..efe852a 100644 --- a/PBGitWindowController.h +++ b/PBGitWindowController.h @@ -14,14 +14,12 @@ IBOutlet NSArrayController* searchController; IBOutlet NSArrayController *branchesController; PBGitRepository* repository; - int selectedViewIndex; IBOutlet NSView* contentView; NSViewController* viewController; } @property (retain) PBGitRepository *repository; @property (readonly) NSViewController *viewController; -@property (assign) int selectedViewIndex; @property (retain) NSArrayController *searchController; - (id)initWithRepository:(PBGitRepository*)theRepository; diff --git a/PBGitWindowController.m b/PBGitWindowController.m index a416dbf..615f747 100644 --- a/PBGitWindowController.m +++ b/PBGitWindowController.m @@ -14,7 +14,7 @@ @implementation PBGitWindowController -@synthesize repository, viewController, searchController, selectedViewIndex; +@synthesize repository, viewController, searchController; - (id)initWithRepository:(PBGitRepository*)theRepository; { @@ -22,6 +22,7 @@ { self.repository = theRepository; [self showWindow:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"selectedViewIndex" options:NULL context:NULL]; } return self; } @@ -31,10 +32,10 @@ [[self window] makeFirstResponder:searchField]; } -- (void) setSelectedViewIndex: (int) i +- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context { - selectedViewIndex = i; - [self changeViewController: i]; + if ([keyPath isEqualToString:@"selectedViewIndex"]) + [self changeViewController:[[[NSUserDefaults standardUserDefaults] objectForKey:@"selectedViewIndex"] intValue]]; } - (void)changeViewController:(NSInteger)whichViewTag @@ -74,7 +75,7 @@ { // We bind this ourselves because otherwise we would lose our selection [branchesController bind:@"selectionIndexes" toObject:repository withKeyPath:@"currentBranch" options:nil]; NSLog(@"CurrentBranch: %@", repository.currentBranch); - [self changeViewController:0]; + [self changeViewController:[[[NSUserDefaults standardUserDefaults] objectForKey:@"selectedViewIndex"] intValue]]; [[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; [[self window] setContentBorderThickness:35.0f forEdge:NSMinYEdge];