DSL资源管理器中的永久节点

时间:2009-12-16 14:48:04

标签: visual-studio visual-studio-2008 dsl vsx dsl-tools

在我的自定义DSL工具中,我想在其资源管理器中找到一个无法删除的节点。除此之外,我希望它像一个常规节点。基本上我想要的是像DSL Explorer中的 Xml序列化行为这样的节点:

Xml Serialization Behavior context menu illustration http://img31.imageshack.us/img31/740/xmlserializerbehavior.png

通过在Microsoft.VisualStudio.Modeling.Sdk.DslDefinition.dll程序集中的XmlSerializationDefinitionSerializer类上使用Reflector,我发现它只是DomainClass的衍生物,因此没有任何(显然)特殊的。

我已经定义了一个充当节点的DomainClass,右键单击它让我按照我想要的方式添加子节点,我只是无法摆脱删除菜单选项:

Delete context menu item illustration http://img705.imageshack.us/img705/9033/validators.png

我已经尝试了任何我能想到的东西......我已经将属性设置器设置为私有,它绕过它,我将多重性设置为1..1,除了给出之外没有任何影响“Validators”节点丢失时的错误...我已经查看了DomainClass和根模型与Validators Domain Class之间的DomainRelationship的所有属性,但它们似乎都没有解决这个问题。我还查看了DSL Explorer窗口中Explorer Behavior节点中的所有内容。我完全难过了。有人知道怎么做吗?

1 个答案:

答案 0 :(得分:1)

好的,经过相当多的广泛研究后,我发现了如何做到这一点。这就是我所做的,以防其他人在将来需要我的问题的答案。您必须为DSL模型的DesignerExplorer创建一个部分类(它位于DslPackage项目中,由ModelExplorer.tt文件创建)并将以下代码放入其中:

internal partial class MyDesignerExplorer
{
    /// <summary>
    /// Override to stop the "Delete" command appearing for
    /// Validators.
    /// </summary>
    protected override void ProcessOnStatusDeleteCommand( MenuCommand command )
    {
        // Check the selected items to see if they contain
        // Validators.
        if( this.SelectedElement.GetType()== typeof( Validators ) ) 
        {
            // Disable the menu command
            command.Enabled = false;
            command.Visible = false;
        }
        else
        {
            // Otherwise, delegate to the base method.
            base.ProcessOnStatusDeleteCommand( command );
        }
    }
}
相关问题