-
Notifications
You must be signed in to change notification settings - Fork 601
/
PBGitWindowController.m
116 lines (93 loc) · 3.03 KB
/
PBGitWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// PBDetailController.m
// GitX
//
// Created by Pieter de Bie on 16-06-08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "PBGitWindowController.h"
#import "PBGitHistoryController.h"
#import "PBGitCommitController.h"
@implementation PBGitWindowController
@synthesize repository, viewController, selectedViewIndex;
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
{
if(self = [self initWithWindowNibName:@"RepositoryWindow"])
{
self.repository = theRepository;
[self showWindow:nil];
}
if (displayDefault) {
self.selectedViewIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"selectedViewIndex"];
} else {
self.selectedViewIndex = -1;
}
return self;
}
- (void)windowWillClose:(NSNotification *)notification
{
NSLog(@"Window will close!");
if (historyViewController)
[historyViewController removeView];
if (commitViewController)
[commitViewController removeView];
}
- (void) setSelectedViewIndex: (int) i
{
selectedViewIndex = i;
[[NSUserDefaults standardUserDefaults] setInteger:i forKey:@"selectedViewIndex"];
[self changeViewController: i];
}
- (void)changeViewController:(NSInteger)whichViewTag
{
[self willChangeValueForKey:@"viewController"];
if (viewController != nil)
[[viewController view] removeFromSuperview];
switch (whichViewTag)
{
case 0: // swap in the "CustomImageViewController - NSImageView"
if (!historyViewController)
historyViewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:self];
viewController = historyViewController;
break;
case 1:
if (!commitViewController)
commitViewController = [[PBGitCommitController alloc] initWithRepository:repository superController:self];
viewController = commitViewController;
break;
}
// make sure we automatically resize the controller's view to the current window size
[[viewController view] setFrame: [contentView bounds]];
//// embed the current view to our host view
[contentView addSubview: [viewController view]];
[self useToolbar: [viewController viewToolbar]];
// Allow the viewcontroller to catch actions
[self setNextResponder: viewController];
[self didChangeValueForKey:@"viewController"]; // this will trigger the NSTextField's value binding to change
}
- (void)awakeFromNib
{
[[self window] setDelegate:self];
[[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge];
[[self window] setContentBorderThickness:35.0f forEdge:NSMinYEdge];
[self showHistoryView:nil];
}
- (void) showCommitView:(id)sender
{
if (self.selectedViewIndex != 1)
self.selectedViewIndex = 1;
}
- (void) showHistoryView:(id)sender
{
if (self.selectedViewIndex != 0)
self.selectedViewIndex = 0;
}
#pragma mark -
#pragma mark Toolbar Delegates
- (void) useToolbar:(NSToolbar *)toolbar
{
NSSegmentedControl *item = (NSSegmentedControl *)[[[toolbar items] objectAtIndex:0] view];
[item bind:@"selectedIndex" toObject:self withKeyPath:@"selectedViewIndex" options:0];
[self.window setToolbar:toolbar];
}
@end