Why isn't changeFont: being called from my NSFontPanel?
Asked Answered
A

1

4

I'm creating an NSFontPanel but selecting a font doesn't call the changeFont: method.

I have these methods defined in an NSWindowController subclass:

- (IBAction)showFontPanel:(id)sender {
    [[NSFontPanel sharedFontPanel] makeKeyAndOrderFront:self];
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSFont *theFont = [NSFont fontWithName:[prefs stringForKey:iepFontName] size:[prefs floatForKey:iepFontSize]];
    [[NSFontPanel sharedFontPanel] setPanelFont:theFont isMultiple:NO];

    [[NSFontManager sharedFontManager] setDelegate:self];
}

- (void)changeFont:(id)sender {
    NSLog(@"changeFont");
}

- (NSUInteger)validModesForFontPanel:(NSFontPanel *)fontPanel {
    return NSFontPanelFaceModeMask |  NSFontPanelSizeModeMask | NSFontPanelCollectionModeMask;
}

The font panel appears with the correct font and size selected and only the modes enabled in validModesForFontPanel:, but when I select a different font, the changeFont: method doesn't get called. My understanding is that the changeFont: action message gets sent up the responder chain. As a test, I put an identical changeFont: method in my application delegate (which is supposed to be in the responder chain) but it isn't getting called either. Am I missing a step somewhere?

Arwood answered 27/5, 2011 at 2:41 Comment(0)
A
3

I found an answer (http://www.cocoabuilder.com/archive/cocoa/108016-nsfontpanel-act-on-it-own-accessory-view.html#108136). I added this line:

[[NSFontManager sharedFontManager] setAction:@selector(changeDefaultFont:)];

and made the corresponding change to the method name in my NSWindowController subclass. Now when I select a different font in the font panel, changeDefaultFont: gets called.

Arwood answered 27/5, 2011 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.