I'm using the Font Panel via NSFont Manager to change text attributes through a modal panel (in fact a sheet).

I can change the font OK, as using -setTarget: I can set the target of the font manager to my modal panel. However, I never get the call to - changeAttributes:, so all the stuff such as colour and shadow that the Font Panel has doesn't function.

Is this a bug, or am I doing something wrong? If it is a bug, can anyone suggest a workaround?

My code is pretty simple:

When my modal sheet is initialized, I set up the font manager thusly:

// establish the connection to the font panel and update it to match the current font/text attributes
        
NSDictionary* textAttributes = [settings objectForKey:kDKOMapGridHorizontalAnnotationTextAttributes];
        NSFont*         font = [textAttributes 
objectForKey:NSFontAttributeName];
        
        [[NSFontManager sharedFontManager] setTarget:self];
[[NSFontManager sharedFontManager] setSelectedAttributes:textAttributes isMultiple:NO];
        [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];

(where 'settings' is a dictionary of a whole raft of things, including the text attributes of the text I want to change via the font panel)

and my -changeFont: and -changeAttributes: methods look like:

- (IBAction)            changeFont:(id) sender
{
        // received changeFont message from font panel

        NSFont* newFont, *oldFont;
NSMutableDictionary* textAttributes = [[mSettings objectForKey:kDKOMapGridHorizontalAnnotationTextAttributes] mutableCopy];
        
        oldFont = [textAttributes objectForKey:NSFontAttributeName];
        newFont = [sender convertFont:oldFont];
        
        [textAttributes setObject:newFont forKey:NSFontAttributeName];
        
[mSettings setObject:textAttributes forKey:kDKOMapGridHorizontalAnnotationTextAttributes]; [mSettings setObject:textAttributes forKey:kDKOMapGridVerticalAnnotationTextAttributes];
        
        [textAttributes release];
        [self conditionallyPreview];
}


- (IBAction)            changeAttributes:(id) sender
{
        NSLog(@"received -changeAttributes: from <%@>", sender );       
        
NSDictionary* textAttributes = [mSettings objectForKey:kDKOMapGridHorizontalAnnotationTextAttributes]; NSDictionary* newAttributes = [sender convertAttributes:textAttributes];
        
[mSettings setObject:newAttributes forKey:kDKOMapGridHorizontalAnnotationTextAttributes]; [mSettings setObject:newAttributes forKey:kDKOMapGridVerticalAnnotationTextAttributes];
        [self conditionallyPreview];
}


The call to changeAttributes is never logged.

It seems as if [NSFontManager setTarget] applies only to the changeFont: message and not to changeAttributes:. This appears to be a bug, but there may be some good reason for it. Workaround?

tia,


Graham

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to