Re: Quickest Way to Open an NSTextAttachment in NSTextView
Re: Quickest Way to Open an NSTextAttachment in NSTextView
- Subject: Re: Quickest Way to Open an NSTextAttachment in NSTextView
- From: "Kirt Cathey" <email@hidden>
- Date: Sat, 05 Mar 2005 09:55:42 +0000
Thanks. This is the constructive criticism I was looking for. All beginner
mistakes, but the end result is better code. Here is updated code.
But, getting back to the question of booting a file w/o having to write it
to the hard disk first........
- (void)textView:(NSTextView *)textView clickedOnCell:(id
<NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame
atIndex:(unsigned)charIndex
{
// NSTextAttachment *myAttachment = [[[NSTextAttachment alloc] init]
autorelease];
NSTextAttachment *myAttachment = [cell attachment];
NSFileWrapper *myFileWrapper = [myAttachment fileWrapper];
NSData *myData = [myFileWrapper regularFileContents];
NSWorkspace *myWorkspace = [NSWorkspace sharedWorkspace];
NSFileManager *projectFile = [NSFileManager defaultManager];
NSMutableString *myPath = [[NSMutableString alloc]
initWithString:NSHomeDirectory()];
[myPath appendString:@"/WPData/temp/"];
[myPath appendString:[myFileWrapper preferredFilename]];
[projectFile createFileAtPath:myPath
contents:myData
attributes:nil];
[myWorkspace openFile:myPath];
[myPath release];
[myAttachment release];
}
From the desk of ..........
Barking Frog
email: email@hidden
From: Matt Neuburg <email@hidden>
To: Kirt Cathey <email@hidden>
CC: <email@hidden>
Subject: Re: Quickest Way to Open an NSTextAttachment in NSTextView
Date: Wed, 02 Mar 2005 08:07:15 -0800
On Wed, 02 Mar 2005 06:51:50 +0000, "Kirt Cathey"
<email@hidden> said:
> NSTextAttachment *myAttachment = [[[NSTextAttachment alloc] init]
>autorelease];
> myAttachment = [cell attachment];
That makes no sense. In the first line you create a blank
NSTextAttachment;
in the second line you throw it away. So why bother?
> NSWorkspace *myWorkspace = [[NSWorkspace alloc]init];
That is not how you work with the workspace. There is already a singleton
workspace; use the appropriate class method to access it. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>
_________________________________________________________________
楽しい絵文字でココロ伝わるメッセンジャー http://messenger.msn.co.jp/
_______________________________________________
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