Reputation: 76
I am using Apple's example "Outline View" as a file browser. I have a DataSource & FileSystemItem exactly as Apple has written them. I am unable to click-hold and then drag a filename or folder name. When I click, the selectedRow turns blue. As I hold, nothing happens. If I move as I hold the blue line scrolls through the file list.
I have gone through Apple's "Drag N Drop Outline View" code and it is not what I am looking for. I do not want to reorder the files and drag them from within the OutlineView. I want to drag a filename (ultimately its path) to an NSTextfield. I have not been able to get the NSOutlineView to register drag operations.
I've subclassed NSOutlineView and tried:
- (void)awakeFromNib {
[_outlineView registerForDraggedTypes:[NSArray arrayWithObjects:LOCAL_REORDER_PASTEBOARD_TYPE, NSStringPboardType, NSFilenamesPboardType, nil]];
[_outlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
}
as well as -(NSDragOperation), draggingEntered, -(void)registerForDraggedTypes, etc...
I have no trouble dragging text from an NSScrollView to this NSTextField without any special code. Apparently an NSOutlineView does not inherit the native drag ability of NSScrollView?
So how can I get an NSOutlineView to allow me to drag. Again, Apple's DragNDropOutlineView does way more than I want, doesn't do what I want, and hasn't helped me figure out how to get that drag ability.
Upvotes: 1
Views: 507
Reputation: 990
You can declare your registerForDraggedTypes
like this
[outline_view registerForDraggedTypes:[NSArray arrayWithObjects:LOCAL_REORDER_PASTEBOARD_TYPE,NSColorPboardType,NSDragPboard, nil]];
And You need to implement this method to perform drag operation in NSOutlineView
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard
{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items];
[pasteboard declareTypes:[NSArray arrayWithObject:LOCAL_REORDER_PASTEBOARD_TYPE] owner:self];
[pasteboard setData:data forType:LOCAL_REORDER_PASTEBOARD_TYPE];
return YES;
}
this will allow to drag NSOutlineView
rows..
Upvotes: 1