Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Conversation

@guidedways
Copy link

This PR includes a number of enhancements, fixes and a back-port of the diffing algorithm (taken from the open source Swift implementation) so that the module itself can be used on macOS 10.11.

I've also fixed a number of bugs present within the demo with some additional optimizations / tests. Duplicate code has been removed from a few places, plus the code is now easier to follow.

Along the way I've also fixed a few known glitches within NSOutlineView (such as parent nodes appearing with overlapping glyphs).

The PR also includes more documentation and some refactoring.

guidedways and others added 14 commits October 2, 2021 14:13
Removed Grouped outline item and moved it to demo instead. Replaced with a subclass.
Simplified code to use OutlineViewItem as a concrete type
Improvements to demo. Only nodes with children show an expansion indicator.
More documentation
WIP - Need to fix drag and drop
Reload parent item (old and new) after a move as expansion states don't otherwise refresh
…ving items would otherwise remain broken.

Reload parent items when removing / inserting
…g "CollectionDifference" related methods

Renamed collection difference methods to avoid clashes on macOS 10.15+
…h deletes child items too

Documentation and cleanup
Perform reloadData() instead of animating if changes above a certain threshold
New test to confirm moving items with children
Fixed NSOutlineView glitch where expansion arrow would overlap the label after a remove + insert
Renamed some variables for clarity
Renamed IndexedID to IndexedNode
Added itemID to Node for consistency
Copy link
Collaborator

@shpakovski shpakovski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I’m happy to see new ideas. However this looks like a new component. Not sure 100% how to handle such a massive branch…

But I’m not going to merge it right now, sorry. Instead I’d like to ask you to maintain your public version and make another request for the README with a URL of your implementation.

Thanks for understanding 🙏

let viewController = NSTabViewController()
viewController.tabStyle = .unspecified
viewController.transitionOptions = []
viewController.view.wantsLayer = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this change?

Parent 3 / Child 31
Parent 3 / Child 32
Parent 3 / Child 33
Cars / Toyota
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 👍

var snapshot: DiffableDataSourceSnapshot = .init()
snapshot.fillItem(nil, with: textView.string)
snapshotBinding.wrappedValue = snapshot
snapshotBinding.wrappedValue = snapshot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the whitespace leftover.


/// Necessary for sets.
public override var hash: Int { title.hash }

/// Necessary for outline view reloading.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain why this isn’t necessary anymore?

override var hash: Int { title.hash }

/// Necessary for outline view reloading.
override func isEqual(_ object: Any?) -> Bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

if parentItemToAppendTo != nil && appendToParentNode == nil {
#if DEBUG
print("insertItems - Cannot find parent item \(String(describing: parentItemToAppendTo))")
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Care to remove spacing in the beginning? 😊

if targetItem != nil && targetItemNode == nil {
#if DEBUG
print("Cannot find item \(String(describing: targetItem))")
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

public func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
guard let item = item as? OutlineViewItem else { return true }
return item.isExpandable
return item.isExpandable && currentSnapshot.childrenOfItem(item).count > 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not work after reloading. I introduced isExpandable and count > 0 explicitly to permit the disclosure indicator without children.


public extension OutlineViewDiffableDataSource {

/// Returns current state of the data source. This property is thread-safe.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙂

}
// When a data source is not set, reload the first time
guard animatingDifferences, let _ = outlineView?.dataSource else {
reloadData()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this effective enough?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants