I did it with steps below: when header view (as it's NSView, it gets mouseDown/mouseDragged) gets information about being clicked, I am passing its IndexPath to collection view (as multiple sections can be dragged in the same time)
when header view gets mouseDragged it calls a method in collectionView, which creates NSDraggingItems from given indexPaths (I have to solve additionally how to remove visible collectionview's background from image as section's decoration view has rounded corners) and calls beginDraggingSession(),
in draggingUpdated I calculate drop index path (it's easy, as You said, I am comparing minX...maxX to cursor's point)
and finally in draggingEnded I use delegate method to execute operations on collectionView and data behind it.
I have to improve a few parts of it (like draggingImage not going back to its position when dragging ends successfully or to hide dragged section), but overall I am satisfied with results.
Thank You for the help!
Post
Replies
Boosts
Views
Activity
I have wrongly asked the question (or not precisely). You have awesomely explained what I have to do to make collection view both sections and items droppable on it, but I don't know how to make section header draggable and that's why I was speaking about NSDraggingSource, as documentation says it contains a methods that I need to make item draggable (I can take it up and move, then the NSDraggingDestination will handle dropping). And here is my problem - I have to override collectionView's NSDragSource or implement conformity to that for my header view (which is a NSView)? When I am pressing the header view, nothing happens. Only when I was overriding mouseDown(sender:) and mouseDragged(sender:) I was able to read these gestures executed on headers.
Just to be sure:
I have to differentiate type of dragging data (section vs item) in collection view's subclass methods related with NSDraggingDestination? Also I can do that with type identifiers, so it won't be a problem.
As I saw the Drag and Drop Programming Guide, I need to override mouseDragged(:) or mouseDown(:) events to make that header view draggable. Did you do that in Your project?
Regarding my last question about decoration views - the problem lies in implementation of the decoration views, layout won't let me access these views when I will want to build NSImageRep for my section, because there isn't any method to acquire them. Only one type of views that I can get (as NSViews) are supplementary views (not counting here NSCollectionViewItem). I am thinking here about reimplementing decorations as supplementary views.
Do You have some part of Your implementation shared somewhere? I would love to see it, as it may greatly reduce my implementation time.
I am sorry for keep asking questions, but knowing these details will make me sure how it has to work and how I should divide code. It's my really first time going that deep into AppKit.
Thanks! I have a few questions: Should header view also conform to NSDraggingDestination? Right now I can't even drag it (it would be the view that decides if I want to move section, not the items inside section, as they're also draggable). Registering draggedType (its my own type) makes only items draggable.
Did the calculations that require from code to recognise type of dragging item and its dropIndexPath impact the performance?
Do You use NSCollectionViewDelegate methods alongside that custom NSDragDestination implementation?
Do You use decoration views (section background view)? I am using them and as I see, they're static views that I can't manage.