Shortcuts.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // global shortcut handler
  34. handleUIShortcut(ev: Atomic.UIShortcutEvent) {
  35. // global shortcuts without qualifiers
  36. if (!ev.qualifiers) {
  37. if (ev.key == Atomic.KEY_S) {
  38. this.invokeFileSave();
  39. }
  40. else if (ev.key == Atomic.KEY_W) {
  41. this.invokeFileClose();
  42. }
  43. else if (ev.key == Atomic.KEY_I) {
  44. this.invokeFormatCode();
  45. }
  46. else if (ev.key == Atomic.KEY_P) {
  47. this.invokePlay();
  48. }
  49. }
  50. }
  51. }
  52. export = Shortcuts;