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> /// Adds items to the given menu layout in which each items specifies its own destination directory. /// </summary> /// <param name="menuLayout">The menu layout to which items are to be added.</param> /// <param name="destinationDirectories">The destination directories to contain the added items.</param> /// <param name="items">The items to add.</param> internal static void AddItems(MenuLayoutViewModel menuLayout, IEnumerable <string> destinationDirectories, IEnumerable <ProgramDescription> items) { var taskData = new AddRomsToMenuData(menuLayout, destinationDirectories, items); var addRomsTask = new AsyncTaskWithProgress(Resources.Strings.AddItems_ProgressTitle, true, false); addRomsTask.RunTask(taskData, AddItems, AddItemsComplete); }
/// <summary> /// Add items to a specific destination folder. /// </summary> /// <param name="menuLayout">The menu layout to add items to.</param> /// <param name="destination">The folder to which items are to be added.</param> /// <param name="items">The items to add.</param> /// <param name="insertIndex">The location at which to insert the new items.</param> internal static void AddItems(MenuLayoutViewModel menuLayout, IFileContainer destination, IEnumerable <ProgramDescription> items, int insertIndex) { var taskData = new AddRomsToMenuData(menuLayout, destination, items, insertIndex); var addRomsTask = new AsyncTaskWithProgress(Resources.Strings.AddItems_ProgressTitle, true, false); addRomsTask.RunTask(taskData, AddItems, AddItemsComplete); }
private AddRomsToMenuData(MenuLayoutViewModel menuLayout, IFileContainer destination, int insertLocation, IEnumerable <ProgramDescription> itemsToAdd, IEnumerable <string> destinationDirectories) : base(null) { MenuLayout = menuLayout; Destination = destination; ItemsToAdd = new List <ProgramDescription>(itemsToAdd); InsertLocation = insertLocation; DestinationDirectories = destinationDirectories; FailedToAdd = new Dictionary <string, IDictionary <string, IList <System.Tuple <string, string> > > >(); AddedItems = new List <FileNode>(); UIDispatcher = OSDispatcher.Current; }
/// <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); }
/// <summary> /// Adds child items to this container. /// </summary> /// <param name="menuLayout">The root of the data tree.</param> /// <param name="insertIndex">The location at which to add the items.</param> /// <param name="items">The items to add.</param> internal void AddItems(MenuLayoutViewModel menuLayout, int insertIndex, IEnumerable <ProgramDescription> items) { IFileContainer dropTarget = Model as IFileContainer; AddItems(menuLayout, dropTarget, items, insertIndex); }
/// <summary> /// Initializes a new instance of AddRomsToMenuData for adding multiple items each to its own destination. /// </summary> /// <param name="menuLayout">The target menu layout.</param> /// <param name="destinationDirectories">Paths of destination directories (relative to <paramref name="menuLayout"/>'s root) for each item in <paramref name="itemsToAdd"/>.</param> /// <param name="itemsToAdd">The items to add to the directories described by <paramref name="destinationDirectories"/>.</param> /// <remarks>The operation must create necessary directories if they do not exist.</remarks> public AddRomsToMenuData(MenuLayoutViewModel menuLayout, IEnumerable <string> destinationDirectories, IEnumerable <ProgramDescription> itemsToAdd) : this(menuLayout, null, -1, itemsToAdd, destinationDirectories) { }
/// <summary> /// Initializes a new instance of AddRomsToMenuData for adding multiple items to a single destination. /// </summary> /// <param name="menuLayout">The target menu layout.</param> /// <param name="destination">The destination directory within <paramref name="menuLayout"/>.</param> /// <param name="itemsToAdd">The items to add to <paramref name="destination"/>.</param> /// <param name="insertLocation">The insertion point within <paramref name="destination"/> at which to insert <paramref name="itemsToAdd"/>. /// A value if <c>-1</c> indicates at the end of the existing items list.</param> public AddRomsToMenuData(MenuLayoutViewModel menuLayout, IFileContainer destination, IEnumerable <ProgramDescription> itemsToAdd, int insertLocation) : this(menuLayout, destination, insertLocation, itemsToAdd, null) { }