Shortcuts.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import EditorEvents = require("../editor/EditorEvents");
  8. import EditorUI = require("./EditorUI");
  9. class Shortcuts extends Atomic.ScriptObject {
  10. constructor() {
  11. super();
  12. this.subscribeToEvent("UIShortcut", (ev: Atomic.UIShortcutEvent) => this.handleUIShortcut(ev));
  13. }
  14. invokePlay() {
  15. this.sendEvent(EditorEvents.SaveAllResources);
  16. Atomic.editorMode.playProject();
  17. }
  18. invokePlayDebug() {
  19. this.sendEvent(EditorEvents.SaveAllResources);
  20. Atomic.editorMode.playProjectDebug();
  21. }
  22. invokeFormatCode() {
  23. var editor = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  24. if (editor && editor.typeName == "JSResourceEditor") {
  25. (<Editor.JSResourceEditor>editor).formatCode();
  26. }
  27. }
  28. invokeFileClose() {
  29. // pretty gross
  30. var editor = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  31. if (!editor) return;
  32. editor.close(true);
  33. }
  34. invokeFileSave() {
  35. this.sendEvent(EditorEvents.SaveResource);
  36. }
  37. invokeUndo() {
  38. this.invokeResourceFrameShortcut("undo");
  39. }
  40. invokeRedo() {
  41. this.invokeResourceFrameShortcut("redo");
  42. }
  43. invokeCut() {
  44. this.invokeResourceFrameShortcut("cut");
  45. }
  46. invokeCopy() {
  47. this.invokeResourceFrameShortcut("copy");
  48. }
  49. invokePaste() {
  50. this.invokeResourceFrameShortcut("paste");
  51. }
  52. invokeSelectAll() {
  53. this.invokeResourceFrameShortcut("selectall");
  54. }
  55. invokeResourceFrameShortcut(shortcut:string) {
  56. if (!ToolCore.toolSystem.project) return;
  57. var resourceFrame = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  58. if(resourceFrame) {
  59. resourceFrame.invokeShortcut(shortcut);
  60. }
  61. }
  62. // global shortcut handler
  63. handleUIShortcut(ev: Atomic.UIShortcutEvent) {
  64. var cmdKey;
  65. if(Atomic.platform == "MacOSX") {
  66. cmdKey = (Atomic.input.getKeyDown(Atomic.KEY_LGUI) || Atomic.input.getKeyDown(Atomic.KEY_RGUI));
  67. } else {
  68. cmdKey = (Atomic.input.getKeyDown(Atomic.KEY_LCTRL) || Atomic.input.getKeyDown(Atomic.KEY_RCTRL));
  69. }
  70. if (cmdKey) {
  71. if (ev.key == Atomic.KEY_S) {
  72. this.invokeFileSave();
  73. }
  74. else if (ev.key == Atomic.KEY_W) {
  75. this.invokeFileClose();
  76. }
  77. else if (ev.key == Atomic.KEY_I) {
  78. this.invokeFormatCode();
  79. }
  80. else if (ev.key == Atomic.KEY_P) {
  81. this.invokePlay();
  82. //if shift is pressed
  83. } else if (ev.qualifiers & Atomic.QUAL_SHIFT) {
  84. if (ev.key == Atomic.KEY_B) {
  85. EditorUI.getModelOps().showBuildSettings();
  86. }
  87. } else if (ev.key == Atomic.KEY_B) {
  88. EditorUI.getModelOps().showBuild();
  89. }
  90. }
  91. }
  92. }
  93. export = Shortcuts;