private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes) { // Get the default property descriptors from the base class PropertyDescriptorCollection propertyDescriptors = base.GetProperties(attributes); HashSet <string> hidePropNames = new HashSet <string>(StringComparer.CurrentCultureIgnoreCase); hidePropNames.Add("CodeSnippetEditor"); hidePropNames.Add("CodeSnippet"); // Get a reference to the model element which is active linked widget of this code snippet VDCodeSnippet source = this.ModelElement as VDCodeSnippet; if (source != null) { // for Reference mode, show code snippet for the active linked widget if (source._Mode.HasFlag(E_CodeSnippetMode.Reference) && source.ActiveLinkedWidget == null) { hidePropNames.Add("CodeSnippet2"); } } // Return the property descriptors for this element List <PropertyDescriptor> list = new List <PropertyDescriptor>(); foreach (PropertyDescriptor desc in propertyDescriptors) { if (!hidePropNames.Contains(desc.Name)) { list.Add(desc); } } return(new PropertyDescriptorCollection(list.ToArray())); }
public override object GetValue(ShapeElement parentShape) { if (parentShape.Diagram != null && parentShape.Diagram.ActiveDiagramView != null && parentShape.Diagram.ActiveDiagramView.DiagramClientView != null) { if (this.HasPendingEdit(parentShape, parentShape.Diagram.ActiveDiagramView.DiagramClientView)) { VDCodeSnippet codeSnippet = parentShape.ModelElement as VDCodeSnippet; if (codeSnippet != null) { return(codeSnippet.CodeSnippet2); } } } return(base.GetValue(parentShape)); }
// when a widget lost its focus, reset the ActiveLinkedWidget of its CodeSnippetEditor protected override void OnSelectionChanging(EventArgs e) { base.OnSelectionChanging(e); ShapeElement shape = this.PrimarySelection as ShapeElement; if (shape == null || shape.ModelElement == null) { return; } VDWidget widgetLosingSelection = shape.ModelElement as VDWidget; if (widgetLosingSelection == null) { return; } VDCodeSnippet codeEditor2Reset = null; if (widgetLosingSelection is VDCodeSnippet) // reference mode codesnippet editor is losting selection { // if new selected shape is Title of code snippet, don't reset it var primaryItem = this.CurrentDesigner.Selection.PrimaryItem; if (primaryItem != null && primaryItem.Shape != null && primaryItem.Shape is VDWidgetTitlePort && primaryItem.Shape.ModelElement != null && ((VDWidgetTitle)primaryItem.Shape.ModelElement).Widget == widgetLosingSelection) { // ... } else if (((VDCodeSnippet)widgetLosingSelection)._Mode.HasFlag(E_CodeSnippetMode.Reference)) { codeEditor2Reset = widgetLosingSelection as VDCodeSnippet; } } else if (widgetLosingSelection.CodeSnippetEditor != null) { VDCodeSnippet newSelectedCodeSnippet = null; // check if the new selected element is EVAACodeSnippet or EVAARawSnippet if (this.CurrentDesigner.Selection != null) { var primaryItem = this.CurrentDesigner.Selection.PrimaryItem; if (primaryItem != null && primaryItem.Shape != null) { if (primaryItem.Shape is VDCodeSnippetShape) { newSelectedCodeSnippet = primaryItem.Shape.ModelElement as VDCodeSnippet; } else if (primaryItem.Shape is VDWidgetTitlePort) // new selection is the Title of code snippet widget { VDWidgetTitle title = primaryItem.Shape.ModelElement as VDWidgetTitle; if (title != null && title.Widget is VDCodeSnippet) { newSelectedCodeSnippet = title.Widget as VDCodeSnippet; } } } } // new selection is the code editor of previously selected widget, // in this case, don't reset the ActiveLinkedWidget of the code viewer if (newSelectedCodeSnippet == null || widgetLosingSelection.CodeSnippetEditor != newSelectedCodeSnippet) { codeEditor2Reset = widgetLosingSelection.CodeSnippetEditor; } } if (codeEditor2Reset != null) { using (Transaction trans = this.DocData.Store.TransactionManager.BeginTransaction("Clear Active Linked Widget")) { codeEditor2Reset.ActiveLinkedWidget = null; trans.Commit(); } } }