Re: NSFilePromisePboardType
Re: NSFilePromisePboardType
- Subject: Re: NSFilePromisePboardType
- From: Peter Maurer <email@hidden>
- Date: Tue, 21 Dec 2004 14:35:45 +0100
Been away for a few days, sorry for the late reply...
I didn't miss the point, that removes context sensitive information.
What if your OutlineView has several differnt objects in it that need
different accompanying data or come from different data sources. You
can't just add in that extra info since your no longer in the data
source (...)
I do that by asking my outline view's delegate, which happens to be the
data source. (Are there situations were this is not the case?) This way
I can have the delegate choose the necessary pasteboard types by doing
something along these lines...
// -dragImage:at:offset:event:pasteboard:source:slideBack: is an
instance method of my NSOutlineView subclass (it's declared by NSView
-- we'll override it here)
- (void)dragImage: (NSImage*)anImage at: (NSPoint)imageLoc offset:
(NSSize)mouseOffset event: (NSEvent*)theEvent pasteboard:
(NSPasteboard*)pboard source: (id)sourceObject slideBack:
(BOOL)slideBack {
[[self delegate] completeDraggingPasteboard: pboard]; //
delegate==data source
// you can do other stuff here, like creating your own proxy image,
for instance
[super dragImage: anImage at: imageLoc offset: mouseOffset event:
theEvent pasteboard: pboard source: sourceObject slideBack: slideBack];
}
// -completeDraggingPasteboard: is an instance method of my data source
- (void)completeDraggingPasteboard: (NSPasteboard*)pboard {
BOOL aCertainConditionIsMet; // assume this exists
NSString *oneOfMyPasteboardTypes; // assume this exists
NSData *dataForOneOfMyPasteboardTypes; // assume this exists
if (aCertainConditionIsMet) {
[pboard addTypes: [NSArray arrayWithObject: oneOfMyPasteboardTypes]
owner: self];
[pboard setData: dataForOneOfMyPasteboardTypes forType:
oneOfMyPasteboardTypes];
}
}
So when you get a FilePromisePboard
with .htm how exactly do you plan on figuring out which website that
came from?
I would tend to ask my data source, which --as mentioned above-- is the
same as the NSOutlineView's delegate.
How about interapplication data? What if I wanted to add
teh original item ontu my pasteboard? How do I know which of the many
.foo items in my outline view corresponds to the item on the
pasteboard?
Just have your data source remember the items you are dragging. Example:
static NSArray *draggedItems = nil;
- (BOOL)outlineView: (NSOutlineView*)outlineView writeItems:
(NSArray*)items toPasteboard: (NSPasteboard*)pboard {
NSString *oneOfMyFileExtensions; // assume this exists
[draggedItems release];
draggedItems = [items retain];
[outlineView dragPromisedFilesOfTypes: [NSArray arrayWithObject:
oneOfMyFileExtensions] fromRect: [outlineView frameOfCellAtColumn: 0
row: [outlineView rowForItem: [items objectAtIndex: 0]]] source:
outlineView slideBack: YES event: [NSApp currentEvent]];
// we may have to post a mouseUp event here, see below...
return NO;
}
That's not very elegant, but it should work. And I would still
recommend taking over the mouseDown/mouseDragged mechanism completely
instead of "hijacking" -outlineView:writeItems:toPasteboard:.
Perhaps it's you who didn't think before he responded...
I never said you didn't think before you posted your reply. I was just
trying to say that the documentation's directions are different from
what you recommend. And doing things the documented way is easier and
safer in most of the cases.
Your way isn't more official unless you write a custom view that only
sends out file promises or for which your outline view has very few
items such that you can easily discern which original item the
filetype came from...
See above. You can always store the items you're currently dragging.
Add to that the
fact you need to cancel the initial drag that started in the first
place.
Right. As I've said before, you can either take over the
mouseDown/mouseDragged mechanism completely, or you can manually post a
mouseUp event -- that's what I do, but I'm not very proud of it ;-)
So again, I ask you, what about this method is more better? It's less
flexible and requires that I dimiss an in progress drag to start
another more limited one.
There's one crucial advantage, IMHO: I don't have to declare
undocumented CorePasteboardFlavorType pasteboard types that might break
my app with any future system update.
Peter.
On Fri, 17 Dec 2004 10:23:47 +0100, Peter Maurer <email@hidden>
wrote:
Why don't you simply use [NSOutlineView dragPromisedFilesOfTypes:
...]
What event are you sending with that?
I'm sending [NSApp currentEvent]. But you could also explicitly store
the latest mouseDown event in your table-/outlineView subclass and use
that.
Plus the docs read that it needs
to be invoked from the mouseDown: method since that has an event to
attach it to.
Well, you can invoke it from your table-/outlineView's
-writeItems:toPasteboard: method (cf.
<http://cocoa.mamasam.com/COCOADEV/2003/03/2/59748.php>). Or you can
take over your outline view's mouseDown/mouseDragged mechanism
completely.
Even if that wasn't the case, the entire point is that
you can't put extra data on the pboard with that method. with mine
all
the data you want arrives intact then you attach the file promise
stuff. Though I don't use any extra types you can easily enough
change the code to support them.
You seem to have missed the following statement from my previous
e-mail...
(...) and override your outline view's
-dragImage:at:offset:event:pasteboard:source:slideBack: method to
add
any additional pasteboard type you might want to use?
Just send [pasteboard addTypes:owner:] from within your subclass's
[self dragImage:at:offset:event:pasteboard:source:slideBack:] to add
any additional types of pasteboard.
<http://developer.apple.com/documentation/Cocoa/Conceptual/
DragandDrop/
Tasks/faq.html#//apple_ref/doc/uid/20002248/BBCFIJGF>
Sometimes reading the manual is indeed worth while... ;-D
Peter.
_______________________________________________
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