private bool MoveItem(MenuLayoutViewModel menuLayout, FolderViewModel newParent, int indexInNewParent, FileNodeViewModel itemToMove) { var movedItem = true; menuLayout.StartItemsUpdate(); // operate on the model var parent = newParent.Model as Folder; var itemToMoveModel = itemToMove.Model; if (indexInNewParent >= parent.Files.Count) { if (!itemToMoveModel.Parent.MoveChildToNewParent(itemToMoveModel, parent, false)) { throw new System.InvalidOperationException(Resources.Strings.MenuLayoutDragDrop_FailedToMoveItemMessage); } } else { if (!itemToMoveModel.Parent.MoveChildToNewParent(itemToMoveModel, parent, indexInNewParent, false)) { throw new System.InvalidOperationException(Resources.Strings.MenuLayoutDragDrop_FailedToMoveItemMessage); } } menuLayout.FinishItemsUpdate(true); return(movedItem); }
/// <summary> /// Moves items from one location in the tree to another. /// </summary> /// <param name="menuLayout">The root of the data tree.</param> /// <param name="newParent">The new parent item for the items being moved.</param> /// <param name="indexInNewParent">THe location in the new parent at which to add the items.</param> /// <param name="itemsToMove">The items to relocate.</param> /// <returns><c>true</c> if any of the items were moved.</returns> internal bool MoveItems(MenuLayoutViewModel menuLayout, FolderViewModel newParent, int indexInNewParent, IEnumerable <FileNodeViewModel> itemsToMove) { var movedItems = itemsToMove.Any(); if (movedItems) { menuLayout.StartItemsUpdate(); foreach (var itemToMove in itemsToMove) { // Post-increment insert location to preserve order of dropped items. movedItems = MoveItem(menuLayout, newParent, indexInNewParent++, itemToMove); if (!movedItems) { break; } } menuLayout.FinishItemsUpdate(true); INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested(); } return(movedItems); }
private bool DropItem(MenuLayoutViewModel menuLayout, IFile droppedItem) { var acceptedDroppedItem = droppedItem != null; if (acceptedDroppedItem) { if (menuLayout != null) { menuLayout.StartItemsUpdate(); } if (droppedItem.Parent != null) { var selfAsFileContainer = Model as IFileContainer; if (selfAsFileContainer != null) { if (!selfAsFileContainer.AddChild(droppedItem)) { // we're moving to the bottom, so remove and re-add selfAsFileContainer.RemoveChild(droppedItem); selfAsFileContainer.AddChild(droppedItem); } } else { // if an item is dropped on a non-file, insert before the drop target item. var insertLocation = Parent.IndexOf(Model); Parent.Insert(insertLocation, droppedItem); } } if (menuLayout != null) { menuLayout.FinishItemsUpdate(); } CommandManager.InvalidateRequerySuggested(); } return(acceptedDroppedItem); }