VSPackage:如何创建自定义虚拟节点,例如“引用"节点 [英] VSPackage: How to create a custom virtual node like References node

查看:57
本文介绍了VSPackage:如何创建自定义虚拟节点,例如“引用"节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,
我有一个C#风格的项目,我想向我的项目中添加一些自定义节点,右键单击它们的唯一选择就是添加或删除我已经创建的自定义项目项,因此我希望它像引用"节点一样,因为它不能被删除,重命名,并且只有2个上下文菜单选项.任何有关如何执行此类操作的想法或链接将不胜感激.

感谢

肯尼

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

推荐答案

这实际上比您想象的要容易(并且我有很多自定义容器和节点类型)...
a)创建一个继承自HierarchyNode的容器类(如文件夹).
b)创建一个也继承自HierarchyNode的项目类(如文件).

要使无法从资源管理器重命名,请覆盖"SetEditLabel"方法并抛出NotImplementedException(是的,这是一种相当愚蠢的技术,但这是唯一可行的方法).我还覆盖了"CanDeleteItem"

对于容器类-重写GetProperty()方法并为"VSHPROPID_Expandable"返回true. .Expandable(当然).

看看MPF ProjectBase中的FileNode和FolderNode类,您会发现最终实现起来很容易.

希望如此帮助,
里德·希尔茨

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


这篇关于VSPackage:如何创建自定义虚拟节点,例如“引用"节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆