-
Notifications
You must be signed in to change notification settings - Fork 56
/
PreferencesController.m
77 lines (56 loc) · 2.07 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
//
// PreferencesController.m
// MarkdownLive
//
// Created by Akihiro Noguchi on 7/05/11.
// Copyright 2011 Aki. All rights reserved.
//
#import "PreferencesController.h"
#import "PreferencesManager.h"
NSString * const kEditPaneFontNameChangedNotification = @"EditPaneFontNameChangedNotification";
NSString * const kFontDisplayFormat = @"%@ %g pt.";
@interface PreferencesController (Private)
- (void)updateFontDisplay;
@end
@implementation PreferencesController
- (void)awakeFromNib {
[self updateFontDisplay];
}
- (IBAction)showFonts:(id)sender {
NSFontManager *fontMan = [NSFontManager sharedFontManager];
NSFont *currentFont = [PreferencesManager editPaneFont];
[prefWindow makeFirstResponder:prefWindow];
[fontMan setSelectedFont:currentFont isMultiple:NO];
[fontMan orderFrontFontPanel:sender];
}
- (void)updateFontDisplay {
NSString *fontName = [PreferencesManager editPaneFontName];
float fontSize = [PreferencesManager editPaneFontSize];
[fontPreviewField setStringValue:[NSString stringWithFormat:kFontDisplayFormat, fontName, fontSize]];
}
- (IBAction)resetEditPanePreferences:(id)sender {
#pragma unused(sender)
[PreferencesManager resetEditPanePreferences];
[self updateFontDisplay];
[[NSNotificationCenter defaultCenter] postNotificationName:kEditPaneFontNameChangedNotification
object:nil];
}
- (void)changeFont:(id)sender {
NSFont *newFont = [sender convertFont:[NSFont systemFontOfSize:0]];
NSString *fontName = [newFont fontName];
float fontSize = [newFont pointSize];
if (newFont && fontName) {
[PreferencesManager setEditPaneFontName:fontName];
[PreferencesManager setEditPaneFontSize:fontSize];
[fontPreviewField setStringValue:[NSString stringWithFormat:kFontDisplayFormat, fontName, fontSize]];
[[NSNotificationCenter defaultCenter] postNotificationName:kEditPaneFontNameChangedNotification
object:nil];
}
}
- (NSUInteger)validModesForFontPanel:(NSFontPanel *)fontPanel {
#pragma unused(fontPanel)
return (NSFontPanelFaceModeMask |
NSFontPanelSizeModeMask |
NSFontPanelCollectionModeMask);
}
@end