Shortcuts.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. invokeFormatCode() {
  19. var editor = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  20. if (editor && editor.typeName == "JSResourceEditor") {
  21. (<Editor.JSResourceEditor>editor).formatCode();
  22. }
  23. }
  24. invokeFileClose() {
  25. // pretty gross
  26. var editor = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  27. if (!editor) return;
  28. editor.close(true);
  29. }
  30. invokeFileSave() {
  31. this.sendEvent(EditorEvents.SaveResource);
  32. }
  33. invokeUndo() {
  34. this.invokeResourceFrameShortcut("undo");
  35. }
  36. invokeRedo() {
  37. this.invokeResourceFrameShortcut("redo");
  38. }
  39. invokeCut() {
  40. this.invokeResourceFrameShortcut("cut");
  41. }
  42. invokeCopy() {
  43. this.invokeResourceFrameShortcut("copy");
  44. }
  45. invokePaste() {
  46. this.invokeResourceFrameShortcut("paste");
  47. }
  48. invokeSelectAll() {
  49. this.invokeResourceFrameShortcut("selectall");
  50. }
  51. invokeResourceFrameShortcut(shortcut:string) {
  52. if (!ToolCore.toolSystem.project) return;
  53. var resourceFrame = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  54. if(resourceFrame) {
  55. resourceFrame.invokeShortcut(shortcut);
  56. }
  57. }
  58. // global shortcut handler
  59. handleUIShortcut(ev: Atomic.UIShortcutEvent) {
  60. var cmdKey;
  61. if(Atomic.platform == "MacOSX") {
  62. cmdKey = (Atomic.input.getKeyDown(Atomic.KEY_LGUI) || Atomic.input.getKeyDown(Atomic.KEY_RGUI));
  63. } else {
  64. cmdKey = (Atomic.input.getKeyDown(Atomic.KEY_LCTRL) || Atomic.input.getKeyDown(Atomic.KEY_RCTRL));
  65. }
  66. if (cmdKey) {
  67. if (ev.key == Atomic.KEY_S) {
  68. this.invokeFileSave();
  69. }
  70. else if (ev.key == Atomic.KEY_W) {
  71. this.invokeFileClose();
  72. }
  73. else if (ev.key == Atomic.KEY_I) {
  74. this.invokeFormatCode();
  75. }
  76. else if (ev.key == Atomic.KEY_P) {
  77. this.invokePlay();
  78. //if shift is pressed
  79. } else if (ev.qualifiers & Atomic.QUAL_SHIFT) {
  80. if (ev.key == Atomic.KEY_B) {
  81. EditorUI.getModelOps().showBuildSettings();
  82. }
  83. } else if (ev.key == Atomic.KEY_B) {
  84. EditorUI.getModelOps().showBuild();
  85. }
  86. }
  87. }
  88. }
  89. export = Shortcuts;