|
| 1 | +// |
| 2 | +// CellOutlineVItem.swift |
| 3 | +// |
| 4 | +// |
| 5 | +// Created by Florian Zand on 20.01.25. |
| 6 | +// |
| 7 | + |
| 8 | +/* |
| 9 | +import AppKit |
| 10 | + |
| 11 | +/// A outline view item that creates it's cell view. |
| 12 | +public protocol CellOutlineItem: Hashable { |
| 13 | + /// Returns the cell view for the item. |
| 14 | + func cellView(_ outlineView: NSOutlineView, column: NSTableColumn, row: Int) -> NSView |
| 15 | + |
| 16 | + /** |
| 17 | + A Boolean value indicating whether the item can be expanded / collapsed by the user. |
| 18 | + |
| 19 | + The default value is `true`. |
| 20 | + */ |
| 21 | + var isExpandable: Bool { get } |
| 22 | + |
| 23 | + /** |
| 24 | + A Boolean value indicating whether the item can be selected. |
| 25 | + |
| 26 | + The default value is `true`. |
| 27 | + */ |
| 28 | + var isSelectable: Bool { get } |
| 29 | + |
| 30 | + /** |
| 31 | + A Boolean value indicating whether the item can be deleted by the user pressing `Backspace`. |
| 32 | + |
| 33 | + The default value is `false`. |
| 34 | + */ |
| 35 | + var isDeletable: Bool { get } |
| 36 | + |
| 37 | + /** |
| 38 | + A Boolean value indicating whether the item can be reorded. |
| 39 | + |
| 40 | + The default value is `false`. |
| 41 | + */ |
| 42 | + var isReordable: Bool { get } |
| 43 | + |
| 44 | + /** |
| 45 | + A Boolean value indicating whether the user can insert items as children. |
| 46 | + |
| 47 | + The default value is `true`. |
| 48 | + */ |
| 49 | + var canInsertChildren: Bool { get } |
| 50 | + |
| 51 | + /** |
| 52 | + A Boolean value indicating whether the item is a group item. |
| 53 | + |
| 54 | + The default value is `false`. |
| 55 | + */ |
| 56 | + var isGroupItem: Bool { get } |
| 57 | +} |
| 58 | + |
| 59 | +extension CellOutlineItem { |
| 60 | + public var isExpandable: Bool { true } |
| 61 | + public var isSelectable: Bool { true } |
| 62 | + public var isDeletable: Bool { false } |
| 63 | + public var isReordable: Bool { false } |
| 64 | + public var canInsertChildren: Bool { true } |
| 65 | + public var isGroupItem: Bool { false } |
| 66 | +} |
| 67 | + |
| 68 | +/// A outline view item that creates it's cell view. |
| 69 | +public protocol RegisteredCellOutlineItem: CellOutlineItem { |
| 70 | + associatedtype Cell: NSTableCellView |
| 71 | + /// The cell registration that creates the cell view for the item. |
| 72 | + static var cellRegistration: NSTableView.CellRegistration<Cell, Self> { get } |
| 73 | +} |
| 74 | + |
| 75 | +extension RegisteredCellOutlineItem { |
| 76 | + public func cellView(_ outlineView: NSOutlineView, column: NSTableColumn, row: Int) -> NSView { |
| 77 | + outlineView.makeCellView(using: Self.cellRegistration, forColumn: column, row: row, item: self) ?? NSTableCellView() |
| 78 | + } |
| 79 | +} |
| 80 | +*/ |
0 commit comments