Exemplo n.º 1
0
        private void TreeView_Drop(object sender, DragEventArgs e)
        {
            // 背景色やセパレータを元に戻します
            ResetDragOver(_changedBlocks);

            e.Handled = true;

            if (IsRenamingInProgress)
            {
                return;
            }

            if (_draggingItem is NodeFeed)
            {
                if (!(((_draggingItem as NodeFeed).Status == NodeFeed.DownloadStatus.normal) || ((_draggingItem as NodeFeed).Status == NodeFeed.DownloadStatus.error)))
                {
                    return;
                }
            }

            try
            {
                // Verify that this is a valid drop and then store the drop target
                NodeTree TargetItem = GetNearestContainer(e.OriginalSource as UIElement);
                if (TargetItem != null && _draggingItem != null)
                {
                    // カーソル要素がドラッグ中の要素の子要素にある時は何もする必要がないのでreturn
                    if (TargetItem.ContainsChild(_draggingItem))
                    {
                        return;
                    }
                    if (_draggingItem.ContainsChild(TargetItem))
                    {
                        return;
                    }

                    _targetItem = TargetItem;
                    e.Effects   = DragDropEffects.Move;
                }
                else
                {
                    e.Effects = DragDropEffects.None;
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 2
0
        private void TreeView_DragOver(object sender, DragEventArgs e)
        {
            // 背景色やセパレータを元に戻します
            ResetDragOver(_changedBlocks);

            if (IsRenamingInProgress)
            {
                return;
            }

            try
            {
                Point currentPosition = e.GetPosition(this.TreeViewMenu);

                if ((Math.Abs(currentPosition.X - this._lastLeftMouseButtonDownPoint.X) > 10.0) || (Math.Abs(currentPosition.Y - this._lastLeftMouseButtonDownPoint.Y) > 10.0))
                {
                    // Verify that this is a valid drop and then store the drop target
                    NodeTree item = GetNearestContainer(e.OriginalSource as UIElement);

                    if (CheckDropTarget(_draggingItem, item))
                    {
                        // カーソル要素がドラッグ中の要素の子要素にある時は何もする必要がないのでreturn
                        if (item.ContainsChild(_draggingItem))
                        {
                            return;
                        }
                        if (_draggingItem.ContainsChild(item))
                        {
                            return;
                        }
                        // Folderを別のFolder内にはドロップさせない
                        if ((_draggingItem is NodeFolder) && (item.Parent is NodeFolder))
                        {
                            return;
                        }
                        // ServiceをFolder内にドロップさせない。
                        if ((_draggingItem is NodeService) && (_draggingItem is not NodeFeed) && (item.Parent is NodeFolder))
                        {
                            return;
                        }

                        var pos = e.GetPosition(e.OriginalSource as UIElement);
                        if (pos.Y > 0 && pos.Y < 10.0)
                        {
                            _insertType = InsertType.Before;

                            e.Effects = DragDropEffects.Move;

                            item.IsBeforeDragSeparator = true;

                            // 背景色などを変更したTreeViewItemInfoオブジェクトを_changedBlocksに追加
                            if (!_changedBlocks.Contains(item))
                            {
                                _changedBlocks.Add(item);
                            }
                        }

                        /*
                         * else if (targetParentLast == targetElementInfo && currentPosition.Y < parentGrid.ActualHeight && currentPosition.Y > parentGrid.ActualHeight - 10.0)
                         * {
                         * //_insertType = InsertType.After;
                         * //targetElementInfo.AfterSeparatorVisibility = Visibility.Visible;
                         * //e.Effects = DragDropEffects.Move;
                         * }
                         */
                        else
                        {
                            if (_draggingItem is NodeService)
                            {
                                if (_draggingItem is not NodeFeed)
                                {
                                    if ((item is NodeFolder) || (item.Parent is NodeFolder))
                                    {
                                        e.Effects = DragDropEffects.None;
                                        return;
                                    }
                                }
                            }

                            if ((_draggingItem is NodeFolder) && (item is NodeFolder))
                            {
                                e.Effects = DragDropEffects.None;
                                return;
                            }

                            if (item is NodeFolder)
                            {
                                _insertType = InsertType.Children;

                                e.Effects = DragDropEffects.Move;

                                // Change background color.
                                item.IsDragOver = true;

                                // 背景色などを変更したTreeViewItemInfoオブジェクトを_changedBlocksに追加
                                if (!_changedBlocks.Contains(item))
                                {
                                    _changedBlocks.Add(item);
                                }
                            }
                            else
                            {
                                e.Effects = DragDropEffects.None;
                            }
                        }
                    }
                    else
                    {
                        e.Effects = DragDropEffects.None;
                    }
                }
                else
                {
                    e.Effects = DragDropEffects.None;
                }

                e.Handled = true;
            }
            catch (Exception) { }
        }