dropping files using Safari on Mac

7 posts, 0 answers
  1. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 07 Jul 2013 Link to this post

    Using Safari 6.0.5 on Mac OS 10.8.4, I want to drop files from outside Safari on to nodes in the tree view.  I have this working fine on Windows.  I see from around the internet:

    http://social.msdn.microsoft.com/Forums/silverlight/en-US/faf922b4-370c-4901-9e87-385ef410e61f/silverlight-5-drag-and-drop-on-mac-os-x-1075-and-safari
    http://connect.microsoft.com/VisualStudio/feedback/details/726450/silverlight-5-drag-from-file-system-does-not-work-on-mac-osx-10-7-running-safari

    that this may be broken in the latest versions of Safari, so before I spend a lot of time looking for workarounds using HTML 5 events and FileReader() have you already investigated this and got a working example for Macs?

    I've read http://msdn.microsoft.com/en-us/library/ee670998%28VS.95%29.aspx also but as mentioned elsewhere this works for the events except the drop event which is not propagated to Silverlight.

    Thanks,

    Scott
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 11 Jul 2013 Link to this post

    Hi Scott,

    I've been trying to workaround the issue but it definitely seems that the Silverlight plug-in doesn't receive any proper notification of the drop action in Safari on Mac and unfortunately I was also not able to come up with any solutions.

    This is why the RadTreeView control also can't detect the drop operation or handle it in any way. I'm afraid that at the moment we can't suggest nor implement any solutions for the same.

    Regards,
    Tina Stancheva
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 14 Jul 2013 Link to this post

    Ok thanks,

    I managed to work around it with a some Html 5 events and a Scriptable event in the Silverlight code.
  5. Cavit
    Cavit avatar
    16 posts
    Member since:
    Apr 2015

    Posted 23 Apr 2015 Link to this post

    Do you know if there is a fix for drag and drop issue for Silverlight on Safari - Mac ?

    Thanks

  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 27 Apr 2015 Link to this post

    Hi Cavit,

    Currently we have no sample with implemented workaround. I guess Scott has used the techniques described here.

    Regards,
    Petar Mladenov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 27 Apr 2015 in reply to Petar Mladenov Link to this post

    Yes, the javascript looks like:

     

    function handleDropEvent(oEvent) {
        // Prevent default operations in DOM
        oEvent.preventDefault();
        var agControl = document.getElementById("AgControl1");
        var flag = agControl.dragDrop(oEvent);
        // If handled, then stop propagation of event in DOM
        if (flag) oEvent.stopPropagation();
     
        var file = oEvent.dataTransfer.files[0];
        var reader = new FileReader();
        reader.onload = (function (theFile) {
            return function (e) {
                agControl.Content.mySLapp.Drop(oEvent.x, oEvent.y, theFile.name, new Uint8Array(e.target.result));
            };
        })(file);
        reader.readAsArrayBuffer(file);
    }

    And the c#:

     

    public class ScriptableDropHandler
        {
            [ScriptableMember]
            public void Drop(object x, object y, object name, object args)
            {
                var scriptObject = args as ScriptObject;
                if(scriptObject != null)
                {
                    var length = scriptObject.GetProperty("length");
                    var intLength = Convert.ToInt32(length);
     
                    var bytes = new byte[intLength];
                    for(var i = 0; i < bytes.Length; i++)
                    {
                        bytes[i] = Convert.ToByte(scriptObject.GetProperty(i));
                    }
     
                    var elements = VisualTreeHelper.FindElementsInHostCoordinates(new Point((double)x, (double)y), Application.Current.RootVisual);
                    foreach (var element in elements)
                    {
                        var handler = FileDropHandlerBehavior.GetFileDropHandler(element);
                        if(handler != null)
                        {
                            handler.Accept(new FileDropArgs
                                {
                                    Source = element,
                                    FileDropInfos = new [] { new FileDropInfo
                                        {
                                            Name = name as string,
                                            Contents = bytes
                                        }}
                                });
                            break;
                        }
                    }
                }
            }

     

    If I remember correctly though, I think a recent update to Mac/Safari has broken something and I've not had a chance to investigate.

  8. Cavit
    Cavit avatar
    16 posts
    Member since:
    Apr 2015

    Posted 05 May 2015 in reply to Scott Waye Link to this post

    Thanks a lot for thre replies.
Back to Top
DevCraft banner