public static async void AddSelectionAsChildren(this IObject3D newParent, InteractiveScene scene, IObject3D selectedItem) { if (selectedItem != null) { var selectedItems = scene.GetSelectedItems(); using (new SelectionMaintainer(scene)) { using (selectedItem.Parent.RebuildLock()) { foreach (var item in selectedItems) { newParent.Children.Add(item.Clone()); } newParent.MakeNameNonColliding(); scene.UndoBuffer.AddAndDo( new ReplaceCommand( selectedItems, new[] { newParent })); } await newParent.Rebuild(); } } }
public void WrapSelectedItemAndSelect(InteractiveScene scene) { using (RebuildLock()) { var selectedItems = scene.GetSelectedItems(); if (selectedItems.Count > 0) { // clear the selected item scene.SelectedItem = null; WrapItems(selectedItems); scene.UndoBuffer.AddAndDo( new ReplaceCommand( new List <IObject3D>(selectedItems), new List <IObject3D> { this })); // and select this scene.SelectedItem = this; } } Invalidate(new InvalidateArgs(this, InvalidateType.Properties, null)); }
public async void WrapSelectedItemAndSelect(InteractiveScene scene) { using (RebuildLock()) { var selectedItems = scene.GetSelectedItems(); if (selectedItems.Count > 0) { // clear the selected item scene.SelectedItem = null; using (RebuildLock()) { var clonedItemsToAdd = new List <IObject3D>(selectedItems.Select((i) => i.Clone())); Children.Modify((list) => { list.Clear(); foreach (var child in clonedItemsToAdd) { list.Add(child); } }); } scene.UndoBuffer.AddAndDo( new ReplaceCommand( new List <IObject3D>(selectedItems), new List <IObject3D> { this })); await this.Rebuild(); } } // and select this var rootItem = this.Ancestors().Where(i => scene.Children.Contains(i)).FirstOrDefault(); if (rootItem != null) { scene.SelectedItem = rootItem; } scene.SelectedItem = this; this.Invalidate(InvalidateType.Children); }
public virtual void WrapSelectedItemAndSelect(InteractiveScene scene) { var items = scene.GetSelectedItems(); var parent = items.First().Parent; RebuildLocks parentLock = (parent == null) ? null : parent.RebuilLockAll(); var firstChild = new Object3D(); this.Children.Add(firstChild); // if the items we are replacing are already in a list if (parent != null) { if (scene.UndoBuffer != null) { foreach (var item in items) { firstChild.Children.Add(item.Clone()); } var replace = new ReplaceCommand(items, new[] { this }); scene.UndoBuffer.AddAndDo(replace); } else { parent.Children.Modify(list => { foreach (var item in items) { list.Remove(item); firstChild.Children.Add(item); } list.Add(this); }); } } else // just add them { firstChild.Children.Modify(list => { list.AddRange(items); }); } parentLock?.Dispose(); // and select this var rootItem = this.Ancestors().Where(i => scene.Children.Contains(i)).FirstOrDefault(); if (rootItem != null) { scene.SelectedItem = rootItem; } scene.SelectedItem = this; parent?.Invalidate(new InvalidateArgs(parent, InvalidateType.Children)); }