/// <summary> /// Replace an existing item with a new one /// </summary> /// <param name="index">Where to do the replacement</param> /// <param name="newItem">The new item</param> public void ReplaceItem(int childIndex, StringTreeViewItem newItem) { if (children == null) { return; } // find location of the item with given index // (should be the same, but just to make sure...) int index = children.FindIndex(child => ((StringTreeViewItem)child).Index == childIndex); if (index == -1) { throw new ArgumentException("Provided index does not exist inside the array."); } children[index] = newItem; newItem.parent = this; newItem.Index = index; // NOTE: no child repair needed here treeView.Reload(); treeView.SelectItem(newItem); treeView.ExpandItem(newItem); }
/// <inheritdoc/> public override void DropItemAt(int index, StringTreeViewItem item) { children.Insert(index, item); item.parent = this; item.Key = null; RepairChildStructure(); treeView.Reload(); treeView.SelectItem(item); }
protected override void SelectionChanged(IList <int> selectedIds) { if (selectedIds.Count == 0) { activeItem = null; return; } activeItem = FindItem(selectedIds[0], rootItem) as StringTreeViewItem; if (activeItem.JsonType == JsonType.NotJson) { activeItem = null; } }
/// <inheritdoc/> public override void DropItemAt(int index, StringTreeViewItem item) { if (item.Key == null || ContainsKey(item.Key)) { item.Key = GenerateNewKey(); } children.Insert(index, item); item.parent = this; RepairChildStructure(); treeView.Reload(); treeView.SelectItem(item); }
protected override void SetupDragAndDrop(SetupDragAndDropArgs args) { if (args.draggedItemIDs.Count == 0) { return; } StringTreeViewItem item = FindItem(args.draggedItemIDs[0], rootItem) as StringTreeViewItem; if (item == null || item.JsonType == JsonType.NotJson) { return; } DragAndDrop.PrepareStartDrag(); DragAndDrop.SetGenericData(typeof(StringTreeViewItem).FullName, item); DragAndDrop.StartDrag(item.Label + item.StringValue); }
/// <summary> /// Replace an existing field with a new one /// </summary> /// <param name="key">Key of the field</param> /// <param name="newItem">The new item to put here</param> public void ReplaceField(string key, StringTreeViewItem newItem) { if (children == null) { return; } int index = children.FindIndex(child => (child as StringTreeViewItem)?.Key == key); if (index == -1) { throw new ArgumentException("Provided key does not exist inside the object."); } children[index] = newItem; newItem.parent = this; newItem.Key = key; // NOTE: no child repair needed here treeView.Reload(); treeView.SelectItem(newItem); treeView.ExpandItem(newItem); }
/// <summary> /// Drop an item at a given child index /// </summary> public virtual void DropItemAt(int index, StringTreeViewItem item) { // overriden by containers }