Задайте вопросЗадайте вопрос
 

Предложенный ответVSPackage: How to create a custom virtual node like References node

Все ответы

  • 25 июня 2009 г. 23: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 25 июня 2009 г. 23:19
    •  
  • 1 июля 2009 г. 17: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
  • 2 июля 2009 г. 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.
  • 2 июля 2009 г. 14: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