[VS2010] - DragDrop for POCO from ToolWindow to Editor Window

Jawab [VS2010] - DragDrop for POCO from ToolWindow to Editor Window

  • 25 April 2012 19:33
     
     

    Hi

    I've been struggling for days to figure this out but cannot seem to find a way.  I'm implementing a DropHandler (IDropHandler, DropHandlerBase, tried em both) to drag from a custom TreeView tool window onto the Visual Studio Editor Window.

    I've found a number of results (including one on the forum that just said "look at IVsLanguageOps") but none that seem to answer my question.  It seems it's all related around the DropFormat not being recognized by the handler.  As such, I get the cannot drag symbol and the GetAssociatedHandler method of my IDropHandlerProvider is never called.

    However, if I drag an item from the solution explorer (file) then no problems and my drop handler is fired.  I've added the "PersistantObject" dropFormat, I've tried defining the class name, putting it as the first handler.  Reflected out all the code that MS is using (DragDropMouseProcessor is where I start, but still comes down to DropFormat).

    Can anyone tell me how to do this?  Or what I'm missing?  I've basically recreated the FileDropHandler from Microsoft.VisualStudio.Editor.Implementation.  But not working out.

    Please help, this is the last stage of my extension and so damn close :)

Semua Balasan

  • 26 April 2012 6:52
    Moderator
     
     

    Hi AnyUserNameWillDo,

    Thank you for your question.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.

     


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

  • 26 April 2012 13:54
     
      Memiliki Kode

    Appreciated.  I've been doing some more digging at the core implementation of DragDrop in Visual Studio.  What I've found is it appears the DropFormat isn't recognized because it's either not wrapped in a DataObject (Implementing both System.Windows.IDataObject and System.Runtime.InteropServices.ComTypes.IDataObject)

    Inside Microsoft.VisualStudio.Platfrom.VSEditor.dll is all the implemenations of the abstractions in VS.  So, inside here you have

    internal class DragDropMouseProcessor : MouseProcessorBase

    As I dig in,, we find the DragDropStateManager which maintains a list of all the IDropHandlerProviders and there associated formats in IDropHandlerMetadata.  It queries on the PreprocessDragEnter based on the DataFormat and finds the handler.  I could probably just implement another MouseProcessorBase to determine the format available, but going to try this first.

    I'll update shortly (hopefully).

  • 26 April 2012 13:57
     
     
    Helps to see DataObject is a sealed class......  alright.. plan B. 
  • 26 April 2012 20:02
    Moderator
     
     

    Hi Chris,

    What exactly are you trying to drop/copy to the editor? The editor should recognize various text formats, can you provide a code snippet, or details aroudn what exactly you want to drop?

    I haven't experimented with those internal platform interfaces. Historically, I think we used to just use (and probably still recognize), IDataOjects.

    Ed..


    Ed Dore

  • 26 April 2012 20:48
     
     

    Just typed a full response for the past 20 mins and clicking outside the text editor here and some how it just went away...  typical for me.

    Alright, so if you look at the VS Editor example for the Image Adornment Drop Handler where you drop an image on the code editor and it does some work to display it on the adornment layer but at the same time adjust tracking spans etc. 

    Now.  I am doing the same thing, but instead of dragging from the file explorer, I'm dragging from a Telerik TreeView Node (WPF, Q3.2011) which each node's datacontext is of a custom class type.  I know Telerik has some stuff that gets a little crazy at times, but usually haven't had a problem working with other MS controls..

    So, more research/reflection found a few things. 

    1.  SVsMainWindowDropTarget http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.svsmainwindowdroptarget%28VS.80%29.aspx

    nothing

    2. Microsoft.VisualStudio.PlatformUI.DragDropHelper  http://technet.microsoft.com/ru-ru/query/microsoft.visualstudio.platformui.dragdrophelper#

    I sent the ru-ru version because if you use the en-us version it says Microsoft Internal Use only.  :)  I've just started to look at this within the past 10 minutes (well 30 because of previous incident). 

    I've looked into implementing System.Windows.IDataObject and Ole.Interop.IDataObject (since they seem to be used interchangable sometimes).  Just haven't had much luck, was kind of hoping Telerik did something automatically, looks like it does not. 

    If all else fails, just going to try some standard controls and play with that.  I have a feeling that if I can just determine the DropFormat I'll be in the shape I want to be. 

  • 30 April 2012 22:46
    Moderator
     
     Jawab Memiliki Kode

    Hi Chris,

    If you're trying to implement a drag operation from your toolwindow, where this Image Adornment Drop Handler is already set up, you just need to set up the DataObject with the CF_HDROP format or similar.

    For example, the following is a PreviewMouseLeftButtonDown handler for a label on my WPF based toolwindow:

            private void label_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                StringCollection files = new StringCollection();
                files.Add("C:\\Users\\eddo\\Pictures\\Koala25.jpg");
                OleDataObject dataObject = new OleDataObject();
                dataObject.SetFileDropList(files);
                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
            }

    Basically, I'm using a DataObject formatted similar to what you'd see if you were dragging the file from Windows Explorer or the Solution Explorer. As long as you're setting up a DataObject with a format the editor (or one of it's extensions, such as the image adornment extension) recognizes, you should be good to go.

    Sincerely,


    Ed Dore