Re: mysterious NSOutlineView crashing
Re: mysterious NSOutlineView crashing
- Subject: Re: mysterious NSOutlineView crashing
- From: Alex Rice <email@hidden>
- Date: Wed, 19 Feb 2003 00:06:45 -0700
On Tuesday, February 18, 2003, at 01:52 PM, Generic User wrote:
hmmm, never thought to do that. do you write the dragged item
pointer to an instance variable in writeItems:, then just manipulate
it in acceptDrop: ?
Yep, I just have a normal accessor for the draggedItems. This idea I
actually kind of got from the Developer/Examples/DragNDropOutlineView,
which doesn't use the NSPasteboard NSData at all! Kinda weird.
Here is what I'm doing
- (BOOL)outlineView:(NSOutlineView *)ov
writeItems:(NSArray*)items
toPasteboard:(NSPasteboard*)pboard
{
NSData *data = [NSArchiver archivedDataWithRootObject: items];
[pboard declareTypes:[NSArray arrayWithObjects: OV_DRAG_TYPE, nil]
owner:self];
[pboard setData: data forType: OV_DRAG_TYPE];
[self setDraggedItems: items];
return YES;
}
-(NSArray *) draggedItems
{
return _draggedItems;
}
-(void) setDraggedItems: (NSArray *) items
{
if(_draggedItems != items)
{
[_draggedItems release];
_draggedItems = [items retain];
}
}
In acceptDrop I do
// drag from another document
if(([pboard availableTypeFromArray: [NSArray arrayWithObject:
OV_DRAG_TYPE]] != nil) &&
([info draggingSource] != outlineView))
{
NSData *data = [pboard dataForType: OV_DRAG_TYPE];
NSArray *draggedItems; = [NSUnarchiver unarchiveObjectWithData:
data];
// insert the items
// ...
[outlineView MLselectItems: draggedItems];
}
// drag from this document
if(([pboard availableTypeFromArray: [NSArray arrayWithObject:
OV_DRAG_TYPE]] != nil) &&
([info draggingSource] == outlineView))
{
NSArray *draggedItems; = [self draggedItems];
// move the items
// ...
[outlineView MLselectItems: draggedItems];
}
I'm not sure what happens to the pasteboard copy then.
I'm ignoring it, unless the dragSource is another NSDocument.
assuming each item in the OV is a NSD and that the NSDs are in an
NSArray and the children of each NSD are in an NSArray within the
NSD...follow so far..
Then you would have to be putting the object into some array at some
index and then removing the old one. Make sure you are removing by
index rather than removeObject: because they are the same and it
will remove the first one it comes to I think, which may not be the
one you want removed
I'm pretty sure my data source is OK after the drop is finished.
Nothing else indicates anything is wrong with my data source. I'm
probably wrong, tho. NSOutlineView seems to think my data source is
bogus somehow. I have a hunch it's because I'm not using a custom
TreeNode class, instead I'm just using NSMutableDictionary tree nodes.
Probably having to do with NSDictionary hashes, and isEqual: vs
isDictionaryEqual:. Just guessing tho.
do you mean selecting with the mouse?
is it the intra drag that is crashing? i'm getting confused
No, what is crashing is the programmatic re-selecting of the items
after the drop is finished. (MLselectItems:) If I remove this
operation then everything is perfectly stable.
This extension on NSOutlineView is adapted from DragNDropOutlineView:
@implementation NSOutlineView (MLExtensions)
- (void) MLselectItems:(NSArray*)items
{
int i;
[self deselectAll: nil];
for (i=0;i<[items count];i++) {
int row = [self rowForItem:[items objectAtIndex:i]];
if(row>=0) [self selectRow: row byExtendingSelection: YES];
}
}
@end
This problem exists no matter whether I use the local accessor, or the
pasteboard data. Although interestingly it does not occur if the nodes
are dragged from another NSDocument.
Alex Rice <email@hidden> | Mindlube Software |
http://mindlube.com
what a waste of thumbs that are opposable
to make machines that are disposable -Ani DiFranco
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.