locked
Custom Folder's Hierarchy RRS feed

  • Question

  • Hi All,

    Background:
    I'm working with VSIP/MPF interfaces & classes. I'm making a function that adds items programmatically into the running project. To be more organized, these new items are added to a custom folder in a project.
    1. If the folder doesn't exist yet, this also means adding the first item, a folder should be created and then should be added to the project. Then the first item is added to that folder.
    2. If the folder exists, this also means there is at least one item inside that folder, then add new item to that existing folder.
    3. I use IVsProject3.AddItem() method to add item to project.

    Problem:
    1. I tried to add the first item to the folder, but instead the item is added to the project. I realize that I use the project's hierarchy to add the item.

    Questions:
    1. How can I get the hierarchy of a folder if it is empty? What I mean here is to get the nested hierarchy so I can put my item there.
    2. Or does anyone have better idea to approach my target above? I'm only interested with VSIP/MPF interfaces.

    I've been trying to look at the SolutionHierarchyTraversal sample. But I'm not sure if it covers what I need (or probably I don't know ). TIA.


    Regards,
    Friday, February 16, 2007 3:25 PM

All replies

  • Hi Herry,

    According to the documentation, it appears that the first parameter to that IVsProject3.AddItem call is ignored. I'm not really sure how accurate that information is though. Is the project system in question yours, or is this by chance just a C#, VB or C++ project you're adding the folder to?

    I'm kind of curious as to why you are not using a .vstemplate wizard to do this. In most cases I've seen, wizards are the preferred way to add additional items to a project. Directly manipulating a project hierarchy via the underlying VSIP interfaces can be tricky, especially if you aren't the implementor of the project hierarchy.

    Once you have a .vstemplate wizard, you can use the DTE2.LaunchWizard method to launch the wizard to add a series of items to a project, and locate them in a subdirectory if desired. Or you can make them visible such that they appear in the Add Item dialog, so that the user can add them as they see fit.

    Sincerely,

    Monday, February 19, 2007 11:55 PM
  • Hi Ed,

    I'm sorry, but can you explain your first question again? I'm not really clear with what you asked.

    For your curiosity, I'm making a DSL package for a specific small sub-project in my company. And since it is a DSL so I designed it as simple as possible, with the smallest scope I can get, but of course powerful to tackle my project's specific problem.

    Indeed to use a customized template in order to add items is way much easier. But as I explained above, the simplicity of my DSL, it is no use and does not make sense to show the Add Item template if the user has to choose only one template (which is exactly only one), and even I hard-coded the name for the new item. In this case, I made a system that forces the user to make no major mistake, and to make clear between the gap of my system. This is as far as I can tell.


    Regards,
    Tuesday, February 20, 2007 9:17 AM