/// <summary> /// Move project elements based on the given project tree, reference project tree and move action. /// Will modify the project if successful, but not save; only dirty. /// </summary> private static bool TryMove(Project project, IProjectTree projectTree, IProjectTree?referenceProjectTree, MoveAction moveAction) { if (!HasValidDisplayOrder(projectTree) || !HasValidDisplayOrder(referenceProjectTree)) { return(false); } if (projectTree == referenceProjectTree) { return(false); } if (referenceProjectTree != null) { // The reference element is the element for which moved items will be above or below it. ProjectItemElement?referenceElement = TryGetReferenceElement(project, referenceProjectTree, ImmutableArray <string> .Empty, moveAction); if (referenceElement != null) { ImmutableArray <ProjectItemElement> elements = GetItemElements(project, projectTree, ImmutableArray <string> .Empty); return(TryMoveElements(elements, referenceElement, moveAction)); } } return(false); }
/// <summary> /// Move the respective item elements below the target. /// </summary> public static bool TryMoveElementsBelow(Project project, ImmutableArray <ProjectItemElement> elements, IProjectTree target) { Requires.NotNull(project, nameof(project)); Requires.NotNull(target, nameof(target)); ProjectItemElement?referenceElement = TryGetReferenceElement(project, target, ImmutableArray <string> .Empty, MoveAction.Below); if (referenceElement == null) { return(false); } return(TryMoveElements(elements, referenceElement, MoveAction.Below)); }
/// <summary> /// Move the respective item elements to the top of the target's children. /// </summary> public static bool TryMoveElementsToTop(Project project, ImmutableArray <ProjectItemElement> elements, IProjectTree target) { Requires.NotNull(project, nameof(project)); Requires.NotNull(target, nameof(target)); IProjectTree newTarget = target; // This is to handle adding files to empty folders since empty folders do not have a valid display order yet. // We need to find a target up the tree that has a valid display order, because it most likely will have our reference element that we want. while (!HasValidDisplayOrder(newTarget) && !newTarget.Flags.Contains(ProjectTreeFlags.ProjectRoot)) { newTarget = newTarget.Parent; } var excludeIncludes = elements.Select(x => x.Include).ToImmutableArray(); ProjectItemElement?referenceElement = GetChildren(newTarget).Select(x => TryGetReferenceElement(project, x, excludeIncludes, MoveAction.Above)).FirstOrDefault(x => x != null); if (referenceElement == null) { return(false); } return(TryMoveElements(elements, referenceElement, MoveAction.Above)); }