Microsoft Developer Network > Página Inicial dos Fóruns > Visual Studio Extensibility > VSPackage: How to create a custom virtual node like References node
Fazer uma PerguntaFazer uma Pergunta
 

Resposta PropostaVSPackage: How to create a custom virtual node like References node

  • quinta-feira, 25 de junho de 2009 18:24Kenny Chinn Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hello,
         I have a C# flavored project and I want to add some custom nodes to my project where the only options when you right click on them is to add or remove a custom project item that I have already created, so I want it to be like the References node in that it cannot be deleted renamed and it only has 2 context menu options. Any idea or links on how to do something like this would be greatly appreciated.

    Thanks

    Kenny

Todas as Respostas

  • quinta-feira, 25 de junho de 2009 23:19Reed Shilts Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Resposta Proposta
    This is actually easier than you would think (and I have bunches of custom containers and node types)...
    a) Create a container class (like a folder) which inherits from HierarchyNode.
    b) Create an item class (like a file) which also inherits from HierarchyNode.

    To make it impossible to rename from explorer, override the "SetEditLabel" method and throw NotImplementedException (yes, it's a rather silly technique, but that's the only thing that works).  I also override "CanDeleteItem" and return false.

    For the container class - override the GetProperty() method and return true for "VSHPROPID_Expandable".
    For the item class - don't return true for the ...Expandable (of course).

    Take a look at the FileNode and FolderNode classes in the MPF ProjectBase and you'll see how easy this ends up being.

    Hope this helps,
    Reed SHilts

    • Sugerido como RespostaReed Shilts quinta-feira, 25 de junho de 2009 23:19
    •  
  • quarta-feira, 1 de julho de 2009 17:40Kenny Chinn Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Thanks for the repsonse but we are not using MPF so we cannot use the HierachyNode class as it uses ProjectNode. Is there any way to do this sort of thing using a Flavored C# project?


    Thanks
    Kenny
  • quinta-feira, 2 de julho de 2009 1:51Nancy ShaoMSFT, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Contém Código

    Hi Kenny,

    Based on my  understanding, you can use Project Template to add a new ProjectNode as Reference Node in treeview. You can export a C# project template by File>Export Template... and  then customize your project template, please refer to following code snippet about how to add a new folder note(named NewFolder1) in project template:

    <TemplateContent>
        <Project TargetFileName="ConsoleApplication.csproj" File="ConsoleApplication.csproj" ReplaceParameters="true">
          <Folder Name="NewFolder1" TargetFolderName="NewFolder1" />
          <ProjectItem ReplaceParameters="true" TargetFileName="Program.cs">Program.cs</ProjectItem>
          <Folder Name="Properties" TargetFolderName="Properties">
            <ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
          </Folder>
        </Project>
      </TemplateContent>
    
    For more information, please see : Create Reusable Project And Item Templates For Your Development Team.

    If I misunderstood you, or you have any questions, please let me know.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • quinta-feira, 2 de julho de 2009 14:14Kenny Chinn Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Hi Nancy,
       Thanks for the response, but I think you misunderstood me. I need to create a custom folder in which all the user can do is add or remove a custom project item I have created. I want it to be sort of like the References folder, except you can add my custom project items instead of references. Does that make senese? If you have any questions for me please let me know. 

    Thanks
    Kenny