This repository was archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Fixes, enhancements and back porting to macOS 10.11 #3
Open
guidedways
wants to merge
15
commits into
cocoabits:master
Choose a base branch
from
BeehiveInnovations:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6a9bf8d
Cleanup and comments
guidedways 1ea3a8e
Removed duplicate code
guidedways 67348bc
Don't allow dragging on, next to a child item
guidedways e0ebd9a
Update expansion state when moving / appending
guidedways 67d2e71
Check expansion state by looking at the number of children
guidedways 4d3c351
Fixed diffing bug where item's parentID wasn't taken into account. Mo…
guidedways 423cc65
Make note of parent items to reload after a move so their expansion s…
guidedways 4fc9294
Lowered required macOS version to 10.11 for the module by back-portin…
guidedways 5f919b9
Update README.md
guidedways dece4a1
Update README.md
guidedways 2c222a2
Move items during drag and drop instead of deleting + appending, whic…
guidedways d174ffc
Refactoring - renamed funcs so they sound like functions.
guidedways c61671f
Fixed moving into a target. Deleting the node was also deleting all i…
guidedways 086c5f9
Better example
guidedways 9e58df9
Support for macOS 10.15 and Xcode 12.2
guidedways File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ import OutlineViewDiffableDataSource | |
|
|
||
| /// The number of controls for an empty outline view selection. | ||
| final class EmptyViewController: NSViewController { | ||
|
|
||
| /// Multiline text editor for the outline contents. | ||
| private lazy var scrollableEditor: NSScrollView = { | ||
| let scrollView = NSTextView.scrollablePlainDocumentContentTextView() | ||
|
|
@@ -56,17 +55,25 @@ extension EmptyViewController { | |
|
|
||
| guard let textView = scrollableEditor.documentView as? NSTextView, textView.string.isEmpty else { return } | ||
| textView.string = """ | ||
| Parent 1 / Child 11 | ||
| Parent 1 / Child 12 | ||
| Parent 1 / Child 13 | ||
| Parent 2 | ||
| Parent 2 / Child 21 | ||
| Child 21 / Leaf 211 | ||
| Child 21 / Leaf 212 | ||
| Parent 3 / Child 31 | ||
| Parent 3 / Child 32 | ||
| Parent 3 / Child 33 | ||
| Cars / Toyota | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one 👍 |
||
| Cars / Honda | ||
| Cars / Tesla | ||
| Phones | ||
| Phones / Samsung | ||
| Samsung / Samsung Note | ||
| Samsung / Samsung Nexus | ||
| Samsung Nexus / Nexus 5 | ||
| OS / macOS | ||
| OS / Windows | ||
| OS / Linux | ||
| """ | ||
|
|
||
| // Parent 3 | ||
| // Parent 3 / Child 31 | ||
| // Child 31 / Child 33 | ||
| // Child 33 / Child 32 | ||
|
|
||
| fillSidebar(nil) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -77,9 +84,11 @@ private extension EmptyViewController { | |
| /// Replaces the whole tree with the given contents. | ||
| @IBAction func fillSidebar(_ sender: Any?) { | ||
| guard let textView = scrollableEditor.documentView as? NSTextView else { return } | ||
|
|
||
| // Create a new snapshot from entered Parent / Child items. | ||
| var snapshot: DiffableDataSourceSnapshot = .init() | ||
| snapshot.fillItem(nil, with: textView.string) | ||
| snapshotBinding.wrappedValue = snapshot | ||
| snapshotBinding.wrappedValue = snapshot | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check the whitespace leftover. |
||
| } | ||
|
|
||
| /// Replaces text with sidebar contents. | ||
|
|
@@ -89,8 +98,8 @@ private extension EmptyViewController { | |
| var items: [String] = [] | ||
| snapshot.enumerateItems { item, parentItem in | ||
| items.append([ | ||
| (parentItem as? GroupOutlineViewItem)?.title ?? (parentItem as? MasterOutlineViewItem)?.title, | ||
| (item as? GroupOutlineViewItem)?.title ?? (item as? MasterOutlineViewItem)?.title, | ||
| (parentItem as? MasterGroupOutlineViewItem)?.title ?? (parentItem as? MasterOutlineViewItem)?.title, | ||
| (item as? MasterGroupOutlineViewItem)?.title ?? (item as? MasterOutlineViewItem)?.title, | ||
| ].compactMap { $0 }.joined(separator: " / ")) | ||
| } | ||
| textView.string = items.joined(separator: "\n") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,22 @@ | ||
| import AppKit | ||
| import OutlineViewDiffableDataSource | ||
|
|
||
| /// Default root item with buttons ‘Show’ and ‘Hide’, not intended for subclassing. | ||
| public final class GroupOutlineViewItem: NSObject, OutlineViewItem { | ||
|
|
||
| /// Unique identifier for diffing. | ||
| public let id: String | ||
|
|
||
| public final class MasterGroupOutlineViewItem: GroupOutlineViewItem { | ||
| /// Display string. | ||
| public let title: String | ||
|
|
||
| /// Show as Group. | ||
| public let isGroup: Bool = true | ||
|
|
||
| /// Deny selection. | ||
| public let isSelectable: Bool = false | ||
|
|
||
| /// Creates a “standard” root item for the sidebar. | ||
| public init(id: String, title: String) { | ||
| self.id = id | ||
| self.title = title | ||
| super.init(id: id) | ||
| } | ||
|
|
||
| /// Returns an appropriate cell view type. | ||
| public func cellViewType(for tableColumn: NSTableColumn?) -> NSTableCellView.Type { GroupTableCellView.self } | ||
| public override func cellViewType(for tableColumn: NSTableColumn?) -> NSTableCellView.Type { GroupTableCellView.self } | ||
|
|
||
| /// Necessary for sets. | ||
| public override var hash: Int { title.hash } | ||
|
|
||
| /// Necessary for outline view reloading. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please explain why this isn’t necessary anymore? |
||
| public override func isEqual(_ object: Any?) -> Bool { | ||
| guard let groupItem = object as? GroupOutlineViewItem else { return false } | ||
| return groupItem.id == id | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Private API | ||
|
|
@@ -86,7 +71,7 @@ private final class GroupTableCellView: NSTableCellView { | |
| /// Retrieves new title from the associated group item. | ||
| override var objectValue: Any? { | ||
| didSet { | ||
| if let label = textField, let groupItem = objectValue as? GroupOutlineViewItem { | ||
| if let label = textField, let groupItem = objectValue as? MasterGroupOutlineViewItem { | ||
| label.stringValue = groupItem.title | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,25 +2,21 @@ import AppKit | |
| import OutlineViewDiffableDataSource | ||
|
|
||
| /// Sidebar iitems. | ||
| class MasterOutlineViewItem: NSObject, OutlineViewItem { | ||
|
|
||
| class MasterOutlineViewItem: OutlineViewItem { | ||
| /// Visible string. | ||
| let title: String | ||
|
|
||
| /// Creates a new item ready for insertion into the sidebar. | ||
| init(title: String) { self.title = title } | ||
|
|
||
| init(id: String, title: String) { | ||
| self.title = title | ||
| super.init(id: id) | ||
| } | ||
|
|
||
| /// Returns a private cell view type. | ||
| func cellViewType(for tableColumn: NSTableColumn?) -> NSTableCellView.Type { MasterCellView.self } | ||
| override func cellViewType(for tableColumn: NSTableColumn?) -> NSTableCellView.Type { MasterCellView.self } | ||
|
|
||
| /// Necessary for sets. | ||
| /// Necessary for supporting drag-n-drop and expand-collapse. | ||
| override var hash: Int { title.hash } | ||
|
|
||
| /// Necessary for outline view reloading. | ||
| override func isEqual(_ object: Any?) -> Bool { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| guard let masterItem = object as? MasterOutlineViewItem else { return false } | ||
| return masterItem.title == title | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Private API | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?