Spring 加载 NSOutlineView 叶行

Spring load NSOutlineView leaf rows

我已经子类化了 NSOutlineView 并实现了 NSSpringLoadingDestination,但是 springLoadingActivated() 只在非叶行上调用过,即使我已经实现了 springLoadingEntered() 并且springLoadingUpdated() 到 return [.enabled] 不分青红皂白。我假设 NSOutlineView 的内置拖放支持干扰了我的尝试。有解决办法吗?

感觉有点老套,但似乎我可以通过 spring 加载行来解决这个问题,而且还覆盖所有 NSDraggingDestination 方法以将单词传递给父级 NSOutlineView:

class SpringLoadedOutlineRow: NSTableCellView, NSSpringLoadingDestination {
    var outlineView: NSOutlineView! {
        didSet {
            registerForDraggedTypes(outlineView.registeredDraggedTypes)
        }
    }

    //Pass through `NSDraggingDestination` methods so we don't interfere with `NSOutlineView`
    override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
        return outlineView.draggingEntered(sender)
    }
    override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool {
        return outlineView.prepareForDragOperation(sender)
    }
    override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
        return outlineView.performDragOperation(sender)
    }
    override func concludeDragOperation(_ sender: NSDraggingInfo?) {
        outlineView.concludeDragOperation(sender)
    }
    override func draggingExited(_ sender: NSDraggingInfo?) {
        outlineView.draggingExited(sender)
    }

    //Only pass through if we're expandable & not yet expanded (to get `NSOutlineView`'s default disclosure spring-loading); otherwise it will eat our leaf spring-loading
    override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation {
        guard let representedItem = outlineView.item(atRow: outlineView.row(for: self)) else { return outlineView.draggingUpdated(sender) }
        if outlineView.isExpandable(representedItem) && !outlineView.isItemExpanded(representedItem) {
            return outlineView.draggingUpdated(sender)
        } else {
            return []
        }
    }

    //Actually spring-load!
    func springLoadingActivated(_ activated: Bool, draggingInfo: NSDraggingInfo) {
        //Whatever you want
    }

    func springLoadingHighlightChanged(_ draggingInfo: NSDraggingInfo) {

    }

    func springLoadingEntered(_ draggingInfo: NSDraggingInfo) -> NSSpringLoadingOptions {
        return [.enabled]
    }

    func springLoadingUpdated(_ draggingInfo: NSDraggingInfo) -> NSSpringLoadingOptions {
        return [.enabled]
    }
}