forked from bdrister/dterm
-
Notifications
You must be signed in to change notification settings - Fork 15
/
DTPrefsWindowController.m
190 lines (152 loc) · 5.77 KB
/
DTPrefsWindowController.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// DTPrefsWindowController.m
// Copyright (c) 2007-2010 Decimus Software, Inc. All rights reserved.
#import "DTPrefsWindowController.h"
#import "DTAppController.h"
#import "DTPrefsAXController.h"
#import "FontNameToDisplayNameTransformer.h"
#import "SRRecorderControl.h"
@implementation DTPrefsWindowController
//@synthesize regPrefsViewController;
@synthesize axPrefsController;
+ (void)initialize {
// Create and register font name value transformer
NSValueTransformer *transformer = [[FontNameToDisplayNameTransformer alloc] init];
[NSValueTransformer setValueTransformer:transformer forName:@"FontNameToDisplayNameTransformer"];
}
- (instancetype)init {
if((self = [super initWithWindowNibName:@"Preferences"])) {
[self setShouldCascadeWindows:NO];
[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
}
return self;
}
// Don't allow closing if we can't commit editing
- (BOOL)windowShouldClose:(id) __unused window {
return [[self window] makeFirstResponder:nil];
}
- (void)windowDidLoad {
[shortcutRecorder setAllowsKeyOnly:NO escapeKeysRecord:NO];
[shortcutRecorder setKeyCombo:[APP_DELEGATE hotKey]];
}
- (void)windowDidBecomeKey:(NSNotification *) __unused notification {
[axPrefsController recheckGeneralAXAccess];
}
- (IBAction)showPrefs:(id)sender {
if(![[self window] isVisible])
[self showGeneral:sender];
else {
[[self window] center];
[[self window] makeKeyAndOrderFront:sender];
}
}
- (BOOL)shortcutRecorder:(SRRecorderControl *)aRecorder
isKeyCode:(NSInteger)keyCode
andFlagsTaken:(NSUInteger)flags
reason:(NSString * __autoreleasing *)aReason
{
UnusedParameter(aRecorder);
UnusedParameter(keyCode);
UnusedParameter(flags);
UnusedParameter(aReason);
return NO;
}
- (void)shortcutRecorder:(SRRecorderControl *)aRecorder
keyComboDidChange:(KeyCombo)newKeyCombo
{
UnusedParameter(aRecorder);
// NSLog(@"New key combo: key code %d, flags %d", newKeyCombo.code, newKeyCombo.flags);
[APP_DELEGATE setHotKey:newKeyCombo];
}
- (void)showView:(NSView*)prefsView {
NSWindow* prefsWindow = [self window];
//blank view to stop flicker
NSView *tempView = [[NSView alloc] initWithFrame:[[prefsWindow contentView] frame]];
[prefsWindow setContentView:tempView];
//mojo to get the right frame for the new window.
NSRect newFrame = [prefsWindow frame];
newFrame.size.height = [prefsView frame].size.height +
([prefsWindow frame].size.height - [[prefsWindow contentView] frame].size.height);
newFrame.size.width = [prefsView frame].size.width;
newFrame.origin.y += ([[prefsWindow contentView] frame].size.height - [prefsView frame].size.height);
//set the frame to newFrame and animate it. (change animate:YES to animate:NO if you don't want this)
// [prefsWindow setShowsResizeIndicator:YES];
[prefsWindow setFrame:newFrame display:YES animate:YES];
//set the main content view to the new view
[prefsWindow setContentView:prefsView];
if (![prefsWindow isVisible]) {
[[self window] center];
[[self window] makeKeyAndOrderFront:self];
}
}
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {
return [toolbar valueForKeyPath:@"items.itemIdentifier"];
}
- (IBAction)showGeneral:(id) __unused sender {
// make sure we have a window
[self window];
// This method can be called programmatically, so make sure general toolbar icon is selected
NSToolbar* toolbar = [[self window] toolbar];
for(NSToolbarItem* item in [toolbar items]) {
if([item tag] == 1 /* general tag */) {
[toolbar setSelectedItemIdentifier:[item itemIdentifier]];
break;
}
}
[self showView:generalPrefsView];
}
- (IBAction)showAccessibility:(id) __unused sender {
// make sure we have a window
[self window];
// This method can be called programmatically, so make sure accessibility toolbar icon is selected
NSToolbar* toolbar = [[self window] toolbar];
for(NSToolbarItem* item in [toolbar items]) {
if([item tag] == 2 /* accessibility tag */) {
[toolbar setSelectedItemIdentifier:[item itemIdentifier]];
break;
}
}
[self showView:accessibilityPrefsView];
}
- (IBAction)showUpdates:(id) __unused sender {
// make sure we have a window
[self window];
// This method can be called programmatically, so make sure updates toolbar icon is selected
NSToolbar* toolbar = [[self window] toolbar];
for(NSToolbarItem* item in [toolbar items]) {
if([item tag] == 3 /* updates tag */) {
[toolbar setSelectedItemIdentifier:[item itemIdentifier]];
break;
}
}
[self showView:updatesPrefsView];
}
#pragma mark font selection
- (IBAction)showFontPanel:(id) __unused sender {
// Get font name and size from user defaults
NSDictionary *values = [[NSUserDefaultsController sharedUserDefaultsController] values];
NSString *fontName = [values valueForKey:DTFontNameKey];
CGFloat fontSize = [[values valueForKey:DTFontSizeKey] floatValue];
// Create font from name and size; initialize font panel
NSFont *font = [NSFont fontWithName:fontName size:fontSize];
if(!font) {
font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
}
[[NSFontManager sharedFontManager] setSelectedFont:font
isMultiple:NO];
[[NSFontManager sharedFontManager] orderFrontFontPanel:self];
// Set window as firstResponder so we get changeFont: messages
[[self window] makeFirstResponder:[self window]];
}
- (IBAction)resetColorAndFont:(id) __unused sender {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:DTFontNameKey];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:DTFontSizeKey];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:DTTextColorKey];
}
#pragma mark Updates support
- (IBAction)checkForUpdatesNow:(id) sender
{
UnusedParameter(sender);
// [[APP_DELEGATE sparkleUpdater] checkForUpdates:sender];
NSLog(@"enable the preceding line of code");
}
@end