forked from torifat/iAvro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreferencesController.m
More file actions
105 lines (86 loc) · 3.01 KB
/
Copy pathPreferencesController.m
File metadata and controls
105 lines (86 loc) · 3.01 KB
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
//
// AvroKeyboard
//
// Created by Rifat Nabi on 6/25/12.
// Copyright (c) 2012 OmicronLab. All rights reserved.
//
#import "PreferencesController.h"
#import "AvroKeyboard-Swift.h"
@implementation PreferencesController
@synthesize autoCorrectItemsArray = _autoCorrectItemsArray;
- (instancetype)init
{
self = [super init];
if (self) {
NSMutableDictionary *autoCorrectEntries = [[AutoCorrect shared].entries mutableCopy];
_autoCorrectItemsArray = [[NSMutableArray alloc] init];
for (id key in autoCorrectEntries) {
AutoCorrectItem* item = [[AutoCorrectItem alloc] initWithReplace:key with:autoCorrectEntries[key]];
[_autoCorrectItemsArray addObject:item];
}
}
return self;
}
- (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];
}
- (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:(NSInteger)tag {
NSView* view = nil;
switch (tag) {
case 0:
view = _generalView;
break;
case 1:
view = _autoCorrectView;
break;
default:
view = _aboutView;
break;
}
return view;
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)item {
if (item.tag == _currentViewTag) {
return NO;
}
return YES;
}
- (IBAction)switchView:(id)sender {
NSInteger 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 & NSEventModifierFlagShift) {
[NSAnimationContext currentContext].duration = 1.0;
}
[[self.window.contentView animator] replaceSubview:previousView with:view];
[[self.window animator] setFrame:newFrame display:YES];
[NSAnimationContext endGrouping];
}
- (IBAction)changePredicate:(id)sender {
NSString *searchTerm = [[sender stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSPredicate *predicate = nil;
if (searchTerm.length) {
predicate = [NSPredicate predicateWithFormat:@"(replace CONTAINS[c] %@) OR (with CONTAINS %@)", searchTerm, searchTerm];
}
_autoCorrectController.filterPredicate = predicate;
}
@end