private void Input_LostFocus(object sender, RoutedEventArgs e) { Input.Text = _chain.Name; Input.Opacity = 0; Input.IsHitTestVisible = false; List <string> r = (from i in Enumerable.Range(0, Input_Clean.Count) select Input.Text).ToList(); if (!r.SequenceEqual(Input_Clean)) { int left = Input_Left; int right = Input_Right; List <string> u = (from i in Input_Clean select i).ToList(); List <int> path = Track.GetPath(_chain); Program.Project.Undo.Add($"Chain Renamed to {Input.Text}", () => { Chain chain = ((Chain)Track.TraversePath(path)); IMultipleChainParent parent = (IMultipleChainParent)chain.Parent; for (int i = left; i <= right; i++) { parent[i].Name = u[i - left]; } TrackWindow window = Track.Get(chain)?.Window; window?.Selection.Select(parent[left]); window?.Selection.Select(parent[right], true); }, () => { Chain chain = ((Chain)Track.TraversePath(path)); IMultipleChainParent parent = (IMultipleChainParent)chain.Parent; for (int i = left; i <= right; i++) { parent[i].Name = r[i - left]; } TrackWindow window = Track.Get(chain)?.Window; window?.Selection.Select(parent[left]); window?.Selection.Select(parent[right], true); }); } }
public void Drop(object sender, DragEventArgs e) { e.Handled = true; IControl source = (IControl)e.Source; while (source.Name != "DropZone" && source.Name != "DropZoneAfter") { source = source.Parent; if (source == this) { e.Handled = false; return; } } bool copy = e.Modifiers.HasFlag(InputModifiers.Control); bool result; if (e.Data.Contains("chain")) { List <Chain> moving = ((List <ISelect>)e.Data.Get("chain")).Select(i => (Chain)i).ToList(); IMultipleChainParent source_parent = (IMultipleChainParent)moving[0].Parent; IMultipleChainParent _device = (IMultipleChainParent)_chain.Parent; int before = moving[0].IParentIndex.Value - 1; int after = _chain.ParentIndex.Value; if (source.Name == "DropZone" && e.GetPosition(source).Y < source.Bounds.Height / 2) { after--; } if (result = Chain.Move(moving, _device, after, copy)) { int before_pos = before; int after_pos = moving[0].IParentIndex.Value - 1; int count = moving.Count; if (source_parent == _device && after < before) { before_pos += count; } List <int> sourcepath = Track.GetPath((ISelect)source_parent); List <int> targetpath = Track.GetPath((ISelect)_device); Program.Project.Undo.Add($"Chain {(copy? "Copied" : "Moved")}", copy ? new Action(() => { IMultipleChainParent targetdevice = ((IMultipleChainParent)Track.TraversePath(targetpath)); for (int i = after + count; i > after; i--) { targetdevice.Remove(i); } }) : new Action(() => { IMultipleChainParent sourcedevice = ((IMultipleChainParent)Track.TraversePath(sourcepath)); IMultipleChainParent targetdevice = ((IMultipleChainParent)Track.TraversePath(targetpath)); List <Chain> umoving = (from i in Enumerable.Range(after_pos + 1, count) select targetdevice[i]).ToList(); Chain.Move(umoving, sourcedevice, before_pos, copy); }), () => { IMultipleChainParent sourcedevice = ((IMultipleChainParent)Track.TraversePath(sourcepath)); IMultipleChainParent targetdevice = ((IMultipleChainParent)Track.TraversePath(targetpath)); List <Chain> rmoving = (from i in Enumerable.Range(before + 1, count) select sourcedevice[i]).ToList(); Chain.Move(rmoving, targetdevice, after); }); } } else if (e.Data.Contains("device")) { List <Device> moving = ((List <ISelect>)e.Data.Get("device")).Select(i => (Device)i).ToList(); Chain source_chain = moving[0].Parent; Chain target_chain = _chain; int before = moving[0].IParentIndex.Value - 1; int after; int?remove = null; if (source.Name == "DropZone") { if (((IMultipleChainParent)_chain.Parent).Expanded != _chain.ParentIndex) { ((IMultipleChainParent)_chain.Parent).SpecificViewer.Expand(_chain.ParentIndex); } } else { ((IMultipleChainParent)_chain.Parent).Insert((remove = _chain.ParentIndex + 1).Value); target_chain = ((IMultipleChainParent)_chain.Parent)[_chain.ParentIndex.Value + 1]; } if (result = Device.Move(moving, target_chain, after = target_chain.Count - 1, copy)) { int before_pos = before; int after_pos = moving[0].IParentIndex.Value - 1; int count = moving.Count; if (source_chain == target_chain && after < before) { before_pos += count; } List <int> sourcepath = Track.GetPath(source_chain); List <int> targetpath = Track.GetPath(target_chain); Program.Project.Undo.Add($"Device {(copy? "Copied" : "Moved")}", copy ? new Action(() => { Chain targetchain = ((Chain)Track.TraversePath(targetpath)); for (int i = after + count; i > after; i--) { targetchain.Remove(i); } if (remove != null) { ((IMultipleChainParent)targetchain.Parent).Remove(remove.Value); } }) : new Action(() => { Chain sourcechain = ((Chain)Track.TraversePath(sourcepath)); Chain targetchain = ((Chain)Track.TraversePath(targetpath)); List <Device> umoving = (from i in Enumerable.Range(after_pos + 1, count) select targetchain[i]).ToList(); Device.Move(umoving, sourcechain, before_pos); if (remove != null) { ((IMultipleChainParent)targetchain.Parent).Remove(remove.Value); } }), () => { Chain sourcechain = ((Chain)Track.TraversePath(sourcepath)); Chain targetchain; if (remove != null) { IMultipleChainParent target = ((IMultipleChainParent)Track.TraversePath(targetpath.Skip(1).ToList())); target.Insert(remove.Value); targetchain = target[remove.Value]; } else { targetchain = ((Chain)Track.TraversePath(targetpath)); } List <Device> rmoving = (from i in Enumerable.Range(before + 1, count) select sourcechain[i]).ToList(); Device.Move(rmoving, targetchain, after, copy); }); } else if (remove != null) { ((IMultipleChainParent)_chain.Parent).Remove(remove.Value); } } else { return; } if (!result) { e.DragEffects = DragDropEffects.None; } }