views:

1094

answers:

2

I have an NSTableView and an NSOutlineView, both with their content provided by bindings, that I'd like to have some drag-and-drop functionality:

  • Drag rows from Table A onto a row of Outline B, where they will be copied into a data structure which the row in Outline B represents.

  • Drag a row from Outline B onto another row in Outline B, which will copy the data represented by the first row into the data represented in the second row.

I've read Apple's drag-and-drop documentation and gotten just about nowhere. It doesn't really seem to apply to what I need to do. What am I missing?

+1  A: 

The page you linked to is pretty clear about what you need to do. In table A's data source, implement registerForDraggedTypes: and tableView:writeRowsWithIndexes:toPasteboard: to put some private TableAPasteboardType data on the pasteboard.

In outline B's data source, implement the same two methods and put some private OutlineBPasteboardType data on the pasteboard.

Finally, implement tableView:validateDrop:proposedRow:proposedDropOperation: and tableView:acceptDrop:row:dropOperation: to check the pasteboard for either TableAPasteboardType or OutlineBPasteboardType and make the appropriate changes to your bound model, depending.

It's pretty straightforward once you just plow in and do it.

Jim Puls
+3  A: 

You need a data source—AFAIK, you can't make this happen with Bindings alone.

The unfinished Adium Xtras Creator, which is under the BSD license, includes an array controller that you can set as the data source to get drag-and-drop in a Bindings-powered table view.

This requirement may not apply to NSOutlineView and NSTreeController. I haven't tried that.

Peter Hosey