示例#1
0
        private static void AddItemsComplete(AsyncTaskData taskData)
        {
            var args = (AddRomsToMenuData)taskData;

            args.MenuLayout.FinishItemsUpdate(args.Error == null);
            if (args.Error == null)
            {
                if (args.Destination != null)
                {
                    var insertFolder = args.MenuLayout.FindViewModelForModel(args.Destination);
                    FileNodeViewModel highlightItem = insertFolder;

                    // NOTE: Multi-Mode Tree will need to fix this!
                    if (insertFolder.IsOpen || (insertFolder == args.MenuLayout))
                    {
                        var items          = insertFolder.Items;
                        var highlightIndex = args.InsertLocation;
                        if (highlightIndex < 0)
                        {
                            highlightIndex = System.Math.Max(0, items.Count - 1);
                        }
                        if (highlightIndex < items.Count)
                        {
                            highlightItem            = items[highlightIndex];
                            highlightItem.IsSelected = true;
                            ////args.MenuLayout.RetainFocus = items[highlightIndex].GetHashCode();
                        }
                    }
                    else
                    {
                        insertFolder.IsSelected = true;
                        ////args.MenuLayout.RetainFocus = insertFolder.GetHashCode();
                    }
                    ++args.MenuLayout.RetainFocus;
#if MAC
                    if (highlightItem != null)
                    {
                        args.MenuLayout.CurrentSelection = highlightItem;
                    }
#endif // MAC
                }
            }
            if ((args.Error != null) || args.FailedToAdd.Any())
            {
                var exception = args.Error;
                if (exception == null)
                {
                    exception = args.FirstFilePreparationError;
                }
                IRomHelpers.ReportAddItemsError(exception, args.FailedToAdd);
            }
        }
示例#2
0
        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>
 /// Initializes a new instance of the StartDragFileNodeCommand class.
 /// </summary>
 /// <param name="draggedItem">The item that's being dragged.</param>
 /// <param name="canExecute">Function to call to determine if the command can be executed.</param>
 public StartDragFileNodeCommand(FileNodeViewModel draggedItem, Func <object, bool> canExecute)
     : base(NoOp, canExecute, null)
 {
     _draggedItem = draggedItem;
 }
示例#4
0
        private static bool GetTreeIterForItem(out Gtk.TreeIter itemIter, Gtk.TreeIter parentIter, Gtk.TreeStore treeStore, FileNodeViewModel item, int index)
        {
            // if item is null, just get iterator at index
            itemIter = Gtk.TreeIter.Zero;
            var validIter  = false;
            var putAtFront = (index < 0) && (item == null);

            if (parentIter.Equals(Gtk.TreeIter.Zero))
            {
                if (putAtFront)
                {
                    validIter = treeStore.IterChildren(out itemIter);
                }
                else
                {
                    validIter = (treeStore.IterNChildren() > index) && treeStore.IterNthChild(out itemIter, index);
                }
            }
            else
            {
                if (putAtFront)
                {
                    validIter = treeStore.IterChildren(out itemIter, parentIter);
                }
                else
                {
                    validIter = (treeStore.IterNChildren(parentIter) > index) && treeStore.IterNthChild(out itemIter, parentIter, index);
                }
            }
            var node    = validIter ? treeStore.GetValue(itemIter, 0) as FileNodeViewModel : null;
            var foundIt = (node == null) || (item == null) || object.ReferenceEquals(node, item);

            return(foundIt && !itemIter.Equals(Gtk.TreeIter.Zero));
        }
示例#5
0
 private static void ViewModelRemoved(FileNodeViewModel viewModel)
 {
     viewModel.Model = null;
 }