-
-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathEditorView.xaml.cs
59 lines (51 loc) · 2.21 KB
/
EditorView.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
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Nodify.Calculator
{
public partial class EditorView : UserControl
{
public EditorView()
{
InitializeComponent();
EventManager.RegisterClassHandler(typeof(NodifyEditor), MouseLeftButtonDownEvent, new MouseButtonEventHandler(CloseOperationsMenu), true);
EventManager.RegisterClassHandler(typeof(NodifyEditor), MouseRightButtonUpEvent, new MouseButtonEventHandler(OpenOperationsMenu));
}
private void OpenOperationsMenu(object sender, MouseButtonEventArgs e)
{
if (e.OriginalSource is NodifyEditor editor && editor.DataContext is CalculatorViewModel calculator)
{
e.Handled = true;
calculator.OperationsMenu.OpenAt(editor.MouseLocation);
}
}
private void CloseOperationsMenu(object sender, MouseButtonEventArgs e)
{
ItemContainer? itemContainer = sender as ItemContainer;
NodifyEditor? editor = sender as NodifyEditor ?? itemContainer?.Editor;
if (editor?.DataContext is CalculatorViewModel calculator)
{
calculator.OperationsMenu.Close();
}
}
private void OnDropNode(object sender, DragEventArgs e)
{
if(e.Source is NodifyEditor editor && editor.DataContext is CalculatorViewModel calculator
&& e.Data.GetData(typeof(OperationInfoViewModel)) is OperationInfoViewModel operation)
{
OperationViewModel op = OperationFactory.GetOperation(operation);
op.Location = editor.GetLocationInsideEditor(e);
calculator.Operations.Add(op);
e.Handled = true;
}
}
private void OnNodeDrag(object sender, MouseEventArgs e)
{
if(e.LeftButton == MouseButtonState.Pressed && ((FrameworkElement)sender).DataContext is OperationInfoViewModel operation)
{
var data = new DataObject(typeof(OperationInfoViewModel), operation);
DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
}
}
}
}