• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextAttachment behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSTextAttachment behavior
      • From: Douglas Davidson <email@hidden>
References: 
 >NSTextAttachment behavior (From: Gwynne <email@hidden>)
 >Re: NSTextAttachment behavior (From: Frank Midgley <email@hidden>)
 >Re: NSTextAttachment behavior (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: menuItem connection to other nib
  • Next by Date: Re: NSTextAttachment behavior
  • Previous by thread: Re: NSTextAttachment behavior
  • Next by thread: Re: NSTextAttachment behavior
  • Index(es):
    • Date
    • Thread