[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Selection / CategoryContainerSelectionPathInterpreter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Selection 
5 {
6     using System.Diagnostics;
7     using System.Text;
8     using System.Windows;
9
10     using System.Activities.Presentation.PropertyEditing;
11
12     using System.Activities.Presentation.Internal.PropertyEditing.State;
13
14     // <summary>
15     // Helper class that knows how to construct and interpret SelectionPaths leading
16     // to CategoryContainers.
17     // </summary>
18     internal class CategoryContainerSelectionPathInterpreter : ISelectionPathInterpreter 
19     {
20
21         private static CategoryContainerSelectionPathInterpreter _instance = new CategoryContainerSelectionPathInterpreter();
22         private CategoryContainerSelectionPathInterpreter() 
23         {
24         }
25         public static CategoryContainerSelectionPathInterpreter Instance 
26         { get { return _instance; } }
27
28         public string PathTypeId 
29         { get { return "Cider_CategoryPath"; } }
30
31         // <summary>
32         // Creates an instance of SelectionPath to the specified category container's
33         // basic or advanced sections that this class knows how to interpret.
34         // </summary>
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) 
41         {
42             StringBuilder path = new StringBuilder(PersistedStateUtilities.Escape(categoryName));
43             if (isAdvanced)
44             {
45                 path.Append(",Advanced");
46             }
47
48             return new SelectionPath(PathTypeId, path.ToString());
49         }
50
51         // ISelectionPathInterpreter Members
52
53         public DependencyObject ResolveSelectionPath(CategoryList root, SelectionPath path, out bool pendingGeneration) 
54         {
55             pendingGeneration = false;
56             if (path == null || !string.Equals(PathTypeId, path.PathTypeId)) 
57             {
58                 Debug.Fail("Invalid SelectionPath specified.");
59                 return null;
60             }
61
62             if (root == null) 
63             {
64                 Debug.Fail("No CategoryList specified.");
65                 return null;
66             }
67
68             string[] pathValues = path.Path.Split(',');
69             string categoryName = PersistedStateUtilities.Unescape(pathValues[0]);
70             bool isAdvanced = pathValues.Length == 2;
71
72             CategoryEntry category = root.FindCategory(categoryName);
73             if (category == null)
74             {
75                 return null;
76             }
77
78             DependencyObject categoryVisual = root.FindCategoryEntryVisual(category);
79             if (categoryVisual == null)
80             {
81                 return null;
82             }
83
84             DependencyObject searchStart;
85
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.
89             if (!isAdvanced)
90             {
91                 searchStart = categoryVisual;
92             }
93             else
94             {
95                 searchStart = VisualTreeUtils.GetNamedChild<FrameworkElement>(categoryVisual, "PART_AdvancedExpander");
96             }
97
98             return PropertySelection.FindNeighborSelectionStop<DependencyObject>(searchStart, SearchDirection.Next);
99         }
100
101     }
102 }