Skip to content

Commit acfa464

Browse files
committed
PBViewController: add a method that is called when a view is loaded for the first time
1 parent 4bc43db commit acfa464

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

PBGitWindowController.m

+13-9
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,32 @@ - (void)changeViewController:(NSInteger)whichViewTag
6969
selectedViewIndex = whichViewTag;
7070
[[NSUserDefaults standardUserDefaults] setInteger:whichViewTag forKey:@"selectedViewIndex"];
7171

72+
BOOL justLoaded = NO;
7273
switch (whichViewTag)
7374
{
74-
case 0: // swap in the "CustomImageViewController - NSImageView"
75-
if (!historyViewController)
75+
case 0:
76+
if (!historyViewController) {
7677
historyViewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:self];
77-
else
78-
[historyViewController updateView];
78+
justLoaded = YES;
79+
}
7980
viewController = historyViewController;
8081
break;
8182
case 1:
82-
if (!commitViewController)
83+
if (!commitViewController) {
8384
commitViewController = [[PBGitCommitController alloc] initWithRepository:repository superController:self];
84-
else
85-
[commitViewController updateView];
86-
85+
justLoaded = YES;
86+
}
8787
viewController = commitViewController;
8888
break;
8989
}
9090

9191
// make sure we automatically resize the controller's view to the current window size
9292
[[viewController view] setFrame: [contentView bounds]];
93-
93+
if (justLoaded)
94+
[viewController viewLoaded];
95+
else
96+
[viewController updateView];
97+
9498
//// embed the current view to our host view
9599
[contentView addSubview: [viewController view]];
96100

PBViewController.h

+12
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@
2121
@property (readonly) NSToolbar *viewToolbar;
2222

2323
- (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGitWindowController *)controller;
24+
25+
/* removeView is called whenever the view is removed, either to be swapped
26+
* with a different view, or when the repository window will be destroyed
27+
*/
2428
- (void) removeView;
29+
30+
/* Updateview is called every time it is loaded into the main view */
2531
- (void) updateView;
32+
33+
/* Called after awakeFromNib:, and the view has been loaded into the main view.
34+
* Useful for resizing stuff after everything has been set in the right position
35+
*/
36+
- (void)viewLoaded;
37+
2638
- (NSResponder *)firstResponder;
2739

2840
@end

PBViewController.m

+9-5
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ - (void) awakeFromNib
3535
{
3636
}
3737

38-
// This is called when the view is displayed again; it
39-
// should be updated to show the most recent information
40-
- (void) updateView
38+
- (NSResponder *)firstResponder;
4139
{
40+
return nil;
4241
}
4342

44-
- (NSResponder *)firstResponder;
43+
// The next methods should be implemented in the subclass if necessary
44+
- (void)updateView
4545
{
46-
return nil;
4746
}
47+
48+
- (void)viewLoaded
49+
{
50+
}
51+
4852
@end

0 commit comments

Comments
 (0)