Microsoft Developer Network > 포럼 홈 > Visual Studio Extensibility > VSPackage: How to create a custom virtual node like References node
질문하기질문하기
 

제안된 답변VSPackage: How to create a custom virtual node like References node

  • 2009년 6월 25일 목요일 오후 6:24Kenny Chinn 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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

모든 응답

  • 2009년 6월 25일 목요일 오후 11:19Reed Shilts 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     제안된 답변
    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

    • 답변으로 제안됨Reed Shilts 2009년 6월 25일 목요일 오후 11:19
    •  
  • 2009년 7월 1일 수요일 오후 5:40Kenny Chinn 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2009년 7월 2일 목요일 오전 1:51Nancy ShaoMSFT, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음

    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.
  • 2009년 7월 2일 목요일 오후 2:14Kenny Chinn 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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