forked from torifat/iAvro
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPreferencesController.m
77 lines (63 loc) · 2.06 KB
/
PreferencesController.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
//
// AvroKeyboard
//
// Created by Rifat Nabi on 6/25/12.
// Copyright (c) 2012 OmicronLab. All rights reserved.
//
#import "PreferencesController.h"
@implementation PreferencesController
- (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) {
case 0:
view = _generalView;
break;
case 1:
view = _autoCorrectView;
break;
case 2: default:
view = _aboutView;
break;
}
return view;
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)item {
if ([item tag] == _currentViewTag) {
return NO;
}
return YES;
}
- (void)awakeFromNib {
[[self window] setContentSize:[_generalView frame].size];
[[[self window] contentView] addSubview:_generalView];
[[[self window] contentView] setWantsLayer:YES];
// Load Credits
[_aboutContent readRTFDFromFile:[[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtfd"]];
[_aboutContent scrollToBeginningOfDocument:_aboutContent];
}
- (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