From acfa464eb4cec36c87096312e333334724536fde Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Mon, 21 Sep 2009 22:09:33 +0200 Subject: [PATCH 1/2] PBViewController: add a method that is called when a view is loaded for the first time --- PBGitWindowController.m | 22 +++++++++++++--------- PBViewController.h | 12 ++++++++++++ PBViewController.m | 16 ++++++++++------ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/PBGitWindowController.m b/PBGitWindowController.m index aba1987..8a338ce 100644 --- a/PBGitWindowController.m +++ b/PBGitWindowController.m @@ -69,28 +69,32 @@ selectedViewIndex = whichViewTag; [[NSUserDefaults standardUserDefaults] setInteger:whichViewTag forKey:@"selectedViewIndex"]; + BOOL justLoaded = NO; switch (whichViewTag) { - case 0: // swap in the "CustomImageViewController - NSImageView" - if (!historyViewController) + case 0: + if (!historyViewController) { historyViewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:self]; - else - [historyViewController updateView]; + justLoaded = YES; + } viewController = historyViewController; break; case 1: - if (!commitViewController) + if (!commitViewController) { commitViewController = [[PBGitCommitController alloc] initWithRepository:repository superController:self]; - else - [commitViewController updateView]; - + justLoaded = YES; + } viewController = commitViewController; break; } // make sure we automatically resize the controller's view to the current window size [[viewController view] setFrame: [contentView bounds]]; - + if (justLoaded) + [viewController viewLoaded]; + else + [viewController updateView]; + //// embed the current view to our host view [contentView addSubview: [viewController view]]; diff --git a/PBViewController.h b/PBViewController.h index 4715c61..5d70dd2 100644 --- a/PBViewController.h +++ b/PBViewController.h @@ -21,8 +21,20 @@ @property (readonly) NSToolbar *viewToolbar; - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGitWindowController *)controller; + +/* removeView is called whenever the view is removed, either to be swapped + * with a different view, or when the repository window will be destroyed + */ - (void) removeView; + +/* Updateview is called every time it is loaded into the main view */ - (void) updateView; + +/* Called after awakeFromNib:, and the view has been loaded into the main view. + * Useful for resizing stuff after everything has been set in the right position + */ +- (void)viewLoaded; + - (NSResponder *)firstResponder; @end diff --git a/PBViewController.m b/PBViewController.m index 510b7a7..4956237 100644 --- a/PBViewController.m +++ b/PBViewController.m @@ -35,14 +35,18 @@ { } -// This is called when the view is displayed again; it -// should be updated to show the most recent information -- (void) updateView -{ -} - - (NSResponder *)firstResponder; { return nil; } + +// The next methods should be implemented in the subclass if necessary +- (void)updateView +{ +} + +- (void)viewLoaded +{ +} + @end From e901894c35db2074f5e1a1010e5bd64dfa527f68 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Mon, 21 Sep 2009 22:10:05 +0200 Subject: [PATCH 2/2] HistoryController: remember location of the split view --- PBGitHistoryController.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index a9fde36..b4a5d66 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -180,6 +180,13 @@ [self refresh:nil]; } +- (void)viewLoaded +{ + float position = [[NSUserDefaults standardUserDefaults] floatForKey:@"PBGitSplitViewPosition"]; + if (position) + [historySplitView setPosition:position ofDividerAtIndex:0]; +} + - (NSResponder *)firstResponder; { return commitList; @@ -201,6 +208,9 @@ - (void) removeView { + float position = [[[historySplitView subviews] objectAtIndex:0] frame].size.height; + [[NSUserDefaults standardUserDefaults] setFloat:position forKey:@"PBGitSplitViewPosition"]; + [[NSUserDefaults standardUserDefaults] synchronize]; [webView close]; [commitController removeObserver:self forKeyPath:@"selection"]; [treeController removeObserver:self forKeyPath:@"selection"];