private void Group_GroupsChanged(object sender, GroupChangedEventArgs e) { List <Guid> layersAffected = new List <Guid>(); e.GroupsAffected.ForEach(x => layersAffected.AddRange(GetGroupLayerGuids(x))); LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(layersAffected)); }
private void PreMoveReassignBounds(GuidStructureItem parentGroup, Guid layer) { if (parentGroup != null) { Guid oldStart = parentGroup.StartLayerGuid; Guid oldEnd = parentGroup.EndLayerGuid; GuidStructureItem parentOfParent = parentGroup.Parent; if (parentGroup.Subgroups.Count == 0 && parentGroup.StartLayerGuid == layer && parentGroup.EndLayerGuid == layer) { RemoveGroup(parentGroup); } else { if (parentGroup.EndLayerGuid == layer) { parentGroup.EndLayerGuid = FindBoundLayer(parentGroup, layer, false); } if (parentGroup.StartLayerGuid == layer) { parentGroup.StartLayerGuid = FindBoundLayer(parentGroup, layer, true); } } if (parentOfParent != null) { ApplyBoundsToParents(parentOfParent, parentGroup, oldStart, oldEnd); } LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(layer)); } }
/// <summary> /// Moves group and it's children from one index to another. This method makes changes in <see cref="Document"/> Layers. /// </summary> /// <param name="groupGuid">Group guid to move.</param> /// <param name="newIndex">New group index, relative to <see cref="Document"/> Layers.</param> public void MoveGroup(Guid groupGuid, int newIndex) { var group = GetGroupByGuid(groupGuid); var parentGroup = group.Parent; bool reverseOrder = true; int groupTopIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.GuidValue == group.EndLayerGuid)); int groupBottomIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.GuidValue == group.StartLayerGuid)); int difference = newIndex - groupTopIndex; if (newIndex < groupTopIndex) { reverseOrder = false; difference = newIndex - groupBottomIndex; } if (difference == 0) { return; } Unassign(parentGroup, group); List <Guid> layersInOrder = GetLayersInOrder(new GroupData(groupTopIndex, groupBottomIndex)); MoveLayersInGroup(layersInOrder, difference, reverseOrder); LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(layersInOrder)); }
public GuidStructureItem AddNewGroup(string groupName, GuidStructureItem childGroup) { if (childGroup == null) { throw new ArgumentException("Child group can't be null."); } GuidStructureItem group = new(groupName, childGroup.StartLayerGuid, childGroup.EndLayerGuid, new[] { childGroup }, childGroup.Parent) { IsExpanded = true }; if (childGroup.Parent == null) { Groups.Add(group); Groups.Remove(childGroup); } else { childGroup.Parent.Subgroups.Add(group); childGroup.Parent.Subgroups.Remove(childGroup); } childGroup.Parent = group; group.GroupsChanged += Group_GroupsChanged; LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(GetGroupLayerGuids(group))); return(group); }
private void AssignParent(Guid layer, GuidStructureItem parent) { var currentParent = GetGroupByLayer(layer); if (currentParent != null) { PreMoveReassignBounds(currentParent, layer); } Assign(parent, layer); LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(layer)); }
private void Assign(GuidStructureItem parentGroup, Guid layerGuid) { if (parentGroup != null) { Guid?oldStart = parentGroup.StartLayerGuid; Guid?oldEnd = parentGroup.EndLayerGuid; int layerIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.GuidValue == layerGuid)); int folderTopIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.GuidValue == parentGroup.EndLayerGuid)); int folderBottomIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.GuidValue == parentGroup.StartLayerGuid)); int finalTopIndex = Math.Max(folderTopIndex, layerIndex); int finalBottomIndex = Math.Min(folderBottomIndex, layerIndex); Guid?topBoundLayer = FindBoundLayer(layerGuid, finalTopIndex, finalBottomIndex, false); Guid?bottomBoundLayer = FindBoundLayer(layerGuid, finalTopIndex, finalBottomIndex, true); if (topBoundLayer == parentGroup.EndLayerGuid) { parentGroup.EndLayerGuid = layerGuid; } if (bottomBoundLayer == parentGroup.StartLayerGuid) { parentGroup.StartLayerGuid = layerGuid; } if (parentGroup.Parent != null) { ApplyBoundsToParents(parentGroup.Parent, parentGroup, oldStart, oldEnd); } var args = new LayerStructureChangedEventArgs(layerGuid); if (topBoundLayer.HasValue) { args.AffectedLayerGuids.Add(topBoundLayer.Value); } if (bottomBoundLayer.HasValue) { args.AffectedLayerGuids.Add(bottomBoundLayer.Value); } LayerStructureChanged?.Invoke(this, args); } }
private void RemoveGroup(GuidStructureItem parentFolder) { parentFolder.GroupsChanged -= Group_GroupsChanged; var layerGuids = GetGroupLayerGuids(parentFolder); if (parentFolder.Parent == null) { Groups.Remove(parentFolder); } else { parentFolder.Parent.Subgroups.Remove(parentFolder); } LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(layerGuids)); }
// This will allow to add new group with multiple layers and groups at once. Not working well, todo fix /*public GuidStructureItem AddNewGroup(string groupName, IEnumerable<Layer> layers, Guid activeLayer) * { * var activeLayerParent = GetGroupByLayer(activeLayer); * * List<GuidStructureItem> sameLevelGroups = new List<GuidStructureItem>(); * * var group = AddNewGroup(groupName, activeLayer); * * if (activeLayerParent == null) * { * sameLevelGroups.AddRange(Groups); * } * else * { * sameLevelGroups.AddRange(activeLayerParent.Subgroups); * } * * sameLevelGroups.Remove(group); * group.Subgroups = new ObservableCollection<GuidStructureItem>(sameLevelGroups); * * sameLevelGroups = new(sameLevelGroups.Where(x => IsChildOf(activeLayer, x))); * * Guid lastLayer = activeLayer; * * foreach (var layer in layers) * { * if (layer.LayerGuid == activeLayer) * { * continue; * } * * Owner.MoveLayerInStructure(layer.LayerGuid, lastLayer, false); * lastLayer = layer.LayerGuid; * } * * return group; * }*/ /// <summary> /// Adds a new group to layer structure taking into consideration nesting. Invokes LayerStructureChanged event. /// </summary> /// <param name="groupName">Name of a group.</param> /// <param name="childLayer">Child layer of a new group.</param> /// <returns>Newly created group (<see cref="GuidStructureItem"/>).</returns> public GuidStructureItem AddNewGroup(string groupName, Guid childLayer) { var parent = GetGroupByLayer(childLayer); GuidStructureItem group = new(groupName, childLayer) { IsExpanded = true }; if (parent == null) { Groups.Add(group); } else { group.Parent = parent; parent.Subgroups.Add(group); } group.GroupsChanged += Group_GroupsChanged; LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(childLayer)); return(group); }
/// <summary> /// Assigns group new parent. /// </summary> /// <param name="group">Group to assign parent</param> /// <param name="referenceLayerGroup">Parent of group.</param> public void ReassignParent(GuidStructureItem group, GuidStructureItem referenceLayerGroup) { group.Parent?.Subgroups.Remove(group); if (Groups.Contains(group)) { Groups.Remove(group); } if (referenceLayerGroup == null) { if (!Groups.Contains(group)) { Groups.Add(group); group.Parent = null; } } else { referenceLayerGroup.Subgroups.Add(group); group.Parent = referenceLayerGroup; } LayerStructureChanged?.Invoke(this, new LayerStructureChangedEventArgs(GetGroupLayerGuids(group))); }