locked
Extension for move/copy files RRS feed

  • Question

  • Hi

    Do you know an extension which asks if I am sure to move/copy a file within Solution Explorer? I really want to have this functionality because I have difficult times when I do this action accidentally and have ankhSvn.

     

    Thanks


    Out of Memory HD Office - En
    HD Office - Bg
    Monday, June 28, 2010 9:14 PM

Answers

  • try VSCommands 2010: http://visualstudiogallery.msdn.microsoft.com/en-us/d491911d-97f3-4cf6-87b0-6a2882120acf
    • Marked as answer by mynkow Thursday, July 15, 2010 6:58 AM
    Wednesday, July 14, 2010 9:21 PM
  • There is no way to do this short of creating a project flavor (aka project subtype). The drag/drop operation you see in the Solution Explorer is implemented each each project system. Specifically, the project system implements IVsHierarchyDropDataSource (think of this as the object being dragged) and  IVsHierarchyDropDataTarget (representing the object that gets the drop). The existing project types that I'm aware of, do not fire any sort of events that would allow you to cancel a drop operation.

    You would essentially have to aggregate the existing project system (only supported by the VB and C# project systems), and then implement your own implementation of IVsHierarchyDropDataSource and reject the drop (or prompt the user) in your OnBeforeDropNotify.

    Essentially, this means you'd have to implement a custom package with the VS SDK, implement a project subtype, and tweak the projects you are interested in, so that they used your project type instead of the default one.

    So unfortunately the short answer is there probably isn't an extension that provides for this. You'd have to build your own, and it would be quite a bit of work.

    Sincerely,

     


    Ed Dore
    Friday, July 2, 2010 5:10 AM

All replies

  • Hello,

    VS automation extensibility enable you to subscribe the command event, which could help. See the following code snippet that does the trick.

            CommandEvents cmdEvents;

            public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)

            {

                handled = false;

                if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)

                {

                    if(commandName == "AddInCutAndMove.Connect.AddInCutAndMove")

                    {

                        //{5EFC7975-14BC-11CF-9B2B-00AA00573819} 16 is the command id of Cut command.

                        cmdEvents = _applicationObject.Events.get_CommandEvents("{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 16);

                        cmdEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(cmdEvents_BeforeExecute);

                        handled = true;

                        return;

                    }

                }

            }

     

            void cmdEvents_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)

            {

                EnsureDialog ensureDialog = new EnsureDialog();

                //Check whether current active window is solution explorer

                if (_applicationObject.ActiveWindow.Caption.StartsWith("Solution Explorer"))

                {

                    if (ensureDialog.ShowDialog() == DialogResult.No)

                    {

                        //If the user select no, set CancelDefault to true, to cancel the cut command.

                        CancelDefault = true;

                    }

                }

            }

    Hope this helps.

    Thanks

    Chao

    Wednesday, June 30, 2010 3:44 AM
  • Thanks Chao

     

    I am not familiar with creating addins but I managed to start this. There are few problems that I cannot resolve.

     

    1) To get the plugin works I have to click on Tools\MyPlugin and this will register the event handler. How can I do this automatically?

    2) What are the codes (16 is for Cut) for Copy, Paste, MoveItemWithMouse, CopyItemWithMouse?

     

    Thank you once again.

    ==================

    Best Regards

    mynkow


    Out of Memory HD Office - En
    HD Office - Bg
    Thursday, July 1, 2010 10:49 AM
  • Hello,

    1.    You need to put the code in onconnection method, and make your add-in autoload(http://msdn.microsoft.com/en-us/library/xwdatdwh(VS.80).aspx).

    2.    Please see this link for getting the command and commandID of copy and move.

    See this link http://blogs.msdn.com/b/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx

    But for mouse drag and drop, there may be no way to capture this.

    Thanks

    Chao

    Friday, July 2, 2010 2:01 AM
  • There is no way to do this short of creating a project flavor (aka project subtype). The drag/drop operation you see in the Solution Explorer is implemented each each project system. Specifically, the project system implements IVsHierarchyDropDataSource (think of this as the object being dragged) and  IVsHierarchyDropDataTarget (representing the object that gets the drop). The existing project types that I'm aware of, do not fire any sort of events that would allow you to cancel a drop operation.

    You would essentially have to aggregate the existing project system (only supported by the VB and C# project systems), and then implement your own implementation of IVsHierarchyDropDataSource and reject the drop (or prompt the user) in your OnBeforeDropNotify.

    Essentially, this means you'd have to implement a custom package with the VS SDK, implement a project subtype, and tweak the projects you are interested in, so that they used your project type instead of the default one.

    So unfortunately the short answer is there probably isn't an extension that provides for this. You'd have to build your own, and it would be quite a bit of work.

    Sincerely,

     


    Ed Dore
    Friday, July 2, 2010 5:10 AM
  • So, there is no way to do this simply because I have to convert all my projects to the custom one. This is not acceptable :( I am disappointed.

    Thanks

     

    Have a nice day


    Out of Memory HD Office - En
    HD Office - Bg
    Friday, July 2, 2010 7:31 AM
  • try VSCommands 2010: http://visualstudiogallery.msdn.microsoft.com/en-us/d491911d-97f3-4cf6-87b0-6a2882120acf
    • Marked as answer by mynkow Thursday, July 15, 2010 6:58 AM
    Wednesday, July 14, 2010 9:21 PM
  • omg, thank you so much Mokosh

    Out of Memory HD Office - En
    HD Office - Bg
    Thursday, July 15, 2010 6:58 AM