1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.State
6 using System.Collections;
8 using System.Activities.Presentation.PropertyEditing;
9 using System.Activities.Presentation.Internal.PropertyEditing.Model;
12 // Container storing the names of properties the value editors of which
13 // are in ExtendedPinned ActiveEditMode. We persist this information
14 // across domain reloads and view changes.
16 internal class PropertyActiveEditModeStateContainer : IStateContainer
19 public static readonly PropertyActiveEditModeStateContainer Instance = new PropertyActiveEditModeStateContainer();
21 private Hashtable _expandedPropertyEditors = new Hashtable();
22 private PropertyActiveEditModeStateContainer()
27 // Gets the last stored ActiveEditMode for the specified property
29 // <param name="property">PropertyEntry to look up</param>
30 // <returns>Last stored ActiveEditMode for the specified property</returns>
31 public PropertyContainerEditMode GetActiveEditMode(PropertyEntry property)
33 return _expandedPropertyEditors.ContainsKey(ModelUtilities.GetCachedSubPropertyHierarchyPath(property)) ?
34 PropertyContainerEditMode.ExtendedPinned :
35 PropertyContainerEditMode.Inline;
39 // Stores the current ActiveEditMode for the specified property
41 // <param name="property">Property to key off of</param>
42 // <param name="editMode">ActiveEditMode value to store</param>
43 public void StoreActiveEditMode(PropertyEntry property, PropertyContainerEditMode editMode)
45 string path = ModelUtilities.GetCachedSubPropertyHierarchyPath(property);
47 // We only care about storing the ExtendedPinned state. Everything
48 // else is transitory and shouldn't be persisted.
50 if (editMode == PropertyContainerEditMode.ExtendedPinned)
52 _expandedPropertyEditors[path] = null;
56 _expandedPropertyEditors.Remove(path);
62 public object RetrieveState()
64 if (_expandedPropertyEditors.Count == 0)
69 bool firstTime = true;
70 StringBuilder sb = new StringBuilder();
71 foreach (string propertyPath in _expandedPropertyEditors)
73 sb.Append(propertyPath);
84 public void RestoreState(object state)
86 string stateString = state as string;
87 if (stateString == null)
92 string[] paths = stateString.Split(';');
93 foreach (string path in paths)
95 if (string.IsNullOrEmpty(path))
99 _expandedPropertyEditors[path] = null;