【问题标题】:Spring load NSOutlineView leaf rows弹簧加载 NSOutlineView 叶行
【发布时间】:2018-01-14 23:57:18
【问题描述】:

我已经继承了NSOutlineView 并实现了NSSpringLoadingDestination,但springLoadingActivated() 只在非叶子行上被调用,即使我已经实现了springLoadingEntered()springLoadingUpdated() 以不加选择地返回[.enabled]。我假设NSOutlineView 的内置拖放支持干扰了我的尝试。有解决办法吗?

【问题讨论】:

  • NSOutlineView spring load expanded item 的副本。你需要拖放吗?
  • Springload 行而不是大纲视图?
  • 我确实需要拖放,当我加载行时,它们会从大纲视图中劫持拖放消息。

标签: swift cocoa drag-and-drop nsoutlineview


【解决方案1】:

感觉有点 hacky,但似乎我可以通过弹簧加载行来解决这个问题,但也可以覆盖所有 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]
    }
}

【讨论】:

    猜你喜欢
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2018-05-06
    • 2020-01-10
    • 2018-03-04
    相关资源
    最近更新 更多