blob: ab992ed2a4c0b8f951933f09f36c1a81cd965294 (
plain)
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
117
118
119
120
121
122
123
124
125
|
//
// PreferenceController.m
// TikZiT
//
// Created by Karl Johan Paulsson on 26/02/2013.
// Copyright (c) 2013 Aleks Kissinger. All rights reserved.
//
//
// This file is part of TikZiT.
//
// TikZiT is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TikZiT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TikZiT. If not, see <http://www.gnu.org/licenses/>.
//
#import "PreferenceController.h"
@interface PreferenceController ()
@end
@implementation PreferenceController
- (id)initWithWindowNibName:(NSString *)windowNibName preambleController:(PreambleController*)pc{
[super initWithWindowNibName:windowNibName];
preambleController = pc;
return self;
}
- (NSRect)newFrameForNewContentView:(NSView*)view {
NSWindow *window = [self window];
NSRect newFrameRect = [window frameRectForContentRect:[view frame]];
NSRect oldFrameRect = [window frame];
NSSize newSize = newFrameRect.size;
NSSize oldSize = oldFrameRect.size;
NSRect frame = [window frame];
frame.size = newSize;
frame.origin.y -= (newSize.height - oldSize.height);
return frame;
}
- (NSView *)viewForTag:(int)tag {
NSView *view = nil;
switch (tag) {
default:
case 0:
view = generalView;
break;
case 1:
view = engineView;
break;
case 2:
view = updateView;
break;
case 3:
view = preambleView;
break;
}
return view;
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)item {
if ([item tag] == currentViewTag) return NO;
else return YES;
}
- (void)awakeFromNib {
[[self window] setContentSize:[generalView frame].size];
[[[self window] contentView] addSubview:generalView];
[[[self window] contentView] setWantsLayer:YES];
updateController = [[UpdatePreferenceController alloc] initWithNibName:@"UpdatePreferencePanel" bundle:nil];
[[updateController view] setFrame:[updateView frame]];
[[[self window] contentView] replaceSubview:updateView with:[updateController view]];
updateView = [updateController view];
[[preambleController view] setFrame:[preambleView frame]];
[[[self window] contentView] replaceSubview:preambleView with:[preambleController view]];
preambleView = [preambleController view];
[[self window] setContentSize:[preambleView frame].size];
[[[self window] contentView] addSubview:preambleView];
currentViewTag = 3;
}
- (IBAction)switchView:(id)sender {
int tag = [sender tag];
NSView *view = [self viewForTag:tag];
NSView *previousView = [self viewForTag:currentViewTag];
currentViewTag = tag;
NSRect newFrame = [self newFrameForNewContentView:view];
[NSAnimationContext beginGrouping];
if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask)
[[NSAnimationContext currentContext] setDuration:1.0];
[[[[self window] contentView] animator] replaceSubview:previousView with:view];
[[[self window] animator] setFrame:newFrame display:YES];
[NSAnimationContext endGrouping];
}
@end
|