forked from ViennaRSS/vienna-rss
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppearancesPreferences.m
203 lines (180 loc) · 7.3 KB
/
AppearancesPreferences.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
191
192
193
194
195
196
197
198
199
200
201
202
203
//
// AppearancesPreferences.m
// Vienna
//
// Created by Steve on 10/15/05.
// Copyright (c) 2004-2005 Steve Palmer. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "AppearancesPreferences.h"
#import "PopUpButtonExtensions.h"
#import "AppController.h"
#import "Constants.h"
#import "Preferences.h"
// List of available font sizes. I picked the ones that matched
// Mail but you easily could add or remove from the list as needed.
int availableFontSizes[] = { 6, 8, 9, 10, 11, 12, 14, 16, 18, 20, 24, 32, 48, 64 };
#define countOfAvailableFontSizes (sizeof(availableFontSizes)/sizeof(availableFontSizes[0]))
// List of minimum font sizes. I picked the ones that matched the same option in
// Safari but you easily could add or remove from the list as needed.
int availableMinimumFontSizes[] = { 9, 10, 11, 12, 14, 18, 24 };
#define countOfAvailableMinimumFontSizes (sizeof(availableMinimumFontSizes)/sizeof(availableMinimumFontSizes[0]))
// Private functions
@interface AppearancesPreferences (Private)
-(void)initializePreferences;
-(void)selectUserDefaultFont:(NSString *)name size:(int)size control:(NSTextField *)control;
@end
@implementation AppearancesPreferences
/* init
* Initialize the class
*/
-(id)init
{
return [super initWithWindowNibName:@"AppearancesPreferences"];
}
/* windowDidLoad
* First time window load initialisation. Since preferences could potentially be
* changed while the Preferences window is closed, initialise the controls in the
* initializePreferences function instead.
*/
-(void)windowDidLoad
{
[self initializePreferences];
// Set up to be notified if preferences change outside this window
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_FolderFontChange" object:nil];
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_ArticleListFontChange" object:nil];
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_MinimumFontSizeChange" object:nil];
[nc addObserver:self selector:@selector(handleReloadPreferences:) name:@"MA_Notify_PreferenceChange" object:nil];
}
/* handleReloadPreferences
* This gets called when MA_Notify_PreferencesUpdated is broadcast. Just update the controls values.
*/
-(void)handleReloadPreferences:(NSNotification *)nc
{
[self initializePreferences];
}
/* initializePreferences
* Set the preference settings from the user defaults.
*/
-(void)initializePreferences
{
Preferences * prefs = [Preferences standardPreferences];
// Populate the drop downs with the font names and sizes
[self selectUserDefaultFont:[prefs articleListFont] size:[prefs articleListFontSize] control:articleFontSample];
[self selectUserDefaultFont:[prefs folderListFont] size:[prefs folderListFontSize] control:folderFontSample];
// Show folder images option
[showFolderImagesButton setState:[prefs showFolderImages] ? NSOnState : NSOffState];
// Set minimum font size option
[enableMinimumFontSize setState:[prefs enableMinimumFontSize] ? NSOnState : NSOffState];
[minimumFontSizes setEnabled:[prefs enableMinimumFontSize]];
NSUInteger i;
[minimumFontSizes removeAllItems];
for (i = 0; i < countOfAvailableMinimumFontSizes; ++i)
[minimumFontSizes addItemWithObjectValue:[NSNumber numberWithInt:availableMinimumFontSizes[i]]];
[minimumFontSizes setFloatValue:[prefs minimumFontSize]];
}
/* changeShowFolderImages
* Toggle whether or not the folder list shows folder images.
*/
-(IBAction)changeShowFolderImages:(id)sender
{
BOOL showFolderImages = [sender state] == NSOnState;
[[Preferences standardPreferences] setShowFolderImages:showFolderImages];
}
/* changeMinimumFontSize
* Enable whether a minimum font size is used for article display.
*/
-(IBAction)changeMinimumFontSize:(id)sender
{
BOOL useMinimumFontSize = [sender state] == NSOnState;
[[Preferences standardPreferences] setEnableMinimumFontSize:useMinimumFontSize];
[minimumFontSizes setEnabled:useMinimumFontSize];
}
/* selectMinimumFontSize
* Changes the actual minimum font size for article display.
*/
-(IBAction)selectMinimumFontSize:(id)sender
{
float newMinimumFontSize = [minimumFontSizes floatValue];
[[Preferences standardPreferences] setMinimumFontSize:newMinimumFontSize];
}
/* selectUserDefaultFont
* Display sample text in the specified font and size.
*/
-(void)selectUserDefaultFont:(NSString *)name size:(int)size control:(NSTextField *)control
{
[control setFont:[NSFont fontWithName:name size:size]];
[control setStringValue:[NSString stringWithFormat:@"%@ %i", name, size]];
}
/* selectArticleFont
* Bring up the standard font selector for the article font.
*/
-(IBAction)selectArticleFont:(id)sender
{
Preferences * prefs = [Preferences standardPreferences];
NSFontManager * manager = [NSFontManager sharedFontManager];
[manager setSelectedFont:[NSFont fontWithName:[prefs articleListFont] size:[prefs articleListFontSize]] isMultiple:NO];
[manager setAction:@selector(changeArticleFont:)];
[manager setDelegate:self];
[manager orderFrontFontPanel:self];
[[articleFontSample window] setDelegate:self];
}
/* selectFolderFont
* Bring up the standard font selector for the folder font.
*/
-(IBAction)selectFolderFont:(id)sender
{
Preferences * prefs = [Preferences standardPreferences];
NSFontManager * manager = [NSFontManager sharedFontManager];
[manager setSelectedFont:[NSFont fontWithName:[prefs folderListFont] size:[prefs folderListFontSize]] isMultiple:NO];
[manager setAction:@selector(changeFolderFont:)];
[[folderFontSample window] makeFirstResponder:self];
[manager setDelegate:self];
[manager orderFrontFontPanel:self];
[[folderFontSample window] setDelegate:self];
}
/* changeArticleFont
* Respond to changes to the article font.
*/
-(IBAction)changeArticleFont:(id)sender
{
Preferences * prefs = [Preferences standardPreferences];
NSFont * font = [NSFont fontWithName:[prefs articleListFont] size:[prefs articleListFontSize]];
font = [sender convertFont:font];
[prefs setArticleListFont:[font fontName]];
[prefs setArticleListFontSize:[font pointSize]];
[self selectUserDefaultFont:[prefs articleListFont] size:[prefs articleListFontSize] control:articleFontSample];
}
/* changeFolderFont
* Respond to changes to the folder font.
*/
-(IBAction)changeFolderFont:(id)sender
{
Preferences * prefs = [Preferences standardPreferences];
NSFont * font = [NSFont fontWithName:[prefs folderListFont] size:[prefs folderListFontSize]];
font = [sender convertFont:font];
[prefs setFolderListFont:[font fontName]];
[prefs setFolderListFontSize:[font pointSize]];
[self selectUserDefaultFont:[prefs folderListFont] size:[prefs folderListFontSize] control:folderFontSample];
}
/* dealloc
* Clean up and release resources.
*/
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
@end