locked
how to handle delete command for a custom file type RRS feed

  • Question

  • HI,

    I have created a new Itemtemplate to add a file (custom file extension). Now whenever user selects this item from solution explorer and do delete, i want to capture that event and do some custom task. Can i handle delete event?

     

    Regards

     

     

     


    singhhome
    Monday, October 3, 2011 5:02 PM

Answers

All replies

  • Hi Singhhome,

    As far as I know you need get the IVsHierarchy of your project and advise the IVsHierarchyEvents to listen the item actions. To handle the delete event, you need to handle IVsHierarchyEvents.OnItemDeleted method.

    Regards,

    Yi

     


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 4, 2011 4:55 AM
  • From my package(which adds context menu to my custom file extension) i have added advisehierarchyEvents(), but

    1. my handler is invoked after the VS shows messagee, "file will be deleted permanently".  Can i restrict not to show this standard dialog?

    2. Even if from my handler if i return !S_OK, the file still gets deleted. Is there a way to restrict(cancel the event) so that file doesn't get deleted.

     

    Regards


    singhhome
    Tuesday, October 4, 2011 6:30 PM
  • Hi Singhhome,

    The onItemDeleted event announce the client when the item has already been deleted. Therefore you are unable to restrict the delete action from this event.

    if you want your package to use its own deletion prompt to delete the items, you may take a look IVsHierarchyDeleteHandler Interface and IVsHierarchyDeleteHandler2 Interface.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, October 5, 2011 2:46 AM
  • Can you please provide any steps/samples on how to use IVSHierarchyDeleteHandler IVSHierarchyDeleteHandler2 interfaces?

    Is there a way to associate it with my custom file type/Item template?

    Regards


    singhhome
    Wednesday, October 5, 2011 6:02 PM
  • Hi Singhhome,

    I suggest you take a look IronPython Integrated Shell sample which implements the IVSHierarchyDeleteHandler interface for Python project.

    Sample URL: http://code.msdn.microsoft.com/IPyIsolatedShell

    Regards,
    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Yi Feng Li Thursday, October 6, 2011 3:59 AM Miss the link of the sample
    • Marked as answer by singhhome Friday, October 7, 2011 6:02 PM
    Thursday, October 6, 2011 3:58 AM
  • You have a couple of options here.

    1. Create your own project subtype, and reimplement these interfaces so as to effectively override the default behavior.

    2. Intercept the command before the hierarchy gets it, and I"m not sure if this can be done. You'll have to experiment with implementing a priority command target to see if you can intercept and handle the delete command before the project hierarchy gets it.

    Sincerely,


    Ed Dore
    Thursday, October 6, 2011 6:32 PM