-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagControl.xaml.cs
106 lines (96 loc) · 3.45 KB
/
TagControl.xaml.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SmartGrid
{
/// <summary>
/// Interaction logic for TagControl.xaml
/// </summary>
public partial class TagControl : UserControl
{
public TagControl()
{
InitializeComponent();
}
private bool CopyMode { get { return Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl); } }
private Node[] SelectedNodes
{
get { return lstMain.SelectedItems.OfType<Node>().ToArray(); }
}
private TagWrap CurTag { get { return lstMain.DataContext as TagWrap; } }
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
var element = sender as FrameworkElement;
var headNode = element.DataContext as HeadNode;
headNode.AddToTag();
}
private void NodeList_Drop(object sender, DragEventArgs e)
{
var data = (Node[])e.Data.GetData(typeof(Node[]));
if (data == null || !data.Any()) return;
var tag = data.First().Tag;
if (tag == CurTag) return;
if (CopyMode)
{
var clones = data.Select(d => d.GetClone());
foreach (Node clone in clones)
clone.Tag = CurTag;
CurTag.Tag.Add(data);
}
else
{
var oldTag = data.First().Tag;
foreach (Node node in data)
node.Tag = CurTag;
CurTag.Tag.Add(data);
oldTag.Tag.Remove(data);
}
}
private void Drag_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var element = (FrameworkElement)sender;
var node = element.DataContext as Node;
if (node == null) return;
var data = SelectedNodes.ToList();
if (!data.Any(d => d.Header.Equals(node.Header, StringComparison.OrdinalIgnoreCase)))
data.Add(node);
var dragEfect = CopyMode ? DragDropEffects.Copy : DragDropEffects.Move;
DragDrop.DoDragDrop(element, data.ToArray(), dragEfect);
e.Handled = false;
}
private void BtnDel_OnClick(object sender, RoutedEventArgs e)
{
CurTag.Tag.Remove(SelectedNodes);
}
private void btnExpand_Click(object sender, RoutedEventArgs e)
{
}
private void CanvTag_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var element = (FrameworkElement)sender;
var tag = element.DataContext as TagWrap;
if (tag == null) return;
var dragEfect = CopyMode ? DragDropEffects.Copy : DragDropEffects.Move;
DragDrop.DoDragDrop(element, tag, dragEfect);
e.Handled = false;
}
private void Tag_Drop(object sender, DragEventArgs e)
{
var second = e.Data.GetData(typeof(TagWrap)) as TagWrap;
if (second == null) return;
CurTag.SwapWith(second);
}
}
}