Shortcuts.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using System;
  2. using JetBrains.Annotations;
  3. using UnityEditor.ShortcutManagement;
  4. using UnityEngine;
  5. namespace UnityEditor.Timeline
  6. {
  7. static class Shortcuts
  8. {
  9. public static class Clip
  10. {
  11. public const string split = "Timeline/Editing/Split";
  12. public const string trimStart = "Timeline/Editing/TrimStart";
  13. public const string trimEnd = "Timeline/Editing/TrimEnd";
  14. [UsedImplicitly, ShortcutManagement.Shortcut(split, typeof(TimelineWindow), KeyCode.S)]
  15. static void Split(ShortcutManagement.ShortcutArguments args)
  16. {
  17. SendEventToInvokeShortcut(split, args.context);
  18. }
  19. [UsedImplicitly, ShortcutManagement.Shortcut(trimStart, typeof(TimelineWindow), KeyCode.I)]
  20. static void TrimStart(ShortcutManagement.ShortcutArguments args)
  21. {
  22. SendEventToInvokeShortcut(trimStart, args.context);
  23. }
  24. [UsedImplicitly, ShortcutManagement.Shortcut(trimEnd, typeof(TimelineWindow), KeyCode.O)]
  25. static void TrimEnd(ShortcutManagement.ShortcutArguments args)
  26. {
  27. SendEventToInvokeShortcut(trimEnd, args.context);
  28. }
  29. }
  30. public static class Timeline
  31. {
  32. public const string play = "Timeline/Play";
  33. public const string previousFrame = "Timeline/PrevFrame";
  34. public const string nextFrame = "Timeline/NextFrame";
  35. public const string frameAll = "Timeline/FrameAll";
  36. public const string previousKey = "Timeline/PrevKey";
  37. public const string nextKey = "Timeline/NextKey";
  38. public const string goToStart = "Timeline/GotoStart";
  39. public const string goToEnd = "Timeline/GotoEnd";
  40. public const string zoomIn = "Timeline/ZoomIn";
  41. public const string zoomOut = "Timeline/ZoomOut";
  42. public const string collapseGroup = "Timeline/CollapseGroup";
  43. public const string unCollapseGroup = "Timeline/UnCollapseGroup";
  44. public const string selectLeftItem = "Timeline/SelectLeftItem";
  45. public const string selectRightItem = "Timeline/SelectRightItem";
  46. public const string selectUpItem = "Timeline/SelectUpItem";
  47. public const string selectUpTrack = "Timeline/SelectUpTrack";
  48. public const string selectDownItem = "Timeline/SelectDownItem";
  49. public const string selectDownTrack = "Timeline/SelectDownTrack";
  50. public const string multiSelectLeft = "Timeline/SelectLeft";
  51. public const string multiSelectRight = "Timeline/SelectRight";
  52. public const string multiSelectUp = "Timeline/SelectUp";
  53. public const string multiSelectDown = "Timeline/SelectDown";
  54. public const string toggleClipTrackArea = "Timeline/ToggleClipTrackArea";
  55. public const string matchContent = "Timeline/MatchContent";
  56. public const string toggleLock = "Timeline/ToggleLock";
  57. public const string toggleMute = "Timeline/ToggleMute";
  58. public const string moveLeft = "Timeline/MoveLeft";
  59. public const string moveRight = "Timeline/MoveRight";
  60. public const string moveUp = "Timeline/MoveUp";
  61. public const string moveDown = "Timeline/MoveDown";
  62. [UsedImplicitly, ShortcutManagement.Shortcut(play, typeof(TimelineWindow), KeyCode.Space)]
  63. static void Play(ShortcutManagement.ShortcutArguments args)
  64. {
  65. SendEventToInvokeShortcut(play, args.context);
  66. }
  67. [UsedImplicitly, ShortcutManagement.Shortcut(previousFrame, typeof(TimelineWindow), KeyCode.Comma)]
  68. static void PreviousFrame(ShortcutManagement.ShortcutArguments args)
  69. {
  70. SendEventToInvokeShortcut(previousFrame, args.context);
  71. }
  72. [UsedImplicitly, ShortcutManagement.Shortcut(nextFrame, typeof(TimelineWindow), KeyCode.Period)]
  73. static void NextFrame(ShortcutManagement.ShortcutArguments args)
  74. {
  75. SendEventToInvokeShortcut(nextFrame, args.context);
  76. }
  77. [UsedImplicitly, ShortcutManagement.Shortcut(frameAll, typeof(TimelineWindow), KeyCode.A)]
  78. static void FrameAll(ShortcutManagement.ShortcutArguments args)
  79. {
  80. SendEventToInvokeShortcut(frameAll, args.context);
  81. }
  82. #if UNITY_EDITOR_OSX
  83. [UsedImplicitly, ShortcutManagement.Shortcut(previousKey, typeof(TimelineWindow), KeyCode.Comma, ShortcutModifiers.Action | ShortcutModifiers.Shift)]
  84. #else
  85. [UsedImplicitly, ShortcutManagement.Shortcut(previousKey, typeof(TimelineWindow), KeyCode.Comma, ShortcutModifiers.Action)]
  86. #endif
  87. static void PrevKey(ShortcutManagement.ShortcutArguments args)
  88. {
  89. SendEventToInvokeShortcut(previousKey, args.context);
  90. }
  91. #if UNITY_EDITOR_OSX
  92. [UsedImplicitly, ShortcutManagement.Shortcut(nextKey, typeof(TimelineWindow), KeyCode.Period, ShortcutModifiers.Action | ShortcutModifiers.Shift)]
  93. #else
  94. [UsedImplicitly, ShortcutManagement.Shortcut(nextKey, typeof(TimelineWindow), KeyCode.Period, ShortcutModifiers.Action)]
  95. #endif
  96. static void NextKey(ShortcutManagement.ShortcutArguments args)
  97. {
  98. SendEventToInvokeShortcut(nextKey, args.context);
  99. }
  100. [UsedImplicitly, ShortcutManagement.Shortcut(goToStart, typeof(TimelineWindow), KeyCode.Comma, ShortcutModifiers.Shift)]
  101. static void GoToStart(ShortcutManagement.ShortcutArguments args)
  102. {
  103. SendEventToInvokeShortcut(goToStart, args.context);
  104. }
  105. [UsedImplicitly, ShortcutManagement.Shortcut(goToEnd, typeof(TimelineWindow), KeyCode.Period, ShortcutModifiers.Shift)]
  106. static void GoToEnd(ShortcutManagement.ShortcutArguments args)
  107. {
  108. SendEventToInvokeShortcut(goToEnd, args.context);
  109. }
  110. [UsedImplicitly, ShortcutManagement.Shortcut(zoomIn, typeof(TimelineWindow), KeyCode.Equals)]
  111. static void ZoomIn(ShortcutManagement.ShortcutArguments args)
  112. {
  113. SendEventToInvokeShortcut(zoomIn, args.context);
  114. }
  115. [UsedImplicitly, ShortcutManagement.Shortcut(zoomOut, typeof(TimelineWindow), KeyCode.Minus)]
  116. static void ZoomOut(ShortcutManagement.ShortcutArguments args)
  117. {
  118. SendEventToInvokeShortcut(zoomOut, args.context);
  119. }
  120. [UsedImplicitly]
  121. [ShortcutManagement.Shortcut(moveLeft, typeof(TimelineWindow), KeyCode.LeftArrow)]
  122. static void SelectLeft(ShortcutManagement.ShortcutArguments args)
  123. {
  124. if (KeyboardNavigation.ClipAreaActive())
  125. {
  126. SendEventToInvokeShortcut(selectLeftItem, args.context);
  127. }
  128. else if (KeyboardNavigation.TrackHeadActive())
  129. {
  130. SendEventToInvokeShortcut(collapseGroup, args.context);
  131. }
  132. }
  133. [UsedImplicitly]
  134. [ShortcutManagement.Shortcut(moveRight, typeof(TimelineWindow), KeyCode.RightArrow)]
  135. static void SelectRight(ShortcutManagement.ShortcutArguments args)
  136. {
  137. if (KeyboardNavigation.ClipAreaActive())
  138. {
  139. SendEventToInvokeShortcut(selectRightItem, args.context);
  140. }
  141. else if (KeyboardNavigation.TrackHeadActive())
  142. {
  143. SendEventToInvokeShortcut(unCollapseGroup, args.context);
  144. }
  145. }
  146. [UsedImplicitly]
  147. [ShortcutManagement.Shortcut(moveUp, typeof(TimelineWindow), KeyCode.UpArrow)]
  148. static void SelectUp(ShortcutManagement.ShortcutArguments args)
  149. {
  150. if (KeyboardNavigation.ClipAreaActive())
  151. {
  152. SendEventToInvokeShortcut(selectUpItem, args.context);
  153. }
  154. else if (KeyboardNavigation.TrackHeadActive())
  155. {
  156. SendEventToInvokeShortcut(selectUpTrack, args.context);
  157. }
  158. else
  159. {
  160. KeyboardNavigation.FocusFirstVisibleItem(GetState(args));
  161. }
  162. }
  163. [UsedImplicitly]
  164. [ShortcutManagement.Shortcut(moveDown, typeof(TimelineWindow), KeyCode.DownArrow)]
  165. static void SelectDown(ShortcutManagement.ShortcutArguments args)
  166. {
  167. if (KeyboardNavigation.ClipAreaActive())
  168. {
  169. SendEventToInvokeShortcut(selectDownItem, args.context);
  170. }
  171. else if (KeyboardNavigation.TrackHeadActive())
  172. {
  173. SendEventToInvokeShortcut(selectDownTrack, args.context);
  174. }
  175. else
  176. {
  177. KeyboardNavigation.FocusFirstVisibleItem(GetState(args));
  178. }
  179. }
  180. [UsedImplicitly, ShortcutManagement.Shortcut(multiSelectLeft, typeof(TimelineWindow), KeyCode.LeftArrow, ShortcutModifiers.Shift)]
  181. static void MultiSelectLeft(ShortcutManagement.ShortcutArguments args)
  182. {
  183. SendEventToInvokeShortcut(multiSelectLeft, args.context);
  184. }
  185. [UsedImplicitly, ShortcutManagement.Shortcut(multiSelectRight, typeof(TimelineWindow), KeyCode.RightArrow, ShortcutModifiers.Shift)]
  186. static void MultiSelectRight(ShortcutManagement.ShortcutArguments args)
  187. {
  188. SendEventToInvokeShortcut(multiSelectRight, args.context);
  189. }
  190. [UsedImplicitly, ShortcutManagement.Shortcut(multiSelectUp , typeof(TimelineWindow), KeyCode.UpArrow, ShortcutModifiers.Shift)]
  191. static void MultiSelectUp(ShortcutManagement.ShortcutArguments args)
  192. {
  193. SendEventToInvokeShortcut(multiSelectUp, args.context);
  194. }
  195. [UsedImplicitly, ShortcutManagement.Shortcut(multiSelectDown, typeof(TimelineWindow), KeyCode.DownArrow, ShortcutModifiers.Shift)]
  196. static void MultiSelectDown(ShortcutManagement.ShortcutArguments args)
  197. {
  198. SendEventToInvokeShortcut(multiSelectDown, args.context);
  199. }
  200. [UsedImplicitly, ShortcutManagement.Shortcut(toggleClipTrackArea, typeof(TimelineWindow), KeyCode.Tab)]
  201. static void ToggleClipTrackArea(ShortcutManagement.ShortcutArguments args)
  202. {
  203. SendEventToInvokeShortcut(toggleClipTrackArea, args.context);
  204. }
  205. [UsedImplicitly, ShortcutManagement.Shortcut(matchContent, typeof(TimelineWindow), KeyCode.C)]
  206. static void Shortcut(ShortcutManagement.ShortcutArguments args)
  207. {
  208. SendEventToInvokeShortcut(matchContent, args.context);
  209. }
  210. [UsedImplicitly, ShortcutManagement.Shortcut(toggleLock, typeof(TimelineWindow), KeyCode.L)]
  211. static void Lock(ShortcutManagement.ShortcutArguments args)
  212. {
  213. SendEventToInvokeShortcut(toggleLock, args.context);
  214. }
  215. [UsedImplicitly, ShortcutManagement.Shortcut(toggleMute, typeof(TimelineWindow), KeyCode.M)]
  216. static void Mute(ShortcutManagement.ShortcutArguments args)
  217. {
  218. SendEventToInvokeShortcut(toggleMute, args.context);
  219. }
  220. }
  221. static WindowState GetState(ShortcutManagement.ShortcutArguments args)
  222. {
  223. return ((TimelineWindow)args.context).state;
  224. }
  225. static void SendEventToInvokeShortcut(string timelineShortcutId, object context)
  226. {
  227. var e = new Event
  228. {
  229. type = EventType.ExecuteCommand,
  230. commandName = timelineShortcutId
  231. };
  232. (context as EditorWindow).SendEvent(e);
  233. }
  234. }
  235. }