1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.View
7 using System.Activities.Presentation.Model;
8 using System.Activities.Presentation.Services;
9 using System.Activities.Presentation.Toolbox;
10 using System.Activities.Presentation.Xaml;
13 using System.Windows.Controls;
14 using System.Windows.Input;
15 using System.Windows.Threading;
17 partial class ActivityTypeDesigner : IExpandChild
19 public ActivityTypeDesigner()
21 this.InitializeComponent();
22 this.DragHandle = null;
25 protected override void OnModelItemChanged(object newItem)
27 base.OnModelItemChanged(newItem);
28 if (this.Context.Services.GetService<DisplayNameUpdater>() == null)
30 this.Context.Services.Publish<DisplayNameUpdater>(new DisplayNameUpdater(this.Context));
34 protected override void OnContextMenuLoaded(ContextMenu menu)
36 base.OnContextMenuLoaded(menu);
37 if (null == this.ModelItem.Properties["Implementation"].Value)
39 var toHide = menu.Items.OfType<MenuItem>().Where(p =>
40 p.Command == DesignerView.GoToParentCommand ||
41 p.Command == DesignerView.ExpandCommand);
43 foreach (var item in toHide)
45 item.Visibility = Visibility.Collapsed;
50 void OnAddAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
52 if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
59 void OnEditAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
61 if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
68 void OnDeleteAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
70 if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
77 // the job of this service is to add an attached property on ActivityBuilder called displayName.
78 // this name will be shown in breadcrumb bar.
79 // also whenever the Name property changes
80 // we want to refresh the DisplayName property too ( by calling displayNameProperty.NotifyPropertyChanged())
81 class DisplayNameUpdater
83 AttachedProperty<string> activityBuilderDisplayNameProperty;
84 AttachedProperty<string> activityTemplateFactoryBuilderDisplayNameProperty;
86 public DisplayNameUpdater(EditingContext context)
88 activityBuilderDisplayNameProperty = new AttachedProperty<string>
91 OwnerType = typeof(ActivityBuilder),
92 Getter = (modelItem) => ViewUtilities.GetActivityBuilderDisplayName(modelItem)
94 activityTemplateFactoryBuilderDisplayNameProperty = new AttachedProperty<string>
97 OwnerType = typeof(ActivityTemplateFactoryBuilder),
98 Getter = (modelItem) => ViewUtilities.GetActivityBuilderDisplayName(modelItem)
100 AttachedPropertiesService attachedPropertiesService = context.Services.GetService<AttachedPropertiesService>();
101 attachedPropertiesService.AddProperty(activityBuilderDisplayNameProperty);
102 attachedPropertiesService.AddProperty(activityTemplateFactoryBuilderDisplayNameProperty);
103 context.Services.GetService<ModelService>().ModelChanged += new EventHandler<ModelChangedEventArgs>(ModelChanged);
106 void ModelChanged(object sender, ModelChangedEventArgs e)
108 ModelChangeInfo changeInfo = e.ModelChangeInfo;
110 if (changeInfo != null && changeInfo.ModelChangeType == ModelChangeType.PropertyChanged)
112 Type propertyType = changeInfo.Subject.ItemType;
113 if (changeInfo.PropertyName == "Name")
115 if (propertyType.Equals(typeof(ActivityBuilder)))
117 activityBuilderDisplayNameProperty.NotifyPropertyChanged(changeInfo.Subject);
119 else if (propertyType.Equals(typeof(ActivityTemplateFactoryBuilder)))
121 activityTemplateFactoryBuilderDisplayNameProperty.NotifyPropertyChanged(changeInfo.Subject);
129 public ModelItem ExpandedChild
133 ModelItem modelItemToSelect = null;
134 if (this.ModelItem != null)
136 modelItemToSelect = this.ModelItem.Properties["Implementation"].Value;
138 return modelItemToSelect;