2009-12-16 41 views
1

在我的自定義DSL工具中,我想要一個無法刪除的資源管理器中的節點。除此之外,我希望它像一個常規節點。基本上我想要的是像在DSL資源管理器中XML序列化行爲節點:DSL Explorer中的永久節點

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

通過使用上的Microsoft.VisualStudio.Modeling.Sdk.DslDefinition.dll組裝我的XmlSerializationDefinitionSerializer類反射發現它只是DomainClass的一個衍生物,所以沒有什麼(顯然)特別的。

我已經定義了一個作爲節點的DomainClass,並且右鍵點擊它可以讓我按照我希望的方式添加子節點,但我無法擺脫Delete菜單選項:

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

我已經試過什麼,我能想到的......我給自己定的屬性setter給私人,它會解決這個問題,我已經設置了多重性爲1..1,有沒有效果,而不是在「Validators」節點丟失時給出錯誤......我查看了DomainClass和DomainRelationship在根模型和Validators Domain Class之間的所有屬性,它們都沒有處理這個問題。我還查看了「DSL資源管理器」窗口的「瀏覽器行爲」節點中的所有內容。我完全被難住了。有人知道怎麼做這個嗎?

回答

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); 
     } 
    } 
} 
+0

+1。做得很好。我喜歡DSL工具,它很好,你已經回答了這個問題。 – 2009-12-17 22:40:57