Re: NSTextAttachment behavior
Re: NSTextAttachment behavior
- Subject: Re: NSTextAttachment behavior
- From: Gwynne <email@hidden>
- Date: Fri, 14 Jan 2005 16:27:40 -0500
On Jan 14, 2005, at 1:09 PM, Douglas Davidson wrote:
First get the icon for the file from NSWorkspace. Then create an
NSTextAttachment, get its cell and call -setImage: on it with the
file's icon.
It's probably better to create a new cell yourself rather than letting
NSTextAttachment create one automatically and then trying to modify
it. First, it avoids the expense of having NSTextAttachment examine
the file contents and create an image or other resource from them,
just to discard it. Second, there's no telling what kind of NSCell
subclass NSTextAttachment will use; it depends entirely on what
NSTextAttachment thinks your file contains. If you create your own
cell, you can just make it an NSTextAttachmentCell and you'll be fine.
My solution is this:
// Yes, I should get the image into a separate var and then set it.
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
[[a attachmentCell] setImage:[[NSWorkspace sharedWorkspace]
iconForFile:path]];
[[[a attachmentCell] image] setSize:NSMakeSize( 16, 16 )]; // get the
small icon
This seems to work well, as long as I plug the resultant
NSAttributedString into an NSTextView. NSTextField doesn't do the job.
-- Gwynne, key to the Code
Email: email@hidden
Website: http://musicimage.plasticchicken.com/
"This whole world is an asylum for the incurable."
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden