/// <summary> /// Discard any current active editable entry. /// </summary> public static void DiscardActiveNewEntry() { if (ActiveControlID == Guid.Empty) { return; } s_ActiveContext = null; Object.DestroyImmediate(s_NewEntry); s_NewEntry = null; NewEntryObject = null; NewEntryKeyProperty = null; NewEntryValueProperty = null; }
/// <summary> /// Activates the 'new entry' editor for a specified control. /// </summary> /// <param name="context">Context of the editable entry.</param> public static void SetActiveNewEntry(IEditableOrderedDictionaryContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (context.ControlID == Guid.Empty) { throw new ArgumentException("Invalid control identifier.", "context"); } if (!typeof(OrderedDictionary).IsAssignableFrom(context.OrderedDictionaryType)) { throw new ArgumentException("Not a valid ordered dictionary type.", "context"); } if (context.ControlID == ActiveControlID) { return; } DiscardActiveNewEntry(); s_NewEntry = CreateEditableEntryObject(context.OrderedDictionaryType); NewEntryObject = new SerializedObject(s_NewEntry); var dictionaryProperty = NewEntryObject.FindProperty("dictionary"); var keysProperty = dictionaryProperty.FindPropertyRelative("keys"); var valuesProperty = dictionaryProperty.FindPropertyRelative("values"); // Add a single key/value entry to the editable entry. NewEntryObject.Update(); keysProperty.arraySize = 1; valuesProperty.arraySize = 1; NewEntryObject.ApplyModifiedPropertiesWithoutUndo(); // Get a `SerializedProperty` for the key and value properties. NewEntryKeyProperty = keysProperty.GetArrayElementAtIndex(0); NewEntryValueProperty = valuesProperty.GetArrayElementAtIndex(0); NewEntryListAdaptor = context.CreateListAdaptor(dictionaryProperty); s_ActiveContext = context; }