mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
make Appearance pref pane use labeled buttons for changing fonts, also lots of stylistic cleanup (bug 175924)
This commit is contained in:
parent
8ab3d601bb
commit
48acafa86d
@ -50,7 +50,8 @@
|
||||
IBOutlet NSColorWell *colorwellUnvisitedLinks;
|
||||
IBOutlet NSColorWell *colorwellVisitedLinks;
|
||||
|
||||
IBOutlet NSMatrix *matrixChooseFont;
|
||||
IBOutlet NSButton *chooseProportionalFontButton;
|
||||
IBOutlet NSButton *chooseMonospaceFontButton;
|
||||
IBOutlet NSPopUpButton *popupFontRegion;
|
||||
|
||||
IBOutlet NSTextField *fontSampleProportional;
|
||||
@ -65,13 +66,14 @@
|
||||
IBOutlet NSPopUpButton *cursiveFontPopup;
|
||||
IBOutlet NSPopUpButton *fantasyFontPopup;
|
||||
IBOutlet NSPopUpButton *minFontSizePopup;
|
||||
|
||||
IBOutlet NSTextField *advancedFontsLabel;
|
||||
|
||||
IBOutlet NSMatrix *defaultFontMatrix;
|
||||
|
||||
|
||||
NSArray *regionMappingTable;
|
||||
NSString *defaultFontType;
|
||||
|
||||
NSButton *fontButtonForEditor;
|
||||
}
|
||||
|
||||
- (void)mainViewDidLoad;
|
||||
@ -79,7 +81,8 @@
|
||||
- (IBAction)buttonClicked:(id)sender;
|
||||
- (IBAction)colorChanged:(id)sender;
|
||||
|
||||
- (IBAction)fontChoiceButtonClicked:(id)sender;
|
||||
- (IBAction)proportionalFontChoiceButtonClicked:(id)sender;
|
||||
- (IBAction)monospaceFontChoiceButtonClicked:(id)sender;
|
||||
- (IBAction)fontRegionPopupClicked:(id)sender;
|
||||
|
||||
- (IBAction)showAdvancedFontsDialog:(id)sender;
|
||||
|
@ -63,7 +63,6 @@
|
||||
- (void)updateFontSampleOfType:(NSString *)fontType;
|
||||
- (NSTextField*)getFontSampleForType:(NSString *)fontType;
|
||||
- (NSString*)getFontSizeType:(NSString*)fontType;
|
||||
- (void)syncFontPanel;
|
||||
|
||||
- (void)buildFontPopup:(NSPopUpButton*)popupButton;
|
||||
|
||||
@ -85,6 +84,7 @@
|
||||
- (id)initWithBundle:(NSBundle *)bundle
|
||||
{
|
||||
self = [super initWithBundle:bundle];
|
||||
fontButtonForEditor = nil;
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -113,7 +113,6 @@
|
||||
|
||||
[self setupFontRegionPopup];
|
||||
[self updateFontPreviews];
|
||||
|
||||
}
|
||||
|
||||
- (void)willUnselect
|
||||
@ -134,8 +133,7 @@
|
||||
[self loadFontPrefs];
|
||||
|
||||
[popupFontRegion removeAllItems];
|
||||
for (unsigned int i = 0; i < [regionMappingTable count]; i ++)
|
||||
{
|
||||
for (unsigned int i = 0; i < [regionMappingTable count]; i++) {
|
||||
NSDictionary* regionDict = [regionMappingTable objectAtIndex:i];
|
||||
[popupFontRegion addItemWithTitle:[regionDict objectForKey:@"region"]];
|
||||
}
|
||||
@ -144,13 +142,9 @@
|
||||
- (IBAction)buttonClicked:(id)sender
|
||||
{
|
||||
if (sender == checkboxUnderlineLinks)
|
||||
{
|
||||
[self setPref:"browser.underline_anchors" toBoolean:[sender state]];
|
||||
}
|
||||
else if (sender == checkboxUseMyColors)
|
||||
{
|
||||
[self setPref:"browser.display.use_document_colors" toBoolean:![sender state]];
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)colorChanged:(id)sender
|
||||
@ -170,12 +164,22 @@
|
||||
[self setPref:prefName toColor:[sender color]];
|
||||
}
|
||||
|
||||
- (IBAction)fontChoiceButtonClicked:(id)sender
|
||||
- (IBAction)proportionalFontChoiceButtonClicked:(id)sender
|
||||
{
|
||||
[self syncFontPanel];
|
||||
NSFontManager *fontManager = [NSFontManager sharedFontManager];
|
||||
NSFont *newFont = [[self getFontSampleForType:[chooseProportionalFontButton alternateTitle]] font];
|
||||
fontButtonForEditor = chooseProportionalFontButton;
|
||||
[fontManager setSelectedFont:newFont isMultiple:NO];
|
||||
[[fontManager fontPanel:YES] makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
NSFontPanel *fontPanel = [[NSFontManager sharedFontManager] fontPanel:YES];
|
||||
[fontPanel makeKeyAndOrderFront:self];
|
||||
- (IBAction)monospaceFontChoiceButtonClicked:(id)sender
|
||||
{
|
||||
NSFontManager *fontManager = [NSFontManager sharedFontManager];
|
||||
NSFont *newFont = [[self getFontSampleForType:[chooseMonospaceFontButton alternateTitle]] font];
|
||||
fontButtonForEditor = chooseMonospaceFontButton;
|
||||
[fontManager setSelectedFont:newFont isMultiple:NO];
|
||||
[[fontManager fontPanel:YES] makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
- (IBAction)fontRegionPopupClicked:(id)sender
|
||||
@ -186,8 +190,7 @@
|
||||
|
||||
- (void)loadFontPrefs
|
||||
{
|
||||
for (unsigned int i = 0; i < [regionMappingTable count]; i ++)
|
||||
{
|
||||
for (unsigned int i = 0; i < [regionMappingTable count]; i++) {
|
||||
NSMutableDictionary *regionDict = [regionMappingTable objectAtIndex:i];
|
||||
NSString *regionCode = [regionDict objectForKey:@"code"];
|
||||
|
||||
@ -246,7 +249,6 @@
|
||||
NSMutableDictionary *sizesDict = [self makeFontSizesDictFromPrefsForRegion:regionCode];
|
||||
[regionDict setObject:sizesDict forKey:@"fontsize"];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)saveFontPrefs
|
||||
@ -254,8 +256,7 @@
|
||||
if (!regionMappingTable)
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < [regionMappingTable count]; i ++)
|
||||
{
|
||||
for (unsigned int i = 0; i < [regionMappingTable count]; i++) {
|
||||
NSMutableDictionary *regionDict = [regionMappingTable objectAtIndex:i];
|
||||
|
||||
[self saveFontNamePrefsForRegion:regionDict forFontType:@"serif"];
|
||||
@ -360,12 +361,10 @@
|
||||
NSMutableDictionary *fontTypeDict = [regionDict objectForKey:fontType];
|
||||
NSMutableDictionary *fontSizeDict = [regionDict objectForKey:@"fontsize"];
|
||||
|
||||
BOOL missingFont = [[fontTypeDict objectForKey:@"missing"] boolValue]; // will be NO if no object
|
||||
if (missingFont)
|
||||
if ([[fontTypeDict objectForKey:@"missing"] boolValue]) // will be false if no object
|
||||
return;
|
||||
|
||||
if (font)
|
||||
{
|
||||
if (font) {
|
||||
[fontTypeDict setObject:[font familyName] forKey:@"fontfamily"];
|
||||
[fontSizeDict setObject:[NSNumber numberWithInt:(int)[font pointSize]] forKey:[self getFontSizeType:fontType]];
|
||||
}
|
||||
@ -381,15 +380,12 @@
|
||||
|
||||
NSFont *returnFont = nil;
|
||||
|
||||
if (fontName && fontSize > 0)
|
||||
{
|
||||
if (fontName && fontSize > 0) {
|
||||
// we can't use [NSFont fontWithName] here, because we only store font
|
||||
// family names in the prefs file. So use the font manager instead
|
||||
// returnFont = [NSFont fontWithName:fontName size:fontSize];
|
||||
returnFont = [[NSFontManager sharedFontManager] fontWithFamily:fontName traits:0 weight:5 size:fontSize];
|
||||
}
|
||||
else if (fontName)
|
||||
{
|
||||
} else if (fontName) {
|
||||
// no size
|
||||
returnFont = [[NSFontManager sharedFontManager] fontWithFamily:fontName traits:0 weight:5 size:16.0];
|
||||
}
|
||||
@ -426,10 +422,8 @@
|
||||
NSTextField *sampleCell = [self getFontSampleForType:fontType];
|
||||
NSString *displayString = nil;
|
||||
|
||||
if (font == nil)
|
||||
{
|
||||
if (regionDict)
|
||||
{
|
||||
if (font == nil) {
|
||||
if (regionDict) {
|
||||
NSDictionary *fontSizeDict = [regionDict objectForKey:@"fontsize"];
|
||||
NSString *fontName = [fontTypeDict objectForKey:@"fontfamily"];
|
||||
int fontSize = [[fontSizeDict objectForKey:[self getFontSizeType:fontType]] intValue];
|
||||
@ -438,25 +432,19 @@
|
||||
font = [NSFont userFontOfSize:14.0];
|
||||
|
||||
// set the missing flag in the dict
|
||||
if (![fontTypeDict objectForKey:@"missing"] || ![[fontTypeDict objectForKey:@"missing"] boolValue])
|
||||
{
|
||||
if (![fontTypeDict objectForKey:@"missing"] || ![[fontTypeDict objectForKey:@"missing"] boolValue]) {
|
||||
[fontTypeDict setObject:[NSNumber numberWithBool:YES] forKey:@"missing"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// should never happen
|
||||
// XXX localize
|
||||
displayString = @"Font missing";
|
||||
font = [NSFont userFontOfSize:16.0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
NS_DURING
|
||||
displayString = [NSString stringWithFormat:@"%@, %dpt", [font displayName], (int)[font pointSize]];
|
||||
NS_HANDLER
|
||||
NSLog(@"Exception %@ getting [font displayName] for %@", localException, font);
|
||||
displayString = [NSString stringWithFormat:@"%@, %dpt", [font familyName], (int)[font pointSize]];
|
||||
NS_ENDHANDLER
|
||||
|
||||
@ -504,14 +492,6 @@
|
||||
return @"variable";
|
||||
}
|
||||
|
||||
- (void)syncFontPanel
|
||||
{
|
||||
NSString *fontType = [[matrixChooseFont selectedCell] alternateTitle];
|
||||
NSFont *newFont = [[self getFontSampleForType:fontType] font];
|
||||
|
||||
[[NSFontManager sharedFontManager] setSelectedFont:newFont isMultiple:NO];
|
||||
}
|
||||
|
||||
- (void)updateFontPreviews
|
||||
{
|
||||
int selectedRegion = [popupFontRegion indexOfSelectedItem];
|
||||
@ -520,7 +500,7 @@
|
||||
|
||||
NSDictionary *regionDict = [regionMappingTable objectAtIndex:selectedRegion];
|
||||
|
||||
[[matrixChooseFont cellWithTag:0] setAlternateTitle:defaultFontType];
|
||||
[chooseProportionalFontButton setAlternateTitle:defaultFontType];
|
||||
|
||||
// make sure the 'proportional' label matches
|
||||
NSString* propLabelString = [NSString stringWithFormat:[self getLocalizedString:@"ProportionalLableFormat"], [self getLocalizedString:defaultFontType]];
|
||||
@ -555,8 +535,7 @@ const int kDefaultFontSansSerifTag = 1;
|
||||
int itemIndex = 0;
|
||||
NSMutableDictionary *fontSizeDict = [regionDict objectForKey:@"fontsize"];
|
||||
NSNumber* minSize = [fontSizeDict objectForKey:@"minimum"];
|
||||
if (minSize)
|
||||
{
|
||||
if (minSize) {
|
||||
itemIndex = [minFontSizePopup indexOfItemWithTag:[minSize intValue]];
|
||||
if (itemIndex == -1)
|
||||
itemIndex = 0;
|
||||
@ -620,19 +599,16 @@ const int kMissingFontPopupItemTag = 9999;
|
||||
NSFont *foundFont = nil;
|
||||
if (defaultValue)
|
||||
foundFont = [[NSFontManager sharedFontManager] fontWithFamily:defaultValue traits:0 weight:5 size:16.0];
|
||||
else
|
||||
{
|
||||
else {
|
||||
foundFont = [fontType isEqualToString:@"monospace"]
|
||||
? [NSFont userFixedPitchFontOfSize:16.0]
|
||||
: [NSFont userFontOfSize:16.0];
|
||||
defaultValue = [foundFont familyName];
|
||||
}
|
||||
|
||||
if (!foundFont)
|
||||
{
|
||||
if (!foundFont) {
|
||||
NSMenuItem* missingFontItem = [[popupButton menu] itemWithTag:kMissingFontPopupItemTag];
|
||||
if (!missingFontItem)
|
||||
{
|
||||
if (!missingFontItem) {
|
||||
missingFontItem = [[[NSMenuItem alloc] initWithTitle:@"temp" action:NULL keyEquivalent:@""] autorelease];
|
||||
[missingFontItem setTag:kMissingFontPopupItemTag];
|
||||
[[popupButton menu] addItem:missingFontItem];
|
||||
@ -641,9 +617,7 @@ const int kMissingFontPopupItemTag = 9999;
|
||||
NSString* itemTitle = [NSString stringWithFormat:@"%@ %@", defaultValue, [self getLocalizedString:@"Missing"]];
|
||||
[missingFontItem setTitle:itemTitle];
|
||||
[popupButton selectItem:missingFontItem];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// remove the missing item if it exists
|
||||
NSMenuItem* missingFontItem = [[popupButton menu] itemWithTag:kMissingFontPopupItemTag];
|
||||
if (missingFontItem)
|
||||
@ -673,8 +647,7 @@ const int kMissingFontPopupItemTag = 9999;
|
||||
NSArray* fontList = [[NSFontManager sharedFontManager] availableFontFamilies];
|
||||
NSArray* sortedFontList = [fontList sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
|
||||
|
||||
for (unsigned int i = 0; i < [sortedFontList count]; i ++)
|
||||
{
|
||||
for (unsigned int i = 0; i < [sortedFontList count]; i ++) {
|
||||
NSString* fontFamilyName = [sortedFontList objectAtIndex:i];
|
||||
unichar firstChar = [fontFamilyName characterAtIndex:0];
|
||||
|
||||
@ -686,13 +659,11 @@ const int kMissingFontPopupItemTag = 9999;
|
||||
|
||||
#if SUBMENUS_FOR_VARIANTS
|
||||
NSArray* fontFamilyMembers = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamilyName];
|
||||
if ([fontFamilyMembers count] > 1)
|
||||
{
|
||||
if ([fontFamilyMembers count] > 1) {
|
||||
NSMenu* familySubmenu = [[NSMenu alloc] initWithTitle:fontFamilyName];
|
||||
[familySubmenu setAutoenablesItems:NO];
|
||||
|
||||
for (unsigned int j = 0; j < [fontFamilyMembers count]; j ++)
|
||||
{
|
||||
for (unsigned int j = 0; j < [fontFamilyMembers count]; j ++) {
|
||||
NSArray* fontFamilyItems = [fontFamilyMembers objectAtIndex:j];
|
||||
NSString* fontItemName = [fontFamilyItems objectAtIndex:1];
|
||||
|
||||
@ -701,9 +672,7 @@ const int kMissingFontPopupItemTag = 9999;
|
||||
}
|
||||
|
||||
[newItem setSubmenu:familySubmenu];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// use the name from the font family info?
|
||||
}
|
||||
#endif
|
||||
@ -718,13 +687,14 @@ const int kMissingFontPopupItemTag = 9999;
|
||||
|
||||
- (void)changeFont:(id)sender
|
||||
{
|
||||
NSString *fontType = [[matrixChooseFont selectedCell] alternateTitle];
|
||||
if (fontButtonForEditor) {
|
||||
NSString *fontType = [fontButtonForEditor alternateTitle];
|
||||
[self updateFontSampleOfType:fontType];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)fontManager:(id)theFontManager willIncludeFont:(NSString *)fontName
|
||||
{
|
||||
NSLog(@"theFontManager willIncludeFont %@", fontName);
|
||||
// filter out fonts for the selected language
|
||||
return YES;
|
||||
}
|
||||
|
@ -23,8 +23,9 @@
|
||||
advancedFontsDone = id;
|
||||
buttonClicked = id;
|
||||
colorChanged = id;
|
||||
fontChoiceButtonClicked = id;
|
||||
fontRegionPopupClicked = id;
|
||||
monospaceFontChoiceButtonClicked = id;
|
||||
proportionalFontChoiceButtonClicked = id;
|
||||
showAdvancedFontsDialog = id;
|
||||
};
|
||||
CLASS = OrgMozillaChimeraPreferenceAppearance;
|
||||
@ -34,6 +35,8 @@
|
||||
advancedFontsLabel = NSTextField;
|
||||
checkboxUnderlineLinks = NSButton;
|
||||
checkboxUseMyColors = NSButton;
|
||||
chooseMonospaceFontButton = NSButton;
|
||||
chooseProportionalFontButton = NSButton;
|
||||
colorwellBackgroundColor = NSColorWell;
|
||||
colorwellTextColor = NSColorWell;
|
||||
colorwellUnvisitedLinks = NSColorWell;
|
||||
@ -43,7 +46,6 @@
|
||||
fantasyFontPopup = NSPopUpButton;
|
||||
fontSampleMonospace = NSTextField;
|
||||
fontSampleProportional = NSTextField;
|
||||
matrixChooseFont = NSMatrix;
|
||||
minFontSizePopup = NSPopUpButton;
|
||||
popupFontRegion = NSPopUpButton;
|
||||
proportionalSampleLabel = NSTextField;
|
||||
|
@ -3,15 +3,20 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>674 107 458 263 0 0 1600 1002 </string>
|
||||
<string>380 113 458 263 0 0 1280 1002 </string>
|
||||
<key>IBEditorPositions</key>
|
||||
<dict>
|
||||
<key>214</key>
|
||||
<string>70 395 152 96 0 0 1152 746 </string>
|
||||
</dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>286.0</string>
|
||||
<string>364.0</string>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>99</integer>
|
||||
<integer>563</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>6G30</string>
|
||||
<string>7M34</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
Loading…
Reference in New Issue
Block a user