forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShortcutHandler.cs
More file actions
51 lines (43 loc) · 1.47 KB
/
Copy pathShortcutHandler.cs
File metadata and controls
51 lines (43 loc) · 1.47 KB
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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.Experimental.UIElements.GraphView
{
public delegate EventPropagation ShortcutDelegate();
public class ShortcutHandler : Manipulator
{
readonly Dictionary<Event, ShortcutDelegate> m_Dictionary;
public ShortcutHandler(Dictionary<Event, ShortcutDelegate> dictionary)
{
m_Dictionary = dictionary;
}
protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback<KeyDownEvent>(OnKeyDown);
}
protected override void UnregisterCallbacksFromTarget()
{
target.UnregisterCallback<KeyDownEvent>(OnKeyDown);
}
void OnKeyDown(KeyDownEvent evt)
{
if (MouseCaptureController.IsMouseCaptureTaken())
return;
if (m_Dictionary.ContainsKey(evt.imguiEvent))
{
EventPropagation result = m_Dictionary[evt.imguiEvent]();
if (result == EventPropagation.Stop)
{
evt.StopPropagation();
if (evt.imguiEvent != null)
{
evt.imguiEvent.Use();
}
}
}
}
}
}