|
@@ -17,10 +17,10 @@ internal class DocumentStructureHelper
|
|
|
|
|
|
public void CreateNewStructureMember(StructureMemberType type)
|
|
public void CreateNewStructureMember(StructureMemberType type)
|
|
{
|
|
{
|
|
- var member = doc.FindFirstSelectedMember();
|
|
|
|
|
|
+ StructureMemberViewModel? member = doc.FindFirstSelectedMember();
|
|
if (member is null)
|
|
if (member is null)
|
|
{
|
|
{
|
|
- var guid = Guid.NewGuid();
|
|
|
|
|
|
+ Guid guid = Guid.NewGuid();
|
|
//put member on top
|
|
//put member on top
|
|
helpers.ActionAccumulator.AddActions(new CreateStructureMember_Action(doc.StructureRoot.GuidValue, guid, doc.StructureRoot.Children.Count, type));
|
|
helpers.ActionAccumulator.AddActions(new CreateStructureMember_Action(doc.StructureRoot.GuidValue, guid, doc.StructureRoot.Children.Count, type));
|
|
helpers.ActionAccumulator.AddFinishedActions(new StructureMemberName_Action(guid, type == StructureMemberType.Layer ? "New Layer" : "New Folder"));
|
|
helpers.ActionAccumulator.AddFinishedActions(new StructureMemberName_Action(guid, type == StructureMemberType.Layer ? "New Layer" : "New Folder"));
|
|
@@ -28,7 +28,7 @@ internal class DocumentStructureHelper
|
|
}
|
|
}
|
|
if (member is FolderViewModel folder)
|
|
if (member is FolderViewModel folder)
|
|
{
|
|
{
|
|
- var guid = Guid.NewGuid();
|
|
|
|
|
|
+ Guid guid = Guid.NewGuid();
|
|
//put member inside folder on top
|
|
//put member inside folder on top
|
|
helpers.ActionAccumulator.AddActions(new CreateStructureMember_Action(folder.GuidValue, guid, folder.Children.Count, type));
|
|
helpers.ActionAccumulator.AddActions(new CreateStructureMember_Action(folder.GuidValue, guid, folder.Children.Count, type));
|
|
helpers.ActionAccumulator.AddFinishedActions(new StructureMemberName_Action(guid, type == StructureMemberType.Layer ? "New Layer" : "New Folder"));
|
|
helpers.ActionAccumulator.AddFinishedActions(new StructureMemberName_Action(guid, type == StructureMemberType.Layer ? "New Layer" : "New Folder"));
|
|
@@ -36,12 +36,12 @@ internal class DocumentStructureHelper
|
|
}
|
|
}
|
|
if (member is LayerViewModel layer)
|
|
if (member is LayerViewModel layer)
|
|
{
|
|
{
|
|
- var guid = Guid.NewGuid();
|
|
|
|
|
|
+ Guid guid = Guid.NewGuid();
|
|
//put member above the layer
|
|
//put member above the layer
|
|
- var path = FindPath(layer.GuidValue);
|
|
|
|
|
|
+ List<StructureMemberViewModel>? path = FindPath(layer.GuidValue);
|
|
if (path.Count < 2)
|
|
if (path.Count < 2)
|
|
throw new InvalidOperationException("Couldn't find a path to the selected member");
|
|
throw new InvalidOperationException("Couldn't find a path to the selected member");
|
|
- var parent = (FolderViewModel)path[1];
|
|
|
|
|
|
+ FolderViewModel? parent = (FolderViewModel)path[1];
|
|
helpers.ActionAccumulator.AddActions(new CreateStructureMember_Action(parent.GuidValue, guid, parent.Children.IndexOf(layer) + 1, type));
|
|
helpers.ActionAccumulator.AddActions(new CreateStructureMember_Action(parent.GuidValue, guid, parent.Children.IndexOf(layer) + 1, type));
|
|
helpers.ActionAccumulator.AddFinishedActions(new StructureMemberName_Action(guid, type == StructureMemberType.Layer ? "New Layer" : "New Folder"));
|
|
helpers.ActionAccumulator.AddFinishedActions(new StructureMemberName_Action(guid, type == StructureMemberType.Layer ? "New Layer" : "New Folder"));
|
|
return;
|
|
return;
|
|
@@ -52,7 +52,7 @@ internal class DocumentStructureHelper
|
|
public StructureMemberViewModel FindOrThrow(Guid guid) => Find(guid) ?? throw new ArgumentException("Could not find member with guid " + guid.ToString());
|
|
public StructureMemberViewModel FindOrThrow(Guid guid) => Find(guid) ?? throw new ArgumentException("Could not find member with guid " + guid.ToString());
|
|
public StructureMemberViewModel? Find(Guid guid)
|
|
public StructureMemberViewModel? Find(Guid guid)
|
|
{
|
|
{
|
|
- var list = FindPath(guid);
|
|
|
|
|
|
+ List<StructureMemberViewModel>? list = FindPath(guid);
|
|
return list.Count > 0 ? list[0] : null;
|
|
return list.Count > 0 ? list[0] : null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -62,13 +62,13 @@ internal class DocumentStructureHelper
|
|
}
|
|
}
|
|
private StructureMemberViewModel? FindFirstWhere(Predicate<StructureMemberViewModel> predicate, FolderViewModel folderVM)
|
|
private StructureMemberViewModel? FindFirstWhere(Predicate<StructureMemberViewModel> predicate, FolderViewModel folderVM)
|
|
{
|
|
{
|
|
- foreach (var child in folderVM.Children)
|
|
|
|
|
|
+ foreach (StructureMemberViewModel? child in folderVM.Children)
|
|
{
|
|
{
|
|
if (predicate(child))
|
|
if (predicate(child))
|
|
return child;
|
|
return child;
|
|
if (child is FolderViewModel innerFolderVM)
|
|
if (child is FolderViewModel innerFolderVM)
|
|
{
|
|
{
|
|
- var result = FindFirstWhere(predicate, innerFolderVM);
|
|
|
|
|
|
+ StructureMemberViewModel? result = FindFirstWhere(predicate, innerFolderVM);
|
|
if (result is not null)
|
|
if (result is not null)
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -78,14 +78,14 @@ internal class DocumentStructureHelper
|
|
|
|
|
|
public (StructureMemberViewModel, FolderViewModel) FindChildAndParentOrThrow(Guid childGuid)
|
|
public (StructureMemberViewModel, FolderViewModel) FindChildAndParentOrThrow(Guid childGuid)
|
|
{
|
|
{
|
|
- var path = FindPath(childGuid);
|
|
|
|
|
|
+ List<StructureMemberViewModel>? path = FindPath(childGuid);
|
|
if (path.Count < 2)
|
|
if (path.Count < 2)
|
|
throw new ArgumentException("Couldn't find child and parent");
|
|
throw new ArgumentException("Couldn't find child and parent");
|
|
return (path[0], (FolderViewModel)path[1]);
|
|
return (path[0], (FolderViewModel)path[1]);
|
|
}
|
|
}
|
|
public List<StructureMemberViewModel> FindPath(Guid guid)
|
|
public List<StructureMemberViewModel> FindPath(Guid guid)
|
|
{
|
|
{
|
|
- var list = new List<StructureMemberViewModel>();
|
|
|
|
|
|
+ List<StructureMemberViewModel>? list = new List<StructureMemberViewModel>();
|
|
if (FillPath(doc.StructureRoot, guid, list))
|
|
if (FillPath(doc.StructureRoot, guid, list))
|
|
list.Add(doc.StructureRoot);
|
|
list.Add(doc.StructureRoot);
|
|
return list;
|
|
return list;
|
|
@@ -97,7 +97,7 @@ internal class DocumentStructureHelper
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- foreach (var member in folder.Children)
|
|
|
|
|
|
+ foreach (StructureMemberViewModel? member in folder.Children)
|
|
{
|
|
{
|
|
if (member is LayerViewModel childLayer && childLayer.GuidValue == guid)
|
|
if (member is LayerViewModel childLayer && childLayer.GuidValue == guid)
|
|
{
|
|
{
|
|
@@ -118,20 +118,20 @@ internal class DocumentStructureHelper
|
|
|
|
|
|
public void MoveStructureMember(Guid guid, bool toSmallerIndex)
|
|
public void MoveStructureMember(Guid guid, bool toSmallerIndex)
|
|
{
|
|
{
|
|
- var path = FindPath(guid);
|
|
|
|
|
|
+ List<StructureMemberViewModel>? path = FindPath(guid);
|
|
if (path.Count < 2)
|
|
if (path.Count < 2)
|
|
throw new ArgumentException("Couldn't find the member to be moved");
|
|
throw new ArgumentException("Couldn't find the member to be moved");
|
|
if (path.Count == 2)
|
|
if (path.Count == 2)
|
|
{
|
|
{
|
|
int curIndex = doc.StructureRoot.Children.IndexOf(path[0]);
|
|
int curIndex = doc.StructureRoot.Children.IndexOf(path[0]);
|
|
- if (curIndex == 0 && toSmallerIndex || curIndex == doc.StructureRoot.Children.Count - 1 && !toSmallerIndex)
|
|
|
|
|
|
+ if ((curIndex == 0 && toSmallerIndex) || (curIndex == doc.StructureRoot.Children.Count - 1 && !toSmallerIndex))
|
|
return;
|
|
return;
|
|
helpers.ActionAccumulator.AddFinishedActions(new MoveStructureMember_Action(guid, doc.StructureRoot.GuidValue, toSmallerIndex ? curIndex - 1 : curIndex + 1));
|
|
helpers.ActionAccumulator.AddFinishedActions(new MoveStructureMember_Action(guid, doc.StructureRoot.GuidValue, toSmallerIndex ? curIndex - 1 : curIndex + 1));
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- var folder = (FolderViewModel)path[1];
|
|
|
|
|
|
+ FolderViewModel? folder = (FolderViewModel)path[1];
|
|
int index = folder.Children.IndexOf(path[0]);
|
|
int index = folder.Children.IndexOf(path[0]);
|
|
- if (toSmallerIndex && index > 0 || !toSmallerIndex && index < folder.Children.Count - 1)
|
|
|
|
|
|
+ if ((toSmallerIndex && index > 0) || (!toSmallerIndex && index < folder.Children.Count - 1))
|
|
{
|
|
{
|
|
helpers.ActionAccumulator.AddFinishedActions(new MoveStructureMember_Action(guid, path[1].GuidValue, toSmallerIndex ? index - 1 : index + 1));
|
|
helpers.ActionAccumulator.AddFinishedActions(new MoveStructureMember_Action(guid, path[1].GuidValue, toSmallerIndex ? index - 1 : index + 1));
|
|
}
|
|
}
|