-
Notifications
You must be signed in to change notification settings - Fork 9
Added MultiSelect #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
a00992f to
72fcdc9
Compare
|
Hi @wogus3602 👋 Thanks for the taking the time to work on this! I was playing around with the example app and I noticed a couple of issues.
You can see both the issues on the screen recording: Screen.Recording.2023-02-13.at.21.11.08.mov |
|
@ZofiaBernadetta , the multi-select not working with drag & drop is something I can work on, since it's my code that ignored the possibility of multiple dragged items. Maybe once @wogus3602 is done with everything else on this PR, I can take that responsibility last :-) |
|
@RCCoop did you ever add support for multi-select drag & drop? |
|
@brendand , I haven't, sorry. I've been working on other projects lately that don't use OutlineView, so I haven't had time to look at it. |
| ) { | ||
| // Returns -1 if row is not found. | ||
| let index = outlineView.row(forItem: selectedItem) | ||
| let index = outlineView.row(forItem: selectedItems) |
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.
I don't think the updated code is correct for multiple selected items. I grabbed your code for an app I'm working on and besides renaming it selectRows my current code is:
func selectRows(
for items: [OutlineViewItem],
in outlineView: NSOutlineView
) {
// Returns -1 if row is not found.
let indices = items.compactMap { outlineView.row(forItem: $0) == -1 ? nil : outlineView.row(forItem: $0) }
outlineView.selectRowIndexes(IndexSet(indices), byExtendingSelection: false)
}
| if selectedItem?.id != newSelection?.id { | ||
| selectedItem = newSelection | ||
| selectionChanged(selectedItem?.value) | ||
| let selectedRowIndexes = outlineView.selectedRowIndexes |
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.
To get selectionChanged(xxx) to be called when I chose a new outline row I had to comment out some of your code. The first check for isEmpty shouldn't be needed because selectionChanged(emptySet) still needs to be called if you unselect every row. Also returning early because selectedItems and newSelection counts are same caused single selecting new items to not call selectionChanged(xxx) too. Also wasn't sure why the if selectedItems.allSatisfy call was there too?
Current code I'm using:
func outlineViewSelectionDidChange(_ notification: Notification) {
let outlineView = notification.object as! NSOutlineView
let selectedRowIndexes = outlineView.selectedRowIndexes
#warning("Check with original author why commented out code was needed")
//if !selectedRowIndexes.isEmpty {
let newSelections = selectedRowIndexes.compactMap {
outlineView.item(atRow: $0).map(typedItem)
}
// if selectedItems.count == newSelections.count {
// return
// }
//if selectedItems.allSatisfy({ newSelections.contains($0) }) {
selectedItems = newSelections
selectionChanged(Set(selectedItems.map(\.value)))
//}
//}
}
2023-02-09.3.06.19.mov