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
[macOS] NSCollectionView.ValidateDrop should use 'ref', not 'out'. Fixes #60416 #2947
Conversation
Build success |
src/appkit.cs
Outdated
#else | ||
[Mac (10,11)] | ||
[Export ("collectionView:validateDrop:proposedIndexPath:dropOperation:")] | ||
NSDragOperation ValidateDrop (NSCollectionView collectionView, [Protocolize (4)] NSDraggingInfo draggingInfo, ref NSIndexPath proposedDropIndexPath, ref NSCollectionViewDropOperation proposedDropOperation); |
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.
Minor: you can use INSDraggingInfo
instead of [Protocolize (4)] NSDraggingInfo
since this is a XAMCORE_4_0-only code path.
[Mac (10, 11)] | ||
public virtual NSDragOperation ValidateDrop (NSCollectionView collectionView, NSDraggingInfo draggingInfo, out NSIndexPath proposedDropIndexPath, out NSCollectionViewDropOperation proposedDropOperation) | ||
{ | ||
throw new InvalidOperationException ("Use 'ValidateDropOperation (NSCollectionView collectionView, NSDraggingInfo draggingInfo, ref NSIndexPath proposedDropIndexPath, ref NSCollectionViewDropOperation proposedDropOperation)' instead."); |
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.
Could these methods work in any scenario with the out
parameter? If so, we should continue making it work by calling the ref
overload instead of throwing an exception.
Same goes for the other methods below.
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.
From what I can tell they do not. The ValidateDrop method is called when you drag an object in the collection view. When you drag over a location, it calls Validatedrop to determine if it can be dropped there. With the 'out' parameter, the method is never called in the first place from what I've seen.
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 suppose there's no real reason I couldn't make it call the ref version anyway
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.
Please implement @rolfbjarne suggestion - it can only avoid compatibility issues :)
Build failure |
Failure appears unrelated: https://github.com/xamarin/maccore/issues/573 |
build |
Build success |
The two pointer parameters pass in the proposed index and operation to the method, then the developer has the option to change those values if desired inside the method. The current binding using 'out' parameters is never called when it is supposed to be in an application.
Because it is an existing binding, we cannot simply change the parameters to 'refs' and instead have to bind a new method using 'ref' and use code-behind to keep versions of the old binding around.
The new method also has to have a new name, because you can not have 2 methods with matching signatures where the only difference is 'ref' versus 'out.