Re: Bug with -changeAttributes: in NSFontManager/Font Panel?
Re: Bug with -changeAttributes: in NSFontManager/Font Panel?
- Subject: Re: Bug with -changeAttributes: in NSFontManager/Font Panel?
- From: Preston Jackson <email@hidden>
- Date: Tue, 16 Sep 2008 12:46:11 -0600
Graham,
[[NSFontManager sharedFontManager] setTarget:self] only sets the
target to the changeFont: method. Alternatively, you can put
changeFont: in the responder chain it will get called without having
to explicitly set the target of the shared NSFontManager.
The changeAttributes: method is called on the NSTextView (or your
sublcass of it). I believe this message will also be passed up the
responder chain if the NSTextView doesn't consume it.
Preston
http://sidelightblog.blogspot.com
On Sep 15, 2008, at 6:16 PM, Graham Cox wrote:
Anyone?
I notice that this question has been asked numerous times in various
forums across the 'net, with not one answer. So clearly it's an
issue that several people have run into, but met with stony silence.
Apparently the Font Panel UI is quite broken yet very few have ever
noticed! Weird.
I'm going to file a bug report anyway, but I really, really would
like to figure out a workaround!!
Thanks for any help at all,
cheers, Graham
On 13 Sep 2008, at 12:16 pm, Graham Cox wrote:
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?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden