Re: NSTreeController drag and drop woes
Re: NSTreeController drag and drop woes
- Subject: Re: NSTreeController drag and drop woes
- From: Keith Blount <email@hidden>
- Date: Tue, 26 Jul 2005 08:50:09 -0700 (PDT)
Hmm, it seems I spoke too soon when I said that I had
got drag and drop working by modifying the underlying
arrays directly - in fact there are still a few
oddities.
I think the best way around this would be to use the
tree controller methods directly, but I am having some
very bizarre results with this. For instance, in my
-outlineView:acceptDrop:item:childIndex:, I do this to
get the index path at which I will need to insert my
dropped items:
NSIndexPath *indexPath;
if (targetItem)
{
[outlineView selectRowIndexes:[NSIndexSet
indexSetWithIndex:[outlineView rowForItem:targetItem]]
byExtendingSelection:NO];
indexPath = [[treeController selectionIndexPath]
indexPathByAddingIndex:index];
}
else
{
// This is very odd!
indexPath = [NSIndexPath indexPathWithIndex:index];
}
This *should* get the index path at which I want to
drop the items provided by the drag. It works fine if
targetItem is non-nil - ie. when we are not dropping
on the root. When dropping on the root, though, the
results are odd. The index path above is created
correctly. Suppose I want to drop at the very top of
the outline view so that the index passed in is 0, the
above code will create an index path with just a 0 in
it. But then, when I call:
[treeController insertObject:draggedItem
atArrangedObjectIndexPath:indexPath];
no matter what, when dragging on the root the item
just gets added to the bottom of the outline view. (My
root is just an NSMutableArray, but I've tried
changing it to be of the same type as all my nodes and
it makes no difference.) Like I say, when not dropping
on the root, this works fine.
I cannot see what I am doing wrong here. Does anyone
have any ideas?
Thanks in advance,
Keith
--- Original message ---
Hello,
I am just wondering if anyone has had any success
implementing drag and drop with NSTreeController. I
have got it working fine for my app, but I want to
check that the way I am doing it is okay. It is the
-outlineView:acceptDrop:item:childIndexes: method that
I am unsure about. It seems to me that I should be
using NSTreeController's
-insertObject:atArrangedIndexPath: and
-removeObjectAtArrangedIndexPath: methods to complete
my drop, but I have had less-than-reliable results
with these. For a start, I have found that
-insertObject:atArrangedIndexPath: behaves erratically
when dropping on the root (ie. when the targetItem
passed in is NULL). It also seems impossible to use
-removeObjectAtArrangedIndexPath: to remove objects
that have been dragged (when the source and
destination are the same), because we need the index
paths of all of the dragged items. This is complicated
because: 1) These index paths may have changed after
inserting the dropped items; 2) NSTreeController only
provides methods for getting the index paths of
selected objects - I can't see any way to calculate
the index paths from an array of dragged items.
The only solution I have come up with is to manipulate
the content arrays directly, without using any of
NSTreeController's methods, and then ensuring that the
outline view remains up to date using
-reloadItem:reloadChildren: and -reloadData (if I
don't do this every time I add a new item, I get some
very screwy results, which is only a problem when
using NSTreeController).
Like I say, I have drag and drop working, but I feel
that I may be doing it the wrong way because I am not
using my tree controller to manage the drop. If anyone
has any examples of an
-outlineView:acceptDrop:item:childIndexes: method that
does this in a better way (using NSTreeController
methods), or any comments in general about this
process, I would be very grateful.
Many thanks,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.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