Does NSFilePromiseReceiver work?

BrianBocciaBrianBoccia USMember ✭✭

I can't find an example of drag/drop with NSFilePromiseReceiver instead of just handling views or file URLs. I've built something based loosely around Apple's documentation and the wiring seems to be more or less correct. I can see the debugger getting to promise.ReceivePromisedFiles, but, I never get to urlList.Add. I've tried making the operation queue class-level so it doesn't get cleaned up before it can process things. And even tried saving off the promise itself for the same reason. But that's ugly and clunky and still doesn't work anyway.

Note: This is an attempt to handle files dropped from Apple's Photos.app - dropping files from finder was working with the old file URL method. And I know that async execution may mean that urlList isn't populated when I hand it off to be handled. But I'm not getting as far as getting the actual file promise working, so one thing at a time.

        [Export("performDragOperation")]
        public override bool PerformDragOperation(NSDraggingInfo sender)
        {
            var urlList = new List<string>();
            var types = NSArray.FromIntPtrs(new IntPtr[] { new ObjCRuntime.Class(typeof(NSFilePromiseReceiver)).Handle, new ObjCRuntime.Class(typeof(NSUrl)).Handle });

            sender.EnumerateDraggingItems(NSDraggingItemEnumerationOptions.ClearNonenumeratedImages, this, types, new NSDictionary(), (NSDraggingItem draggingItem, nint idx, ref bool stop) =>
            {
                Console.WriteLine("DraggingItem: {0}", draggingItem);
                if (draggingItem.Item is NSFilePromiseReceiver promise)
                {
                    promise.ReceivePromisedFiles(new NSUrl(Path.GetTempFilePath()), new NSDictionary(), _dragOperations,
                        (NSUrl url, NSError error) => {
                            urlList.Add(url.Path);
                        });

                }
                else if (draggingItem.Item is NSUrl url)
                {
                    urlList.Add(url.Path);
                }
            });


        HandleUrls(urlList);

            return true;
        }

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    It would be very useful for questions like this to produce an entire small sample showing your issue. Correctly wiring up the various steps (registering for type, prepare for, perform, etc) is non-trivial.

Sign In or Register to comment.