Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop on NSTableView Behavior

I have an NSTableView and I have successfully implemented both tableView:validateDrop:proposedRow:proposedDropOperation: and tableView:acceptDrop:row:dropOperation:.

I don't need tableView:writeRowsWithIndexes:toPasteboard: because that's for dragging objects out of the NSTableView.

Now, the problem is that I want it to behave kind of iTunes-like. In iTunes 9.x (I don't remember it for the previous versions) you have an NSTableView (the playlist) and when you drag a file over it you get this blue focus inside the NSTableView (maybe it's the NSScrollView?) and you don't have the blue horizontal line that indicates where you're going to insert an object. So basically I would like:

  • No blue horizontal insert line between rows when hovering a file over the NSTableView.

  • The blue focus inside the NSTableView (or NSScrollView).

Any help would be greatly appreciated so thank you in advance.

like image 781
Jef Avatar asked Feb 06 '10 11:02

Jef


People also ask

How do you use drag and drop in NSTableView?

When a drag starts, you write to the pasteboard. When a drag ends, you can read data from the pasteboard. NSTableView and NSOutlineView have delegate methods that make it (relatively) easy to deal with drag and drop for their rows.

How to support reordering of rows in a NSTableView?

To support reordering of rows in a NSTableView, you need to understand how a table works with drag and drop operation. In a drag and drop operation, there is a source and a destination. They can be the same table view, or can be different views (any kind of view)!

How do I customize a table view without subclassing NSTableView?

To learn about the methods that an NSTableView object uses to provide and access the contents of its data source object, see NSTableViewDataSource. To customize a table view’s behavior without subclassing NSTableView, use the methods defined by the NSTableViewDelegate protocol.

What is a nstableviewdelegate?

For example, the delegate supports table column management, type-to-select functionality, row selection and editing, custom tracking, and custom views for individual columns and rows. To learn more about the table view delegate, see NSTableViewDelegate.


1 Answers

From the NSTableView reference:

- (void)setDropRow:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation

....

"Passing a value of –1 for row, and NSTableViewDropOn as the operation causes the entire table view to be highlighted rather than a specific row. This is useful if the data displayed by the receiver does not allow the user to drop items at a specific row location"

like image 97
Erik Elmgren Avatar answered Oct 11 '22 23:10

Erik Elmgren