1
votes

I have a series of items that I am showing them in a NSCollectionView. The selection and multiple selection are both enabled.

The user can select items by dragging (i.e. marking items by drag). however this works when the user start dragging from collection view background or the space between items (and not on the items) but I want make it possible when dragging starts on the items too.

I want something like this photo if we consider text and image as a single item.

enter image description here

image source: http://osxdaily.com/2013/09/16/select-multiple-files-mac-os-x/

Thank you in advance.

1
What have you done so far?Willeke
The point is until this state most of the work is done through IB, and Datasource is just showing the items. What I want to achieve here is an extra feature which is not implemented by default in NSCollectionView.Alan
What did you do to implement drag & drop? Show us your code.Willeke
it's not drag and drop, it's drag selecting like finder app that you mark items, but I want to make it work when the user start the drag on items. It has to do with events but I can't figure it out how.Alan

1 Answers

3
votes

Implement hitTest(_:) in the class of the item view to make the items "see through" for clicks. Return the collection view instead of the item view when the user clicks in the item view.

override func hitTest(_ point: NSPoint) -> NSView? {
    var view = super.hitTest(point)
    if view == self {
        repeat {
            view = view!.superview
        } while view != nil && !(view is NSCollectionView)
    }
    return view;
}