Disabling Display of JPG and PDF Files in NSTextView
Disabling Display of JPG and PDF Files in NSTextView
- Subject: Disabling Display of JPG and PDF Files in NSTextView
- From: "Kirt Cathey" <email@hidden>
- Date: Tue, 13 Sep 2005 21:24:09 +0000
Hi All.
Have been working on this one, then dropping it, then coming back to it....
kinda like the cat you mistakenly fed once.
I looked through the archives and Googled, which is what has gotten me this
far... it was alot worse!
NSTextView automatically displays JPG and PDF as images, instead of icons,
and while many people would be thrilled with this feature, I don't want it.
A posting from a while back fostered in getting the code this far (this is
raw without any checks or releases):
///////////////// BEGIN CODE SNIPPET ////////////////////////////
NSFileWrapper *theFileWrapper =[[NSFileWrapper alloc]
initWithPath:filePath];
[theFileWrapper setPreferredFilename:attachmentName];
NSTextAttachment *theAttachment = [[NSTextAttachment
alloc]initWithFileWrapper:theFileWrapper];
NSTextAttachmentCell *bCell = [[NSTextAttachmentCell alloc]
initImageCell:[theFileWrapper icon]];
// BEGIN Another attempt at resolving jpg and pdf file attachment!
if ([filePath hasSuffix:@"jpg"] || [filePath hasSuffix:@"pdf"] ||
[filePath hasSuffix:@"jpeg"])
{
[theAttachment setAttachmentCell:bCell];
[bCell setAttachment:theAttachment];
}
// END Another attempt at resolving jpg and pdf file attachment
// RESOLVED. OOPS! Not resolved! Again...
[[attachmentTextView textStorage] appendAttributedString:
[NSAttributedString attributedStringWithAttachment:theAttachment]];
///////////////// END SNIPPET ////////////////////////////
This gets me most of the way there. It shows up in the text view as an
icon,
and I was psyched for about a month. Out bragging with fellow Cocoa
developers
and wearing a crown.... until I reopened one of my saved files, clicked on
one of those
icons to see that after I closed the document and re-opened it, there
seemed to
be no data stored in the attachment.
Here is what I do to try and re-open the attachment:
///////////////// BEGIN CODE SNIPPET ////////////////////////////
- (void)textView:(NSTextView *)textView clickedOnCell:(id
<NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame
atIndex:(unsigned)charIndex
{
NSTextAttachment *myAttachment = [[[NSTextAttachment
alloc]init]autorelease];
myAttachment = [cell attachment];
NSFileWrapper *myFileWrapper = [myAttachment fileWrapper];
NSData *myData = [myFileWrapper regularFileContents];
NSWorkspace *myWorkspace = [NSWorkspace sharedWorkspace];
NSFileManager *projectFile = [NSFileManager defaultManager];
// New way using temporary directory
NSMutableString *myPath = [[[NSMutableString alloc]
initWithString:NSTemporaryDirectory()]autorelease];
[myPath appendString:[myFileWrapper preferredFilename]];
[projectFile createFileAtPath:myPath
contents:myData
attributes:nil];
[myWorkspace openFile:myPath];
}
/////////////////// END SNIPPET /////////////////////////////
Any ideas? This should be much easier! Never had to work so hard to turn
something off.
Regards,
-------------------------
Kirt S. Cathey
http://www.bizolutions.com
-------------------------
_________________________________________________________________
ウィルス駆除も無料の 「MSN Hotmail」 http://www.hotmail.com/
_______________________________________________
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