-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppearancePreferencePane.m
77 lines (60 loc) · 1.94 KB
/
AppearancePreferencePane.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
//
// AppearancePreferencePane.m
// Pipe
//
// Created by RenŽ Puls on 12.03.05.
// Copyright 2005 RenŽ Puls. All rights reserved.
//
#import "AppearancePreferencePane.h"
#import "UserDefaults.h"
@implementation AppearancePreferencePane
- (id)init
{
if ((self = [super init])) {
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[NSString stringWithFormat:@"values.%@", PipeFontDefaultKey] options:nil context:NULL];
}
return self;
}
- (void)contentViewDidLoad
{
[self applyPrefs:self];
}
- (void)dealloc
{
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[NSString stringWithFormat:@"values.%@", PipeFontDefaultKey]];
[super dealloc];
}
- (NSString *)title
{
return NSLocalizedString(@"Appearance", @"Preferences panel (TOOL)");
}
- (NSImage *)image
{
return [NSImage imageNamed:@"Appearance Preferences"];
}
- (void)showFontSelector:(id)sender
{
NSFont *myFont;
myFont = [NSUnarchiver unarchiveObjectWithData:JGUserDefaultValue(PipeFontDefaultKey)];
[[NSFontManager sharedFontManager] setSelectedFont:myFont isMultiple:NO];
[[NSFontManager sharedFontManager] orderFrontFontPanel:self];
}
- (void)changeFont:(id)sender
{
NSFont *myFont;
myFont = [NSUnarchiver unarchiveObjectWithData:JGUserDefaultValue(PipeFontDefaultKey)];
myFont = [sender convertFont:myFont];
JGSetUserDefaultValue(PipeFontDefaultKey, [NSArchiver archivedDataWithRootObject:myFont]);
}
- (void)applyPrefs:(id)sender
{
NSFont *myFont = [NSUnarchiver unarchiveObjectWithData:JGUserDefaultValue(PipeFontDefaultKey)];
NSFont *displayFont = [NSFont fontWithName:[myFont fontName] size:12];
[fontTextField setStringValue:[NSString stringWithFormat:@"%@ %.0f", [myFont displayName], [myFont pointSize]]];
[fontTextField setFont:displayFont];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
[self applyPrefs:self];
}
@end