Exemplo n.º 1
0
    protected void CreateDropPositions()
    {
        dropPositions = new List<DropPosition>();

        var angleStep = 360f/dropPositionCount;

        // Debug.Log("AngleStep = " + angleStep);

        var angle = 180f;

        var startVector = -transform.forward * dropRadius;

        startVector.y = 0;

        for (var i = 0; i < dropPositionCount; i++)
        {
            var newDropPos = new DropPosition();

            newDropPos.offset = Quaternion.AngleAxis(angle, Vector3.up) * startVector;
            newDropPos.inUse = false;
            newDropPos.index = i;

            dropPositions.Add(newDropPos);

            angle += angleStep;
        }
    }
Exemplo n.º 2
0
    protected void CreateDropPositions()
    {
        dropPositions = new List <DropPosition>();

        var angleStep = 360f / dropPositionCount;

        // Debug.Log("AngleStep = " + angleStep);

        var angle = 180f;

        var startVector = -transform.forward * dropRadius;

        startVector.y = 0;

        for (var i = 0; i < dropPositionCount; i++)
        {
            var newDropPos = new DropPosition();

            newDropPos.offset = Quaternion.AngleAxis(angle, Vector3.up) * startVector;
            newDropPos.inUse  = false;
            newDropPos.index  = i;

            dropPositions.Add(newDropPos);

            angle += angleStep;
        }
    }
Exemplo n.º 3
0
        protected virtual void PerformDragDrop(Point dropLocation, TreeNodeElement targetNodeElement, List <RadTreeNode> draggedNodes)
        {
            RadTreeNode  targetNode = targetNodeElement.Data;
            DropPosition position   = this.GetDropPosition(dropLocation, targetNodeElement);

            if (position == DropPosition.AsChildNode)
            {
                foreach (RadTreeNode node in draggedNodes)
                {
                    if (!this.OnDragEnding(position, node, targetNode))
                    {
                        continue;
                    }

                    node.Remove();
                    targetNode.Nodes.Add(node);
                    this.owner.OnDragEnded(new RadTreeViewDragEventArgs(node, targetNode));
                }

                targetNode.Expand();
            }
            else
            {
                this.PerformDragDropCore(position, targetNode, draggedNodes);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets drag indicators in appropriate position.
        /// </summary>
        /// <param name="dropPosition">
        /// Indicates the drop position, based on that the indicators will shown.
        /// </param>
        /// <param name="rowColumnIndex">
        /// Specifies the rowColumn index based on mouse hover.
        /// </param>
        protected virtual void ShowDragIndicators(DropPosition dropPosition, RowColumnIndex rowColumnIndex)
        {
            if (upArrowIndicator == null && downArrowIndicator == null)
            {
                upArrowIndicator         = new Popup();
                downArrowIndicator       = new Popup();
                upArrowIndicator.Child   = new UpIndicatorContentControl();
                downArrowIndicator.Child = new DownIndicatorContentControl();
            }
            var lineinfo = TreeGrid.TreeGridPanel.ScrollRows.GetVisibleLineAtLineIndex(rowColumnIndex.RowIndex);

            var upHoffset   = 0.0;
            var downHoffset = 0.0;
            var upVoffset   = 0.0;
            var downVoffset = 0.0;

            double width = 0;

            if (TreeGrid.showRowHeader)
            {
                width = this.TreeGrid.RowHeaderWidth / 2;
            }
            else
            {
                width = 22;
            }
            upHoffset = downHoffset = this.TreeGrid.GetControlRect(this.TreeGrid).X + width;

            if (dropPosition == DropPosition.DropAbove)
            {
                CloseDragIndicators();
                upVoffset   = lineinfo.Origin + 5;
                downVoffset = lineinfo.Origin - (22);
                //VisualStateManager.GoToState(GetRowControl(rowColumnIndex), "DropAbove", true);
            }
            else if (dropPosition == DropPosition.DropBelow)
            {
                CloseDragIndicators();
                upVoffset   = lineinfo.Corner + 5;
                downVoffset = lineinfo.Corner - 22;
                //VisualStateManager.GoToState(GetRowControl(rowColumnIndex), "DropBelow", true);
            }
            else
            {
                CloseDragIndicators();
                //VisualStateManager.GoToState(GetRowControl(rowColumnIndex), "DropOver", true);
                return;
            }

            // Need to convert the values to their related screen coordinates
            upArrowIndicator.IsOpen   = true;
            downArrowIndicator.IsOpen = true;
            var pt1 = this.TreeGrid.TransformToVisual(null).TransformPoint(new Point(upHoffset, upVoffset));
            var pt2 = this.TreeGrid.TransformToVisual(null).TransformPoint(new Point(downHoffset, downVoffset));

            upArrowIndicator.HorizontalOffset   = pt1.X;
            downArrowIndicator.HorizontalOffset = pt2.X;
            upArrowIndicator.VerticalOffset     = pt1.Y;
            downArrowIndicator.VerticalOffset   = pt2.Y;
        }
Exemplo n.º 5
0
        public virtual void Drop(List <object> node, DropPosition mode, bool copy)
        {
            bool isRunningCompositeTask = Services.TaskService.IsRunningCompositeTask;

            if (!isRunningCompositeTask)
            {
                Services.TaskService.BeginCompositeTask("Drag drop GameObject");
            }
            foreach (object current in node)
            {
                if (!copy)
                {
                    IDragSource dragSource = current as IDragSource;
                    if (dragSource != null)
                    {
                        dragSource.Detach();
                    }
                }
                NodeObject nodeObject = current as NodeObject;
                if (nodeObject != null)
                {
                    this.LoadDropObject(nodeObject, mode);
                }
            }
            if (!isRunningCompositeTask)
            {
                Services.TaskService.EndCompositeTask();
            }
        }
        static bool IsDropTargetUserModifiable(GameObjectTreeViewItem targetItem, DropPosition dropPos)
        {
            switch (dropPos)
            {
            case DropPosition.Upon:
                if (targetItem.objectPPTR != null)
                {
                    return(IsUserModifiable(targetItem.objectPPTR));
                }
                break;

            case DropPosition.Below:
            case DropPosition.Above:
                var targetParent = targetItem.parent as GameObjectTreeViewItem;
                if (targetParent != null && targetParent.objectPPTR != null)
                {
                    return(IsUserModifiable(targetParent.objectPPTR));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dropPos), dropPos, null);
            }

            return(true);
        }
Exemplo n.º 7
0
 public void Drop(IEnumerable<IDragSource> nodes, DropPosition mode, DragDropEffect effect, DragDropKeyStates initialKeyStates)
 {
     foreach (var node in nodes)
     {
         this.Drop(node, mode, effect == DragDropEffect.Copy);
     }
 }
Exemplo n.º 8
0
 private Target(DockPane pane, DockPanePreviewPlacement placement)
 {
     _targetItem = pane.SelectedItem;
     if (placement == DockPanePreviewPlacement.Left)
     {
         _targetPosition = DropPosition.Left;
     }
     else if (placement == DockPanePreviewPlacement.Right)
     {
         _targetPosition = DropPosition.Right;
     }
     else if (placement == DockPanePreviewPlacement.Top)
     {
         _targetPosition = DropPosition.Top;
     }
     else if (placement == DockPanePreviewPlacement.Bottom)
     {
         _targetPosition = DropPosition.Bottom;
     }
     else
     {
         Debug.Assert(placement == DockPanePreviewPlacement.Fill);
         _targetPosition = DropPosition.Fill;
     }
 }
        bool IsValidSubSceneDropTarget(int dropTargetGameObjectOrSceneInstanceID, DropPosition dropPosition, Object[] draggedObjects)
        {
            if (draggedObjects == null || draggedObjects.Length == 0)
            {
                return(false);
            }

            Transform parentForDrop = GetTransformParentForDrop(dropTargetGameObjectOrSceneInstanceID, dropPosition);

            if (parentForDrop == null)
            {
                // Drop is on a root scene which is always allowed
                return(true);
            }

            foreach (var obj in draggedObjects)
            {
                var gameObject = obj as GameObject;
                if (gameObject == null)
                {
                    continue;
                }

                // Require all dragged objects to be valid (since native cannot filter out invalid sub scene drags currently)
                if (SubSceneGUI.IsChildOrSameAsOtherTransform(parentForDrop, gameObject.transform))
                {
                    return(false);
                }
            }

            // Valid drop target for current dragged objects
            return(true);
        }
Exemplo n.º 10
0
        void GetPreviousAndNextItemsIgnoringDraggedItems(int targetRow, DropPosition dropPosition, out TreeViewItem previousItem, out TreeViewItem nextItem)
        {
            if (dropPosition != DropPosition.Above && dropPosition != DropPosition.Below)
            {
                throw new ArgumentException("Invalid argument: " + dropPosition);
            }

            previousItem = nextItem = null;
            int curPrevRow = (dropPosition == DropPosition.Above) ? targetRow - 1 : targetRow;
            int curNextRow = (dropPosition == DropPosition.Above) ? targetRow : targetRow + 1;

            while (curPrevRow > 0)
            {
                var curPreviousItem = m_TreeView.data.GetItem(curPrevRow);
                if (!m_TreeView.IsDraggingItem(curPreviousItem))
                {
                    previousItem = curPreviousItem;
                    break;
                }
                curPrevRow--;
            }

            while (curNextRow < m_TreeView.data.rowCount)
            {
                var curNextItem = m_TreeView.data.GetItem(curNextRow);
                if (!m_TreeView.IsDraggingItem(curNextItem))
                {
                    nextItem = curNextItem;
                    break;
                }
                curNextRow++;
            }
        }
Exemplo n.º 11
0
 private Target(DockTreePosition dockTreePosition)
 {
     _targetItem = null;
     if (dockTreePosition == DockTreePosition.Left)
     {
         _targetPosition = DropPosition.Left;
     }
     else if (dockTreePosition == DockTreePosition.Right)
     {
         _targetPosition = DropPosition.Right;
     }
     else if (dockTreePosition == DockTreePosition.Top)
     {
         _targetPosition = DropPosition.Top;
     }
     else if (dockTreePosition == DockTreePosition.Bottom)
     {
         _targetPosition = DropPosition.Bottom;
     }
     else if (dockTreePosition == DockTreePosition.Document)
     {
         _targetPosition = DropPosition.Fill;
     }
     else
     {
         Debug.Assert(dockTreePosition == DockTreePosition.Floating);
         _targetPosition = DropPosition.Floating;
     }
 }
Exemplo n.º 12
0
 public void Drop(IEnumerable <IDragSource> nodes, DropPosition mode, DragDropEffect effect, DragDropKeyStates initialKeyStates)
 {
     foreach (var node in nodes)
     {
         this.Drop(node, mode, effect == DragDropEffect.Copy);
     }
 }
 int GetDropTargetInstanceID(GameObjectTreeViewItem hierarchyTargetItem, DropPosition dropPosition)
 {
     if (SubSceneGUI.IsUsingSubScenes())
     {
         var gameObjectDropTarget = hierarchyTargetItem.objectPPTR as GameObject;
         if (gameObjectDropTarget != null)
         {
             if (dropPosition == DropPosition.Above)
             {
                 return(hierarchyTargetItem.id);
             }
             if (SubSceneGUI.IsSubSceneHeader(gameObjectDropTarget))
             {
                 Scene subScene = SubSceneGUI.GetSubScene(gameObjectDropTarget);
                 if (subScene.IsValid())
                 {
                     return(subScene.handle);
                 }
                 else
                 {
                     return(0);
                 }
             }
         }
     }
     return(hierarchyTargetItem.id);
 }
Exemplo n.º 14
0
        public virtual void Drop(List <object> node, DropPosition mode, bool copy)
        {
            bool runningCompositeTask = Services.TaskService.IsRunningCompositeTask;

            if (!runningCompositeTask)
            {
                Services.TaskService.BeginCompositeTask("Drag drop GameObject");
            }
            foreach (object obj in node)
            {
                if (!copy)
                {
                    IDragSource dragSource = obj as IDragSource;
                    if (dragSource != null)
                    {
                        dragSource.Detach();
                    }
                }
                NodeObject gameObjectData = obj as NodeObject;
                if (gameObjectData != null)
                {
                    this.LoadDropObject(gameObjectData, mode);
                }
            }
            if (runningCompositeTask)
            {
                return;
            }
            Services.TaskService.EndCompositeTask();
        }
Exemplo n.º 15
0
            private static Target?GetTarget(DockItem targetItem, DropPosition targetPosition)
            {
                if (targetPosition == DropPosition.Left)
                {
                    return(targetItem == null ? Target.LeftToolWindow : Target.LeftPane(targetItem));
                }
                else if (targetPosition == DropPosition.Right)
                {
                    return(targetItem == null ? Target.RightToolWindow : Target.RightPane(targetItem));
                }
                else if (targetPosition == DropPosition.Top)
                {
                    return(targetItem == null ? Target.TopToolWindow : Target.TopPane(targetItem));
                }
                else if (targetPosition == DropPosition.Bottom)
                {
                    return(targetItem == null ? Target.BottomToolWindow : Target.BottomPane(targetItem));
                }
                else if (targetPosition == DropPosition.Fill)
                {
                    return(targetItem == null ? Target.Document : Target.FillPane(targetItem));
                }
                else if (targetPosition == DropPosition.Tab && targetItem != null)
                {
                    return(Target.Tab(targetItem));
                }

                return(null);
            }
Exemplo n.º 16
0
        private void _tree_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.None;
            if (!e.Data.GetDataPresent(typeof(TreeNodeAdv[])))
            {
                return;
            }

            TreeNodeAdv[] nodes = e.Data.GetData(typeof(TreeNodeAdv[])) as TreeNodeAdv[];
            if (nodes.Length == 0)
            {
                return;
            }

            DropPosition dp = _tree.DropPosition;

            if (dp.Node != null)
            {
                if (dp.Node.Tag is FavouritesNode)
                {
                    if ((dp.Position == NodePosition.Inside && (dp.Node.Tag as FavouritesNode).IsFolder) ||
                        (dp.Position != NodePosition.Inside))
                    {
                        e.Effect = e.AllowedEffect;
                    }
                }
            }
            else
            {
                e.Effect = e.AllowedEffect;
            }
        }
Exemplo n.º 17
0
        public void Drop(object node, DropPosition mode, bool copy)
        {
            var cvm = node as NodeViewModel;

            if (copy)
            {
                cvm = new NodeViewModel(cvm.Node, cvm.Parent);
            }

            switch (mode)
            {
            case DropPosition.Add:
                this.Children.Add(cvm);
                cvm.Parent      = this;
                this.IsExpanded = true;
                break;

            case DropPosition.InsertBefore:
                int index = this.Parent.Children.IndexOf(this);
                Parent.Children.Insert(index, cvm);
                cvm.Parent = this.Parent;
                break;

            case DropPosition.InsertAfter:
                int index2 = this.Parent.Children.IndexOf(this);
                Parent.Children.Insert(index2 + 1, cvm);
                cvm.Parent = this.Parent;
                break;
            }
        }
Exemplo n.º 18
0
        public virtual bool CanDrop(object node, DropPosition mode, bool copy)
        {
            if (copy || !(node is NodeObject) || this.IsAncestor(node as NodeObject))
            {
                return(false);
            }
            NodeObject nodeObject = node as NodeObject;

            switch (mode)
            {
            case DropPosition.InsertBefore:
                if (this.Parent == null || !this.Parent.CanDrop(node, DropPosition.Add, copy))
                {
                    return(false);
                }
                break;

            case DropPosition.InsertAfter:
                if (this.Parent == null || !this.Parent.CanDrop(node, DropPosition.Add, copy))
                {
                    return(false);
                }
                break;
            }
            return(true);
        }
Exemplo n.º 19
0
        private bool OnDragEnding(DropPosition position, RadTreeNode node, RadTreeNode targetNode)
        {
            RadTreeViewDragCancelEventArgs args = new RadTreeViewDragCancelEventArgs(node, targetNode);

            args.DropPosition = position;
            this.owner.OnDragEnding(args);
            return(!args.Cancel);
        }
Exemplo n.º 20
0
 public override bool CanDrop(object node, DropPosition mode, bool copy)
 {
     if (mode != DropPosition.Add)
     {
         return(base.CanDrop(node, mode, copy));
     }
     return(false);
 }
Exemplo n.º 21
0
    public void FreeDropPosition(DropPosition position)
    {
        if (position == null)
        {
            return;
        }

        dropPositions[position.index].inUse = false;
    }
Exemplo n.º 22
0
 public override bool CanDrop(object node, DropPosition mode, bool copy)
 {
     if (mode != DropPosition.Add || node is WidgetObject)
     {
         return(base.CanDrop(node, mode, copy));
     }
     LogConfig.Output.Info((object)LanguageInfo.ListViewOutputMessage);
     return(false);
 }
Exemplo n.º 23
0
 public override bool CanDrop(object node, DropPosition mode, bool copy)
 {
     if (mode != DropPosition.Add || node.GetType().Equals(typeof(PanelObject)))
     {
         return(base.CanDrop(node, mode, copy));
     }
     LogConfig.Logger.Error((object)LanguageInfo.OutputMessage);
     return(false);
 }
Exemplo n.º 24
0
        private void dragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
        {
            GridDataRowElement rowElement = e.DragInstance as GridDataRowElement;

            if (rowElement == null)
            {
                return;
            }
            string          sourceText        = rowElement.RowInfo.Cells[0].Value.ToString();
            TreeNodeElement targetNodeElement = e.HitTarget as TreeNodeElement;

            if (targetNodeElement != null)
            {
                RadTreeViewElement treeViewElement = targetNodeElement.TreeViewElement;
                RadTreeNode        targetNode      = targetNodeElement.Data;
                DropPosition       dropPosition    = this.GetDropPosition(e.DropLocation, targetNodeElement);

                switch (dropPosition)
                {
                case DropPosition.None:
                    break;

                case DropPosition.BeforeNode:
                    radGridView1.Rows.Remove(rowElement.RowInfo);

                    RadTreeNodeCollection nodes = targetNode.Parent == null ? treeViewElement.Nodes : targetNode.Parent.Nodes;
                    nodes.Insert(targetNode.Index, new RadTreeNode(sourceText));

                    break;

                case DropPosition.AfterNode:
                    radGridView1.Rows.Remove(rowElement.RowInfo);

                    RadTreeNodeCollection nodes1 = targetNode.Parent == null ? treeViewElement.Nodes : targetNode.Parent.Nodes;
                    int targetIndex = targetNodeElement.Data.Index <= treeViewElement.Nodes.Count - 1 ?
                                      (targetNodeElement.Data.Index + 1) : treeViewElement.Nodes.Count - 1;
                    nodes1.Insert(targetIndex, new RadTreeNode(sourceText));

                    break;

                case DropPosition.AsChildNode:
                    radGridView1.Rows.Remove(rowElement.RowInfo);

                    targetNode.Nodes.Add(new RadTreeNode(sourceText));

                    break;
                }
            }

            RadTreeViewElement treeElement = e.HitTarget as RadTreeViewElement;

            if (treeElement != null)
            {
                radGridView1.Rows.Remove(rowElement.RowInfo);
                radTreeView1.Nodes.Add(new RadTreeNode(sourceText));
            }
        }
Exemplo n.º 25
0
 protected override bool CanDragOver(
     DropPosition dropPosition,
     TreeNodeElement targetNodeElement)
 {
     if ((this.Owner as RadDataFilterElement).RootNode == targetNodeElement.Data && dropPosition != DropPosition.AsChildNode)
     {
         return(false);
     }
     return(base.CanDragOver(dropPosition, targetNodeElement));
 }
Exemplo n.º 26
0
        protected virtual void PerformDragDrop(
            Point dropLocation,
            TreeNodeElement targetNodeElement,
            List <RadTreeNode> draggedNodes)
        {
            RadTreeNode  data         = targetNodeElement.Data;
            DropPosition dropPosition = this.GetDropPosition(dropLocation, targetNodeElement);

            if (dropPosition == DropPosition.AsChildNode)
            {
                bool isCopyingNodes = this.IsCopyingNodes;
                int  index          = 0;
                while (index < draggedNodes.Count)
                {
                    if (!this.OnDragEnding(dropPosition, draggedNodes[index], data))
                    {
                        draggedNodes.RemoveAt(index);
                    }
                    else
                    {
                        ++index;
                    }
                }
                if (this.owner.bindingProvider.CanDrop || data.treeView != null && data.treeView.bindingProvider.CanDrop)
                {
                    this.owner.bindingProvider.DropNodes(data, draggedNodes);
                    foreach (RadTreeNode draggedNode in draggedNodes)
                    {
                        this.owner.OnDragEnded(new RadTreeViewDragEventArgs(draggedNode, data));
                    }
                }
                else
                {
                    foreach (RadTreeNode draggedNode in draggedNodes)
                    {
                        RadTreeNode radTreeNode = draggedNode;
                        if (isCopyingNodes)
                        {
                            radTreeNode = this.CreateTreeNode(radTreeNode);
                        }
                        else
                        {
                            radTreeNode.Remove();
                        }
                        data.Nodes.Add(radTreeNode);
                        this.owner.OnDragEnded(new RadTreeViewDragEventArgs(radTreeNode, data));
                    }
                }
                data.Expand();
            }
            else
            {
                this.PerformDragDropCore(dropPosition, data, draggedNodes);
            }
        }
Exemplo n.º 27
0
        private double GetDropPositionFeedbackOffset(GridViewRow row, DropPosition dropPosition)
        {
            var yOffset = row.TransformToVisual(this.dropPositionFeedbackPresenterHost).Transform(new Point(0, 0)).Y;

            if (dropPosition == DropPosition.After)
            {
                yOffset += row.ActualHeight;
            }
            yOffset -= (this.dropPositionFeedbackPresenter.ActualHeight / 2.0);
            return(yOffset);
        }
Exemplo n.º 28
0
 public virtual bool CanDropNode(object dataObject, DragOperation operation, DropPosition position)
 {
     if (position == DropPosition.Into)
     {
         return(CanDropNode(dataObject, operation));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 29
0
 internal static bool CanHandleDropFromChild(object [] dataObjects, DropPosition position)
 {
     foreach (var o in dataObjects)
     {
         if (!(o is ProjectFolder || o is ProjectFile))
         {
             return(false);
         }
     }
     return(position == DropPosition.Into);
 }
Exemplo n.º 30
0
        protected virtual bool CanDragOver(DropPosition dropPosition, TreeNodeElement targetNodeElement)
        {
            RadTreeViewElement targetTreeView = targetNodeElement.TreeViewElement;

            if (!targetNodeElement.Enabled || !targetTreeView.ElementTree.Control.AllowDrop || !this.IsInValidState(targetTreeView))
            {
                return(false);
            }

            RadTreeNode        targetNode = targetNodeElement.Data;
            List <RadTreeNode> nodes      = new List <RadTreeNode>(draggedNode.TreeViewElement.SelectedNodes);

            // If the count is empty, we are in single selection mode
            if (nodes.Count == 0)
            {
                nodes.Add(draggedNode);
            }

            foreach (RadTreeNode selected in nodes)
            {
                if (selected == targetNode)
                {
                    return(false);
                }

                RadTreeNode parent = targetNode.Parent;

                while (parent != null)
                {
                    if (parent == selected)
                    {
                        return(false);
                    }

                    parent = parent.Parent;
                }

                if (dropPosition == DropPosition.AsChildNode && selected.Parent == targetNode)
                {
                    return(false);
                }
            }

            if (dropPosition == DropPosition.AsChildNode)
            {
                targetTreeView.AutoExpand(targetNode);
            }

            targetTreeView.AutoScroll(targetNodeElement);
            return(true);
        }
Exemplo n.º 31
0
        public bool CanDrop(IDragSource node, DropPosition mode, DragDropEffect effect)
        {
            var cvm2 = this;

            while (cvm2 != null)
            {
                if (cvm2 == node)
                {
                    return(false);
                }
                cvm2 = cvm2.Parent;
            }
            return(node is NodeViewModel && (mode == DropPosition.Add || this.Parent != null));
        }
Exemplo n.º 32
0
        public override bool CanDrop(object node, DropPosition mode, bool copy)
        {
            bool result;

            if (mode == DropPosition.Add)
            {
                if (!(node is WidgetObject))
                {
                    LogConfig.Output.Info(LanguageInfo.ListViewOutputMessage);
                    result = false;
                    return(result);
                }
            }
            result = base.CanDrop(node, mode, copy);
            return(result);
        }
Exemplo n.º 33
0
        public void Move(PageItem from, PageItem to, DropPosition dropPosition)
        {
            var pageCache = PageCache.From(_session);

            if (dropPosition == DropPosition.Over)
            {
                to.Pages.Add(from);
                to.Pages.AdjustOrders(false);
                return;
            }

            if (dropPosition == DropPosition.Before)
            {
                var pages = new PageItemCollectionWrapper(to.Parent == null ? pageCache.RootPages : to.Parent.Pages);

                if (from.IsSiblingOf(to))
                {
                    pages.MoveBefore(to, from);
                }
                else
                {
                    pages.AddBefore(to, from);
                }

                pages.AdjustOrders(false);

                return;
            }

            if (dropPosition == DropPosition.After)
            {
                var pages = new PageItemCollectionWrapper(to.Parent == null ? pageCache.RootPages : to.Parent.Pages);

                if (from.IsSiblingOf(to))
                {
                    pages.MoveAfter(to, from);
                }
                else
                {
                    pages.AddAfter(to, from);
                }

                pages.AdjustOrders(false);
            }
        }
Exemplo n.º 34
0
        public void Drop(IDragSource node, DropPosition mode, bool copy)
        {
            var cvm = node as NodeViewModel;
            if (copy) cvm = new NodeViewModel(cvm.Node, cvm.Parent);

            switch (mode)
            {
                case DropPosition.Add:
                    this.Children.Add(cvm);
                    cvm.Parent = this;
                    this.IsExpanded = true;
                    break;
                case DropPosition.InsertBefore:
                    int index = this.Parent.Children.IndexOf(this);
                    Parent.Children.Insert(index, cvm);
                    cvm.Parent = this.Parent;
                    break;
                case DropPosition.InsertAfter:
                    int index2 = this.Parent.Children.IndexOf(this);
                    Parent.Children.Insert(index2 + 1, cvm);
                    cvm.Parent = this.Parent;
                    break;
            }
        }
Exemplo n.º 35
0
    public void FreeDropPosition(DropPosition position)
    {
        if (position == null) return;

        dropPositions[position.index].inUse = false;
    }
Exemplo n.º 36
0
 public static string ConverDropPositionToString(DropPosition dropPosition)
 {
     switch (dropPosition)
     {
         case DropPosition.After:
             return "的后面";
         case DropPosition.Before:
             return "的前面";
         default:
             return "的里面";
     }
 }
Exemplo n.º 37
0
        /// <summary>
        /// Decides the drop target.
        /// </summary>
        /// <param name="e">
        /// The event args.
        /// </param>
        private void DecideDropTarget(DragEventArgs e)
        {
            // If the types of the dragged data and ItemsControl's source are compatible,
            // there are 3 situations to have into account when deciding the drop target:
            // 1. mouse is over an items container
            // 2. mouse is over the empty part of an ItemsControl, but ItemsControl is not empty
            // 3. mouse is over an empty ItemsControl.
            // The goal of this method is to decide on the values of the following properties:
            // targetItemContainer, insertionIndex and isInFirstHalf.
            int targetItemsControlCount = this.targetItemsControl.Items.Count;
            var draggedItems = e.Data.GetData(this.format.Name) as IList;

            if (targetItemsControlCount > 0)
            {
                this.hasVerticalOrientation = true;
                this.targetItemContainer =
                    this.targetItemsControl.ContainerFromElement((DependencyObject)e.OriginalSource) as TreeListBoxItem;

                if (this.targetItemContainer != null)
                {
                    Point positionRelativeToItemContainer = e.GetPosition(this.targetItemContainer);
                    double relativePosition = GetRelativePosition(
                        this.targetItemContainer, positionRelativeToItemContainer, this.hasVerticalOrientation);
                    this.isInFirstHalf = relativePosition < 0.5;

                    if (relativePosition > 0.3 && relativePosition < 0.7)
                    {
                        this.dropPosition = DropPosition.Add;
                    }
                    else
                    {
                        this.dropPosition = relativePosition < 0.5
                                                ? DropPosition.InsertBefore
                                                : DropPosition.InsertAfter;
                    }
                }
                else
                {
                    this.targetItemContainer = this.targetItemsControl.ContainerFromIndex(targetItemsControlCount - 1);
                    this.isInFirstHalf = false;
                    this.dropPosition = DropPosition.InsertAfter;
                }
            }
            else
            {
                this.targetItemContainer = null;
                this.dropPosition = DropPosition.InsertBefore;
            }

            if (this.targetItemContainer != null && draggedItems != null)
            {
                var dropTarget = this.targetItemContainer.DataContext as IDropTarget;
                bool copy = (e.Effects & DragDropEffects.Copy) != 0;

                foreach (var draggedItem in draggedItems)
                {
                    var dragSource = draggedItem as IDragSource;
                    if ((dragSource == null || !dragSource.IsDraggable)
                        || (dropTarget == null || !dropTarget.CanDrop(dragSource, this.dropPosition, copy)))
                    {
                        this.targetItemContainer = null;
                        e.Effects = DragDropEffects.None;
                        return;
                    }
                }
            }
        }
Exemplo n.º 38
0
 public bool CanDrop(IDragSource node, DropPosition mode, DragDropEffect effect)
 {
     return node is NodeViewModel && (mode == DropPosition.Add || this.Parent != null);
 }
Exemplo n.º 39
0
		public virtual void OnNodeDrop (object dataObjects, DragOperation operation, DropPosition position)
		{
			OnNodeDrop (dataObjects, operation);
		}
		public override bool CanDropNode (object dataObject, DragOperation operation, DropPosition position)
		{
			return false;
		}
Exemplo n.º 41
0
 public abstract DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPosition);
Exemplo n.º 42
0
		public override bool CanDropNode (object dataObject, DragOperation operation, DropPosition pos)
		{
			object parent1 = CurrentNode.GetParentDataItem (typeof(Extension), false);
			if (parent1 == null)
				parent1 = CurrentNode.GetParentDataItem (typeof(ExtensionPoint), false);
			
			ITreeNavigator nav = CurrentNode.Clone ();
			if (!nav.MoveToObject (dataObject))
				return false;
			object parent2 = nav.GetParentDataItem (parent1.GetType (), false);
			if (parent2 != parent1)
				return false;
			
			return true;
		}
		public override bool CanDropMultipleNodes (object[] dataObjects, DragOperation operation, DropPosition position)
		{
			foreach (object dataObject in dataObjects) 
				if (dataObjects is GuiProjectFolder)
					return false;
			
			return base.CanDropMultipleNodes (dataObjects, operation, position);
		}
Exemplo n.º 44
0
		public override void OnMultipleNodeDrop (object[] dataObjects, DragOperation operation, DropPosition pos)
		{
			DotNetProject p = (DotNetProject) CurrentNode.GetParentDataItem (typeof(Project), false);
			AddinData adata = p.GetAddinData ();
			
			ExtensionNodeInfo en = (ExtensionNodeInfo) CurrentNode.DataItem;

			foreach (ExtensionNodeInfo newNode in dataObjects) {
				if (newNode.Node.Parent is ExtensionNodeDescription)
					((ExtensionNodeDescription)newNode.Node.Parent).ChildNodes.Remove (en.Node);
				else
					((Extension)newNode.Node.Parent).ExtensionNodes.Remove (newNode.Node);
				InsertNode (adata, en, pos, newNode.Node);
				
				// Add all other nodes after the first node
				en = newNode;
				pos = DropPosition.After;
			}
			
			adata.CachedAddinManifest.Save ();
			adata.NotifyChanged (false);
		}
Exemplo n.º 45
0
		public virtual bool CanDropNode (object dataObject, DragOperation operation, DropPosition position)
		{
			if (position == DropPosition.Into)
				return CanDropNode (dataObject, operation);
			else
				return false;
		}
		public override bool CanDropMultipleNodes (object[] dataObjects, DragOperation operation, DropPosition position)
		{
			return false;
		}
Exemplo n.º 47
0
		public virtual bool CanDropMultipleNodes (object[] dataObjects, DragOperation operation, DropPosition position)
		{
			cachedPosition = position;
			return CanDropMultipleNodes (dataObjects, operation);
		}
Exemplo n.º 48
0
 public bool CanDrop(object node, DropPosition mode, bool copy)
 {
     return node is NodeViewModel && (mode == DropPosition.Add || this.Parent != null);
 }
Exemplo n.º 49
0
		public virtual void OnMultipleNodeDrop (object[] dataObjects, DragOperation operation, DropPosition position)
		{
			cachedPosition = position;
			OnMultipleNodeDrop (dataObjects, operation);
		}
Exemplo n.º 50
0
		ExtensionNodeDescription InsertNode (AddinData adata, ExtensionNodeInfo refNode, DropPosition pos, ExtensionNodeDescription newNode)
		{
			ExtensionNodeDescriptionCollection nodes = null;
			newNode.InsertBefore = "";
			newNode.InsertAfter = "";
			
			if (refNode.CanModify) {
				if (pos == DropPosition.Into)
					nodes = refNode.Node.ChildNodes;
				else if (refNode.Node.Parent is ExtensionNodeDescription)
					nodes = ((ExtensionNodeDescription)refNode.Node.Parent).ChildNodes;
			} else {
				if (pos == DropPosition.After)
				    newNode.InsertAfter = refNode.Node.Id;
				else if (pos == DropPosition.Before)
					newNode.InsertBefore = refNode.Node.Id;
			}
			if (nodes == null) {
				string path = refNode.Node.GetParentPath ();
				if (pos == DropPosition.Into)
					path += "/" + refNode.Node.Id;
				Extension ext = adata.CachedAddinManifest.MainModule.GetExtension (path);
				nodes = ext.ExtensionNodes;
			}

			for (int n = 0; n < nodes.Count; n++) {
				ExtensionNodeDescription node = nodes [n];
				if (node == refNode.Node) {
					if (pos == DropPosition.After) n++;
					nodes.Insert (n, newNode);
					return newNode;
				}
			}
			nodes.Add (newNode);
			return newNode;
		}