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

发布于 2024-08-15 05:46:41 字数 936 浏览 9 评论 0原文

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

Xml 序列化行为上下文菜单图 http://img31.imageshack.us/img31/740/xmlserializerbehavior.png

通过在 Microsoft.VisualStudio.Modeling.Sdk.DslDefinition 中的 XmlSerializationDefinitionSerializer 类上使用 Reflector。我发现它只是 DomainClass 的派生类,因此(显然)没有什么特别之处。

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

删除上下文菜单项插图 http://img705.imageshack.us/img705/9033/validators.png

我已经尝试了我能想到的任何方法...我已将属性设置器设置为私有,它解决了这个问题,我已将多重性设置为 1..1,除了在“验证器”节点丢失...我已经查看了 DomainClass 以及根模型和验证器域类之间的 DomainRelationship 的所有属性,但它们似乎都没有处理这个问题。我还查看了 DSL Explorer 窗口中 Explorer Behaviour 节点中的所有内容。我完全被难住了。有人知道该怎么做吗?

In my custom DSL tool I want a node in its Explorer which cannot be removed. Other than that, I want it to be like a regular node. Basically what I want is a node like the Xml Serialization Behavior in the DSL Explorer:

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

Through using Reflector on the XmlSerializationDefinitionSerializer class in the Microsoft.VisualStudio.Modeling.Sdk.DslDefinition.dll assembly I've discovered that it's just a derivative of DomainClass, so there's nothing (obviously) special about it.

I've defined a DomainClass that functions as the node, and right clicking it lets me add sub-nodes just the way I want it to work, I just can't get rid of that Delete menu choice:

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

I've tried anything that I can think of... I've set the property setter to private, it gets around that, I've set the multiplicity to 1..1, that has no effect other than giving errors when the "Validators" node is missing... I've looked at all the properties both for the DomainClass and for the DomainRelationship between the root model and the Validators Domain Class and none of them seem to deal with this. I've also looked at everything in the Explorer Behavior node in the DSL Explorer window. I'm completely stumped. Does anybody know how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2024-08-22 05:46:41

好吧,经过大量广泛的研究,我找到了如何做到这一点。这就是我所做的,以防其他人将来需要我的问题的答案。您必须为 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 );
        }
    }
}

Okay, after quite a bit of extensive research, I found out how to do this. Here's what I did, in case anybody else needs the answer to my question in the future. You must create a partial class for your DSL model's DesignerExplorer (It's in the DslPackage project, created by the ModelExplorer.tt file) and put the following code in it:

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 );
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文