1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Views
7 using System.Collections.Generic;
9 using System.Activities.Presentation.Model;
10 using System.Activities.Presentation.PropertyEditing;
12 using System.Activities.Presentation.Internal.PropertyEditing.Model;
13 using System.Activities.Presentation.Internal.PropertyEditing.Selection;
16 // IPropertyViewManager we use to display an alphabetical list of properties
18 internal class AlphabeticalViewManager : IPropertyViewManager
21 public static readonly AlphabeticalViewManager Instance = new AlphabeticalViewManager();
22 private AlphabeticalViewManager()
27 // AlphabeticalViewManager doesn't show category headers
29 public bool ShowCategoryHeaders
30 { get { return false; } }
33 // AlphabeticalViewManager always uses PropertyEntryNameComparer instance
35 private IComparer<PropertyEntry> PropertyComparer
38 return PropertyEntryNameComparer.Instance;
42 // IPropertyViewManager Members
45 // Add a property into the correct category within the specified CategoryList.
47 // <param name="propertySet">Specified property (passed in as a set for multi-select scenarios)</param>
48 // <param name="propertyName">Name of the current property (perf optimization)</param>
49 // <param name="categoryList">CategoryList instance to populate</param>
50 // <returns>Wrapped ModelPropertyEntry for the specified propertySet</returns>
51 public ModelPropertyEntry AddProperty(IEnumerable<ModelProperty> propertySet, string propertyName, CategoryList categoryList)
53 string categoryName = System.Activities.Presentation.Internal.Properties.Resources.PropertyCategoryAllProperties;
54 ModelCategoryEntry category = categoryList.FindCategory(categoryName) as ModelCategoryEntry;
56 bool reuseEntries = ExtensibilityAccessor.IsEditorReusable(propertySet);
57 if (reuseEntries && category != null)
59 ModelPropertyEntry foundProperty;
60 if ((foundProperty = (ModelPropertyEntry)category[propertyName]) != null) {
61 if (foundProperty.PropertyType != null && foundProperty.PropertyType.Equals(System.Activities.Presentation.Internal.PropertyEditing.Model.ModelUtilities.GetPropertyType(propertySet)))
63 // Found a match for the property, so reuse it
65 bool oldIsBrowsable = foundProperty.IsBrowsable;
67 foundProperty.SetUnderlyingModelProperty(propertySet);
69 // If the IsBrowsable or IsAdvanced value of the property changed,
70 // refresh the property within the category, because how and whether
71 // this property should be rendered may have changed.
72 // Note that refreshing a selected property also nullifies its stickiness
73 // (ie. it resets CategoryList.PropertySelectionMode)
74 if (oldIsBrowsable != foundProperty.IsBrowsable)
76 category.Refresh(foundProperty, category.BasicProperties, this.PropertyComparer);
86 category = new ModelCategoryEntry(categoryName);
87 categoryList.InsertAlphabetically(category);
90 ModelPropertyEntry property = new ModelPropertyEntry(propertySet, null);
91 category.Add(property, category.BasicProperties, this.PropertyComparer);
96 // Scans the list of categories in the specified CategoryList and returns a set of
97 // CategoryEditor types that should be present in the list based on the properties
100 // <param name="ownerType">Type of the currently displayed item</param>
101 // <param name="categoryList">CategoryList to examine</param>
102 // <returns>Set of expected CategoryEditor types</returns>
103 public Dictionary<Type, object> GetCategoryEditors(Type ownerType, CategoryList categoryList)
105 // No category editors in alpha-view
106 return new Dictionary<Type, object>();
110 // Returns a SelectionPath pointing to the first visible property
111 // in the list or null if no such property exists.
113 // <param name="categoryList">CategoryList for reference</param>
114 // <returns>SelectionPath pointing to the first visible property
115 // in the list or null if no such property exists.</returns>
116 public SelectionPath GetDefaultSelectionPath(CategoryList categoryList)
118 if (categoryList.Count > 0)
120 CategoryEntry firstCategory = categoryList[0];
122 if (firstCategory != null)
124 foreach (ModelPropertyEntry firstProperty in firstCategory.Properties)
126 if (firstProperty != null && firstProperty.IsBrowsable && firstProperty.MatchesFilter)
128 return PropertySelectionPathInterpreter.Instance.ConstructSelectionPath(firstProperty);
137 // Blend's CollectionEditor compatibility APIs
140 // Since Blend's API uses PropertyEntries instead of ModelProperties, we need
141 // to provide methods that consume those instead. Ideally, with the two code
142 // bases merged, we wouldn't need these at all.
146 // Gets the category name of the specified property
148 // <param name="property">Property to examine</param>
149 // <returns>Category name the property belongs to.</returns>
150 public string GetCategoryName(PropertyEntry property)
152 return System.Activities.Presentation.Internal.Properties.Resources.PropertyCategoryAllProperties;
156 // Adds the specified property into the specified category.
158 // <param name="property">Property to add</param>
159 // <param name="category">Category to populate</param>
160 public void AddProperty(PropertyEntry property, ModelCategoryEntry category)
162 category.Add(property, category.BasicProperties, this.PropertyComparer);