1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Selection
6 using System.Diagnostics;
10 using System.Activities.Presentation.PropertyEditing;
12 using System.Activities.Presentation.Internal.PropertyEditing.State;
15 // Helper class that knows how to construct and interpret SelectionPaths leading
16 // to CategoryContainers.
18 internal class CategoryContainerSelectionPathInterpreter : ISelectionPathInterpreter
21 private static CategoryContainerSelectionPathInterpreter _instance = new CategoryContainerSelectionPathInterpreter();
22 private CategoryContainerSelectionPathInterpreter()
25 public static CategoryContainerSelectionPathInterpreter Instance
26 { get { return _instance; } }
28 public string PathTypeId
29 { get { return "Cider_CategoryPath"; } }
32 // Creates an instance of SelectionPath to the specified category container's
33 // basic or advanced sections that this class knows how to interpret.
35 // <param name="categoryName">Name of the category</param>
36 // <param name="isAdvanced">True if the path should lead to the advanced section,
37 // false otherwise.</param>
38 // <returns>A new instance of SelectionPath to the specified section of the specified
39 // category container.</returns>
40 public SelectionPath ConstructSelectionPath(string categoryName, bool isAdvanced)
42 StringBuilder path = new StringBuilder(PersistedStateUtilities.Escape(categoryName));
45 path.Append(",Advanced");
48 return new SelectionPath(PathTypeId, path.ToString());
51 // ISelectionPathInterpreter Members
53 public DependencyObject ResolveSelectionPath(CategoryList root, SelectionPath path, out bool pendingGeneration)
55 pendingGeneration = false;
56 if (path == null || !string.Equals(PathTypeId, path.PathTypeId))
58 Debug.Fail("Invalid SelectionPath specified.");
64 Debug.Fail("No CategoryList specified.");
68 string[] pathValues = path.Path.Split(',');
69 string categoryName = PersistedStateUtilities.Unescape(pathValues[0]);
70 bool isAdvanced = pathValues.Length == 2;
72 CategoryEntry category = root.FindCategory(categoryName);
78 DependencyObject categoryVisual = root.FindCategoryEntryVisual(category);
79 if (categoryVisual == null)
84 DependencyObject searchStart;
86 // For basic section, start at the root.
87 // For advanced section, start at the advanced expander.
88 // The next SelectionStop in both cases will be the section header SelectionStop.
91 searchStart = categoryVisual;
95 searchStart = VisualTreeUtils.GetNamedChild<FrameworkElement>(categoryVisual, "PART_AdvancedExpander");
98 return PropertySelection.FindNeighborSelectionStop<DependencyObject>(searchStart, SearchDirection.Next);