chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using GongSolutions.Wpf.DragDrop;
using Keysight.OpenTap.Wpf;
using OpenTap;
using System.Collections.ObjectModel;
using System.Windows;
 
namespace OpenTapEditor.Util
{
    public class StepTreeDragHandler: DefaultDropHandler
    {
        public bool CanConvert(IDropInfo dropInfo)
        {
            if (!(dropInfo.TargetItem is TestStep target))
            {
                return false;
            }
 
            if (!(dropInfo.Data is TestStep source))
            {
                return false;
            }
 
            if (source == target)
            {
                return false;
            }
            var t = target.GetType();
            var s = source.GetType();
            var sss = TestStepList.AllowChild(t, s);
 
            if (!TestStepList.AllowChild(target.GetType(), source.GetType()))
            {
                return false;
            }
 
            //if(source.)
 
            //if (target.sequence != source.sequence)
            //{
            //    return false;
            //}
            return true;
        }
 
        public override void DragOver(IDropInfo dropInfo)
        {
            if (CanConvert(dropInfo))
            {
                dropInfo.Effects = DragDropEffects.Move;
 
                if (dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter))
                {
                    dropInfo.DropTargetAdorner = null;
                }
                else
                {
                    dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
                }
 
                //if (dropInfo.DropTargetAdorner == DropTargetAdorners.Highlight) { 
 
                //}
                //dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
                dropInfo.DropTargetHintState = DropHintState.Active;
                dropInfo.DropTargetHintAdorner = DropTargetAdorners.Hint;
            }
            else
            {
                dropInfo.Effects = DragDropEffects.None;
                dropInfo.DropTargetHintAdorner = DropTargetAdorners.Hint;
                dropInfo.DropTargetHintState = DropHintState.Error;
            }
        }
 
        //public override void Drop(IDropInfo dropInfo)
        //{
        //    if (!CanConvert(dropInfo))
        //    {
        //        return;
        //    }
        //    //var sourceItem = (TreeItemData)dropInfo.Data;
        //    //var targetItem = (TreeItemData)dropInfo.TargetItem;
 
        //    var source = dropInfo.Data as TestStep;
        //    var target = dropInfo.TargetItem as TestStep;
 
        //    int sourceIndex = source.IndexInSequence;
        //    int targetIndex = target.IndexInSequence;
 
 
        //    if (sourceIndex == targetIndex)
        //    {
        //        return;
        //    }
 
        //    bool insertBefore = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.BeforeTargetItem);
 
        //    if (!insertBefore && (sourceIndex == targetIndex + 1))
        //    {
        //        return;
        //    }
 
        //    ObservableCollection<StepUI> datasource = model.sequenceCache[source.sequence];
        //    int uiSourceIndex = datasource.IndexOf(source);
        //    int uiTargetIndex = datasource.IndexOf(target);
 
        //    StepGroups group = target.StepGroup;
 
        //    if (sourceIndex < targetIndex)
        //    {
        //        source.sequence.DeleteStep(sourceIndex, source.StepGroup);
        //        target.sequence.InsertStep(source.step, targetIndex, group);
        //        datasource.Move(uiSourceIndex, uiTargetIndex);
        //    }
        //    else if (sourceIndex > targetIndex)
        //    {
        //        source.sequence.DeleteStep(sourceIndex, source.StepGroup);
        //        target.sequence.InsertStep(source.step, targetIndex, group);
        //        datasource.Move(uiSourceIndex, uiTargetIndex);
        //    }
        //}
    }
}