コード例 #1
0
 private static void Cancel()
 {
     dropInfo?.DropTargetAdorner?.Detach();
     dropInfo = null;
     dragInfo = null;
 }
コード例 #2
0
        public static void HandleDropForTarget(DragDropEffects result, DragEventArgs e = null)
        {
            System.Diagnostics.Debug.WriteLine($"HandleDropForTarget: {dropInfo.TargetItem.Item}");
            IEnumerable <CmdBase> data = DropInfo.ExtractDropData(dragInfo, e);

            if (dropInfo.CanAcceptData(data) &&
                (result.HasFlag(DragDropEffects.Move) || result.HasFlag(DragDropEffects.Copy)))
            {
                var idx = dropInfo.InsertIndex;
                if (result.HasFlag(DragDropEffects.Copy))
                {
                    data = data.Select(cmd => cmd.Copy());
                }

                var dataList = data.ToList();

                var souldDeselctItem = dropInfo.InsertPosition.HasFlag(DropInfo.RelativInsertPosition.IntoTargetItem) &&
                                       dropInfo.TargetItem.Item is CmdContainer tarCon &&
                                       !tarCon.IsExpanded;

                if (dataList.Count > 0)
                {
                    ToolWindowHistory.SaveState();
                }

                foreach (var sourceItem in dataList)
                {
                    if (souldDeselctItem)
                    {
                        if (sourceItem is CmdContainer con)
                        {
                            con.GetEnumerable(useView: false, includeSelf: true)
                            .ForEach(item => item.IsSelected = false);
                        }
                        else
                        {
                            sourceItem.IsSelected = false;
                        }
                    }

                    dropInfo.TargetContainer.Insert(idx++, sourceItem);
                }

                var focusItem = dragInfo?.DirectSourceItem ?? dataList.FirstOrDefault();

                var selectItemCommand = dropInfo.TargetItem.ParentTreeView.SelectItemCommand;
                if (souldDeselctItem)
                {
                    selectItemCommand.SafeExecute(dropInfo.TargetItem.Item);
                }
                else if (selectItemCommand.SafeExecute(focusItem))
                {
                    foreach (var sourceItem in dataList)
                    {
                        sourceItem.IsSelected = true;
                    }
                }
            }
            else
            {
                if (e != null)
                {
                    e.Effects = DragDropEffects.None;
                }
            }

            dropInfo?.DropTargetAdorner?.Detach();
            dropInfo = null;
        }