Re: Correct way to insert an image into NSTextView.
Re: Correct way to insert an image into NSTextView.
- Subject: Re: Correct way to insert an image into NSTextView.
- From: Gus Mueller <email@hidden>
- Date: Sat, 7 Feb 2004 10:36:55 -0800
I'm going to go ahead and answer my own question, in case anyone else
comes across this problem in the future (or anyone says, no.. that's not
the right way..):
NSString *path = @"path/to/file.pdf";
NSFileWrapper *filew = [[[NSFileWrapper alloc]
initRegularFileWithContents:[NSData dataWithContentsOfFile:path]]
autorelease];
[filew setPreferredFilename:[path lastPathComponent]];
NSTextAttachment *fileAttatchment =
[[[NSTextAttachment alloc] initWithFileWrapper:filew] autorelease];
NSAttributedString *fileAttString =
[NSAttributedString attributedStringWithAttachment:fileAttatchment];
[textView insertText:fileAttString];
thanks,
-gus
Gus Mueller (email@hidden) wrote:
>
I've got a program where I'm inserting an image from the filesystem into
>
a NSTextView. However, after the image is inserted, the file is still
>
held onto (by the textview I think). So if a user tries to delete the
>
file via the trash, they will get a message saying it's still in use.
>
>
Here's the snippet of code I'm using:
>
>
NSFileWrapper *filew = [[[NSFileWrapper alloc]
>
initWithPath:@"path/to/file.pdf"] autorelease];
>
NSTextAttachment *fileAttatchment = [[[NSTextAttachment alloc]
>
initWithFileWrapper:filew] autorelease];
>
NSAttributedString *fileAttString = [NSAttributedString
>
attributedStringWithAttachment:fileAttatchment];
>
[textView insertText:fileAttString];
>
>
Is there another way I should be doing this?
>
>
thanks,
>
>
-gus
>
>
--
>
August 'Gus' Mueller
>
Flying Meat Inc.
>
http://flyingmeat.com/
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
-gus
--
August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.