-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutlineViewDataSource+Passthrough.swift
320 lines (277 loc) · 14.9 KB
/
OutlineViewDataSource+Passthrough.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
//
// OutlineViewDataSource+Passthrough.swift
// OutlineViewDiffableDataSource
//
// Created by Steve Sparks on 2/9/20.
// Copyright © 2020 Big Nerd Ranch. All rights reserved.
//
import Cocoa
public extension NSObject {
}
public class PassthroughOutlineViewDataSource: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate {
func report(_ message: String = "", _ preamble: String = "", function: String = #function) {
// let fn = String(describing: type(of: self))
// print("--> \(preamble)\(fn) \(function) \(message) ")
}
var dataSource: NSOutlineViewDataSource!
var delegate: NSOutlineViewDelegate?
init(dataSource: NSOutlineViewDataSource, delegate: NSOutlineViewDelegate? = nil) {
self.dataSource = dataSource
self.delegate = delegate
super.init()
}
enum OverriddenSelectors: String, CaseIterable {
case outlineViewNumberOfChildrenOfItem = "outlineView:numberOfChildrenOfItem:"
case outlineViewChildOfItem = "outlineView:child:ofItem:"
case outlineViewIsItemExpandable = "outlineView:isItemExpandable:"
}
enum DataSourceSelectors: String, CaseIterable {
case outlineViewPersistentObjectForItem = "outlineView:persistentObjectForItem:"
case outlineViewItemForPersistentObject = "outlineView:itemForPersistentObject:"
case outlineViewObjectValueForByItem = "outlineView:objectValueForTableColumn:byItem:"
case outlineViewSetObjectValueForByItem = "outlineView:setObjectValue:forTableColumn:byItem:"
case outlineViewSortDescriptorsDidChange = "outlineView:sortDescriptorsDidChange:"
case outlineViewUpdateDraggingItemsForDrag = "outlineView:updateDraggingItemsForDrag:"
case outlineViewPasteboardWriterForItem = "outlineView:pasteboardWriterForItem:"
case outlineViewWriteItemsTo = "outlineView:writeItems:to:"
case outlineViewValidateDrop = "outlineView:validateDrop:proposedItem:proposedChildIndex:"
case outlineViewAcceptDrop = "outlineView:acceptDrop:item:childIndex:"
case outlineViewDraggingBegin = "outlineView:draggingSession:willBeginAt:forItems:"
case outlineViewDraggingEnd = "outlineView:draggingEndedAt:operation:"
}
enum DelegateSelectors: String, CaseIterable {
case outlineViewColumnDidMove = "outlineViewColumnDidMove:"
case outlineViewIsGroupItem = "outlineView:isGroupItem:"
case outlineViewDidClick = "outlineView:didClick:"
case outlineViewDidDrag = "outlineView:didDrag:"
case outlineViewMouseDownInHeaderOf = "outlineView:mouseDownInHeaderOf:"
case outlineViewShouldExpandItem = "outlineView:shouldExpandItem:"
case outlineViewShouldCollapseItem = "outlineView:shouldCollapseItem:"
case outlineViewShouldSelectItem = "outlineView:shouldSelectItem:"
case outlineViewShouldSelectTableColumn = "outlineView:shouldSelect:"
case outlineViewShouldEditTableColumn = "outlineView:shouldEdit:item:"
case outlineViewViewForTableColumnItem = "outlineView:viewForTableColumn:item:"
case outlineViewItemWillExpand = "outlineViewItemWillExpand:"
case outlineViewItemWillCollapse = "outlineViewItemWillCollapse:"
case outlineViewItemDidExpand = "outlineViewItemDidExpand:"
case outlineViewItemDidCollapse = "outlineViewItemDidCollapse:"
case outlineViewWillDisplayCellForTableColumnItem = "outlineView:willDisplayCell:forTableColumn:item:"
case outlineViewWillDisplayOutlineCellForTableColumnItem = "outlineView:willDisplayOutlineCell:forTableColumn:item:"
}
override public func responds(to aSelector: Selector!) -> Bool {
let sel = aSelector.description
var ret = false
var ident = "???"
if let _ = OverriddenSelectors(rawValue: sel) {
ident = "OVR"
ret = true
} else if let _ = DataSourceSelectors(rawValue: sel) {
ident = "DS "
ret = dataSource.responds(to: aSelector)
} else if let _ = DelegateSelectors(rawValue: sel) {
ident = "DLG"
ret = delegate?.responds(to: aSelector) ?? false
} else {
ret = super.responds(to: aSelector)
}
// change this to print() if you wish
_ = "\(ident) \(sel) -> \(ret)"
return ret
}
public func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
report()
return dataSource.outlineView!(outlineView, numberOfChildrenOfItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
report()
return dataSource.outlineView!(outlineView, child: index, ofItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
report()
return dataSource.outlineView!(outlineView, isItemExpandable: item)
}
////
public func outlineView(_ outlineView: NSOutlineView, persistentObjectForItem item: Any?) -> Any? {
report()
return dataSource.outlineView!(outlineView, persistentObjectForItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, itemForPersistentObject object: Any) -> Any? {
report()
return dataSource.outlineView!(outlineView, itemForPersistentObject: object)
}
public func outlineView(_ outlineView: NSOutlineView, objectValueFor tableColumn: NSTableColumn?, byItem item: Any?) -> Any? {
report()
return dataSource.outlineView!(outlineView, objectValueFor: tableColumn, byItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, byItem item: Any?) {
report()
dataSource.outlineView!(outlineView, setObjectValue: object, for: tableColumn, byItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) {
report()
dataSource.outlineView!(outlineView, sortDescriptorsDidChange: oldDescriptors)
}
public func outlineView(_ outlineView: NSOutlineView, updateDraggingItemsForDrag draggingInfo: NSDraggingInfo) {
report()
dataSource.outlineView!(outlineView, updateDraggingItemsForDrag: draggingInfo)
}
public func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? {
report()
return dataSource.outlineView?(outlineView, pasteboardWriterForItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, writeItems items: [Any], to pasteboard: NSPasteboard) -> Bool {
report()
return dataSource.outlineView!(outlineView, writeItems: items, to: pasteboard)
}
public func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
report()
return dataSource.outlineView?(outlineView, validateDrop: info, proposedItem: item, proposedChildIndex: index) ?? .generic
}
public func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
report()
return dataSource.outlineView?(outlineView, acceptDrop: info, item: item, childIndex: index) ?? false
}
public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forItems draggedItems: [Any]) {
report()
dataSource.outlineView?(outlineView, draggingSession: session, willBeginAt: screenPoint, forItems: draggedItems)
}
public func outlineView(_ outlineView: NSOutlineView, draggingSession session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
report()
dataSource.outlineView?(outlineView, draggingSession: session, endedAt: screenPoint, operation: operation)
}
// MARK: - NSOutlineViewDelegate
public func outlineViewColumnDidMove(_ notification: Notification) {
report()
delegate!.outlineViewColumnDidMove?(notification)
}
public func outlineView(_ outlineView: NSOutlineView, isGroupItem item: Any) -> Bool {
report()
return delegate!.outlineView!(outlineView, isGroupItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, didClick tableColumn: NSTableColumn) {
report()
delegate!.outlineView!(outlineView, didClick: tableColumn)
}
public func outlineView(_ outlineView: NSOutlineView, didDrag tableColumn: NSTableColumn) {
report()
delegate!.outlineView!(outlineView, didDrag: tableColumn)
}
public func outlineView(_ outlineView: NSOutlineView, mouseDownInHeaderOf tableColumn: NSTableColumn) {
report()
delegate!.outlineView!(outlineView, mouseDownInHeaderOf: tableColumn)
}
public func outlineView(_ outlineView: NSOutlineView, shouldExpandItem item: Any) -> Bool {
report()
return delegate!.outlineView!(outlineView, shouldExpandItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool {
report()
return delegate!.outlineView!(outlineView, shouldSelectItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, shouldCollapseItem item: Any) -> Bool {
report()
return delegate!.outlineView!(outlineView, shouldCollapseItem: item)
}
public func outlineView(_ outlineView: NSOutlineView, shouldSelect tableColumn: NSTableColumn?) -> Bool {
report()
return delegate!.outlineView!(outlineView, shouldSelect: tableColumn)
}
public func outlineView(_ outlineView: NSOutlineView, shouldEdit tableColumn: NSTableColumn?, item: Any) -> Bool {
report()
return delegate!.outlineView!(outlineView, shouldEdit: tableColumn, item: item)
}
public func outlineViewItemWillCollapse(_ notification: Notification) {
report()
delegate!.outlineViewItemWillCollapse!(notification)
}
public func outlineViewItemWillExpand(_ notification: Notification) {
report()
delegate!.outlineViewItemWillExpand!(notification)
}
public func outlineViewItemDidCollapse(_ notification: Notification) {
report()
delegate!.outlineViewItemDidCollapse!(notification)
}
public func outlineViewItemDidExpand(_ notification: Notification) {
report()
delegate!.outlineViewItemDidExpand!(notification)
}
public func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
report()
return delegate!.outlineView!(outlineView, viewFor: tableColumn, item: item) ?? nil
}
// MARK: - To Do
// TODO: Implement the loop:
// - contrive a use of the method
// - note the selector logged in `responds(to:)`
// - add the selector to the DelegateSelectors array
// - uncomment the method down below
// - correct the code as necessary
//
// public func outlineView(_ outlineView: NSOutlineView, shouldShowCellExpansionFor tableColumn: NSTableColumn?, item: Any) -> Bool {
// report()
// return delegate!.outlineView!(outlineView, shouldShowCellExpansionFor: tableColumn, item: item) ?? false
// }
// public func outlineView(_ outlineView: NSOutlineView, shouldReorderColumn columnIndex: Int, toColumn newColumnIndex: Int) -> Bool {
// report()
// return delegate!.outlineView!(outlineView, shouldReorderColumn: columnIndex, toColumn: newColumnIndex) ?? false
// }
// public func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
// report()
// return delegate!.outlineView!(outlineView, heightOfRowByItem: item) ??
// delegate!.outlineView!(outlineView, viewFor: nil, item: item)?.fittingSize.height ??
// 16.0
// }
// public func outlineView(_ outlineView: NSOutlineView, sizeToFitWidthOfColumn column: Int) -> CGFloat {
// report()
// return delegate!.outlineView!(outlineView, sizeToFitWidthOfColumn: column) ?? 0.0
// }
// public func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {
// report()
// return delegate!.outlineView!(outlineView, rowViewForItem: item) ?? nil
// }
// public func outlineView(_ outlineView: NSOutlineView, dataCellFor tableColumn: NSTableColumn?, item: Any) -> NSCell? {
// report()
// return delegate!.outlineView!(outlineView, dataCellFor: tableColumn, item: item) ?? nil
// }
// public func outlineView(_ outlineView: NSOutlineView, typeSelectStringFor tableColumn: NSTableColumn?, item: Any) -> String? {
// report()
// return delegate!.outlineView!(outlineView, typeSelectStringFor: tableColumn, item: item) ?? nil
// }
// public func outlineView(_ outlineView: NSOutlineView, shouldShowOutlineCellForItem item: Any) -> Bool {
// report()
// return delegate!.outlineView!(outlineView, shouldShowOutlineCellForItem: item) ?? false
// }
//
// public func outlineView(_ outlineView: NSOutlineView, didAdd rowView: NSTableRowView, forRow row: Int) {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, didRemove rowView: NSTableRowView, forRow row: Int) {
// report()
// }
//
// public func outlineView(_ outlineView: NSOutlineView, willDisplayCell cell: Any, for tableColumn: NSTableColumn?, item: Any) {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, willDisplayOutlineCell cell: Any, for tableColumn: NSTableColumn?, item: Any) {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, shouldTrackCell cell: NSCell, for tableColumn: NSTableColumn?, item: Any) -> Bool {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet) -> IndexSet {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, shouldTypeSelectFor event: NSEvent, withCurrentSearch searchString: String?) -> Bool {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, nextTypeSelectMatchFromItem startItem: Any, toItem endItem: Any, for searchString: String) -> Any? {
// report()
// }
// public func outlineView(_ outlineView: NSOutlineView, toolTipFor cell: NSCell, rect: NSRectPointer, tableColumn: NSTableColumn?, item: Any, mouseLocation: NSPoint) -> String {
// report()
// }
// public func selectionShouldChange(in outlineView: NSOutlineView) -> Bool {
// report()
// }
}