views:

59

answers:

1

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

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

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?

+1  A: 

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 );
        }
    }
}
Alex
+1. Nicely done. I love DSL tools and its good that you've answered the question.
John Buchanan