public DictionaryPropertyEditor(IPropertyEditorParams editorParams, Func <Type, PropertyEditorParams, Widget, object, IEnumerable <IPropertyEditor> > populateEditors) : base(editorParams)
        {
            if (EditorParams.Objects.Skip(1).Any())
            {
                EditorContainer.AddNode(new Widget()
                {
                    Layout = new HBoxLayout(),
                    Nodes  = { new ThemedSimpleText {
                                   Text = "Edit of dictionary properties isn't supported for multiple selection.", ForceUncutText = false
                               } },
                    Presenter = new WidgetFlatFillPresenter(Theme.Colors.WarningBackground)
                });
                return;
            }
            this.populateEditors = populateEditors;
            dictionary           = PropertyValue(EditorParams.Objects.First()).GetValue();
            var addButton = new ThemedAddButton {
                Clicked = () => {
                    if (dictionary == null)
                    {
                        var pi = EditorParams.PropertyInfo;
                        var o  = EditorParams.Objects.First();
                        pi.SetValue(o, dictionary = Activator.CreateInstance <TDictionary>());
                    }
                    if (dictionary.ContainsKey(keyValueToAdd.Key))
                    {
                        AddWarning($"Key \"{keyValueToAdd.Key}\" already exists.", ValidationResult.Warning);
                        return;
                    }
                    using (Document.Current.History.BeginTransaction()) {
                        InsertIntoDictionary <TDictionary, string, TValue> .Perform(dictionary, keyValueToAdd.Key,
                                                                                    keyValueToAdd.Value);

                        ExpandableContent.Nodes.Add(CreateDefaultKeyValueEditor(keyValueToAdd.Key,
                                                                                keyValueToAdd.Value));
                        Document.Current.History.CommitTransaction();
                    }
                    keyValueToAdd.Value = DefaultValue;
                    keyValueToAdd.Key   = string.Empty;
                },
                LayoutCell = new LayoutCell(Alignment.LeftCenter),
            };
            var keyEditorContainer = CreateKeyEditor(editorParams, keyValueToAdd, s => keyValueToAdd.Key = s, addButton);

            ExpandableContent.Nodes.Add(keyEditorContainer);
            ExpandableContent.Nodes.Add(CreateValueEditor(editorParams, keyValueToAdd, populateEditors));
            Rebuild();
            EditorContainer.Tasks.AddLoop(() => {
                if (dictionary != null && ((ICollection)dictionary).Count != pairs.Count)
                {
                    Rebuild();
                }
            });
            var current = PropertyValue(EditorParams.Objects.First());

            ContainerWidget.AddChangeWatcher(() => current.GetValue(), d => {
                dictionary = d;
                Rebuild();
            });
        }
        private void SetValue(KeyValuePair keyValue, TValue value)
        {
            using (Document.Current.History.BeginTransaction()) {
                InsertIntoDictionary <TDictionary, string, TValue> .Perform(dictionary, keyValue.Key, value);

                keyValue.Value = value;
                Document.Current.History.CommitTransaction();
            }
        }
        private void SetKey(KeyValuePair keyValue, string key)
        {
            if (dictionary.ContainsKey(key))
            {
                AddWarning($"Key \"{key}\" already exists.", ValidationResult.Warning);
                return;
            }
            using (Document.Current.History.BeginTransaction()) {
                RemoveFromDictionary <TDictionary, string, TValue> .Perform(dictionary, keyValue.Key);

                keyValue.Key = key;
                InsertIntoDictionary <TDictionary, string, TValue> .Perform(dictionary, key, keyValue.Value);

                Document.Current.History.CommitTransaction();
            }
        }