Re: TextEdit features in my Cocoa app
Re: TextEdit features in my Cocoa app
- Subject: Re: TextEdit features in my Cocoa app
- From: Chris Heimark <email@hidden>
- Date: Fri, 19 Oct 2007 10:24:51 -0400
Finally got around to implementing advice in this thread. Namely, I
added two drag delegate methods per the TextEdit sample code, per
below. The sample code runs as expected.
Same code in my application animates but refuses to light up the +
sign, indicating willingness to drop unto Finder, though it will
light a + sign over editor window of XCode (drop leaves no traces
that drop happened). I can open the very same underlying rtfd file
(used in my application) in TextEdit.app and it allows me to drag/
drop any cell element just about anywhere. Visually, my NSTextView
and TextEdit views look identical with same underlying RTFD.
Is there some magical setting I am not making to my NSTextView object
that I am missing? I have noticed one peculiar thing, which I don't
know if it is related, but I noticed writablePasteboardTypesForCell
is called twice, with same parameters, at the beginning of the drag.
Is this a hint to me?
Puzzled, once again...
- (NSArray *)textView:(NSTextView *)aTextView
writablePasteboardTypesForCell:(id <NSTextAttachmentCell>)cell
atIndex:(unsigned)charIndex
{
NSArray *types = nil;
NSString *name = [[[cell attachment] fileWrapper] filename];
if (name && ![name isEqualToString:@""])
{
types = [NSArray arrayWithObject:NSFilenamesPboardType];
}
return types;
}
- (BOOL)textView:(NSTextView *)aTextView writeCell:(id
<NSTextAttachmentCell>)cell atIndex:(unsigned)charIndex toPasteboard:
(NSPasteboard *)pboard type:(NSString *)type
{
BOOL success = NO;
NSString *name = [[[cell attachment] fileWrapper] filename];
if (name && ![name isEqualToString:@""] && [type
isEqualToString:NSFilenamesPboardType])
{
NSString *fullPath = [[NSString stringWithFormat:kCHRTFDirectory,
tempDir] stringByAppendingPathComponent:name];
success = [pboard setPropertyList:[NSArray
arrayWithObject:fullPath] forType:NSFilenamesPboardType];
}
return success;
}
On Sep 17, 2007, at 8:40 PM, Douglas Davidson wrote:
On Sep 17, 2007, at 5:34 PM, Chris Heimark wrote:
Douglas, what do you mean by: "Probably the main problem is that
you need to have a file in the filesystem in order to use
NSFilenamesPboardType." ?
What I mean is that an attachment in the text system ordinarily has
an in-memory copy of the file contents. If you wish to use
NSFilenamesPboardType on the pasteboard in order to copy this to
Finder, you will need to have an on-disk representation. For
example, TextEdit's dragging of attachments in this way works if
the attachment has been saved in an RTFD, but not if it has not
been saved.
Douglas Davidson
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden