Shortcuts.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import EditorEvents = require("../editor/EditorEvents");
  2. import EditorUI = require("./EditorUI");
  3. class Shortcuts extends Atomic.ScriptObject {
  4. constructor() {
  5. super();
  6. this.subscribeToEvent("UIShortcut", (ev: Atomic.UIShortcutEvent) => this.handleUIShortcut(ev));
  7. }
  8. invokePlay() {
  9. this.sendEvent(EditorEvents.SaveAllResources);
  10. Atomic.editorMode.playProject();
  11. }
  12. invokeFormatCode() {
  13. var editor = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  14. if (editor && editor.typeName == "JSResourceEditor") {
  15. (<Editor.JSResourceEditor>editor).formatCode();
  16. }
  17. }
  18. invokeFileClose() {
  19. // pretty gross
  20. var editor = EditorUI.getMainFrame().resourceframe.currentResourceEditor;
  21. if (!editor) return;
  22. editor.close(true);
  23. }
  24. invokeFileSave() {
  25. this.sendEvent(EditorEvents.SaveResource);
  26. }
  27. // global shortcut handler
  28. handleUIShortcut(ev: Atomic.UIShortcutEvent) {
  29. // global shortcuts without qualifiers
  30. if (!ev.qualifiers) {
  31. if (ev.key == Atomic.KEY_S) {
  32. this.invokeFileSave();
  33. }
  34. else if (ev.key == Atomic.KEY_W) {
  35. this.invokeFileClose();
  36. }
  37. else if (ev.key == Atomic.KEY_I) {
  38. this.invokeFormatCode();
  39. }
  40. else if (ev.key == Atomic.KEY_P) {
  41. this.invokePlay();
  42. }
  43. }
  44. }
  45. }
  46. export = Shortcuts;