MainFrameMenu.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import strings = require("ui/EditorStrings");
  2. import EditorEvents = require("editor/EditorEvents");
  3. import EditorUI = require("ui/EditorUI");
  4. import MenuItemSources = require("./MenuItemSources");
  5. class MainFrameMenu extends Atomic.ScriptObject {
  6. constructor() {
  7. super();
  8. MenuItemSources.createMenuItemSource("menu atomic editor", editorItems);
  9. MenuItemSources.createMenuItemSource("menu edit", editItems);
  10. MenuItemSources.createMenuItemSource("menu file", fileItems);
  11. MenuItemSources.createMenuItemSource("menu tools", toolsItems);
  12. MenuItemSources.createMenuItemSource("menu developer", developerItems);
  13. }
  14. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  15. if (target.id == "menu atomic editor popup") {
  16. if (refid == "about atomic editor") {
  17. EditorUI.getModelOps().showAbout();
  18. return true;
  19. }
  20. if (refid == "manage license") {
  21. EditorUI.getModelOps().showManageLicense();
  22. return true;
  23. }
  24. if (refid == "quit") {
  25. this.sendEvent(EditorEvents.Quit);
  26. return true;
  27. }
  28. } else if (target.id == "menu edit popup") {
  29. if (refid == "edit play") {
  30. EditorUI.getShortcuts().invokePlay();
  31. return true;
  32. }
  33. if (refid == "edit format code") {
  34. EditorUI.getShortcuts().invokeFormatCode();
  35. return true;
  36. }
  37. return false;
  38. } else if (target.id == "menu file popup") {
  39. if (refid == "file new project") {
  40. if (ToolCore.toolSystem.project) {
  41. EditorUI.showModalError("Project Open",
  42. "Please close the current project before creating a new one");
  43. return true;
  44. }
  45. var mo = EditorUI.getModelOps();
  46. mo.showNewProject();
  47. return true;
  48. }
  49. if (refid == "file open project") {
  50. if (ToolCore.toolSystem.project) {
  51. EditorUI.showModalError("Project Open",
  52. "Please close the current project before opening new one");
  53. return true;
  54. }
  55. var utils = new Editor.FileUtils();
  56. var path = utils.openProjectFileDialog();
  57. if (path) {
  58. this.sendEvent(EditorEvents.LoadProject, { path: path });
  59. }
  60. return true;
  61. }
  62. if (refid == "file close project") {
  63. this.sendEvent(EditorEvents.CloseProject);
  64. return true;
  65. }
  66. if (refid == "file save file") {
  67. EditorUI.getShortcuts().invokeFileSave();
  68. return true;
  69. }
  70. if (refid == "file close file") {
  71. EditorUI.getShortcuts().invokeFileClose();
  72. return true;
  73. }
  74. if (refid == "file save all") {
  75. this.sendEvent(EditorEvents.SaveAllResources);
  76. return true;
  77. }
  78. return false;
  79. } else if (target.id == "menu developer popup") {
  80. if (refid == "developer show console") {
  81. Atomic.ui.showConsole(true);
  82. return true;
  83. }
  84. } else if (target.id == "menu tools popup") {
  85. if (refid == "tools toggle profiler") {
  86. Atomic.ui.toggleDebugHud();
  87. return true;
  88. }
  89. }
  90. }
  91. }
  92. export = MainFrameMenu;
  93. // initialization
  94. var StringID = strings.StringID;
  95. var editorItems = {
  96. "About Atomic Editor": "about atomic editor",
  97. "-1": null,
  98. "Manage License": "manage license",
  99. "-2": null,
  100. "Check for Updates": "check update",
  101. "-3": null,
  102. "Quit": "quit"
  103. };
  104. var editItems = {
  105. "Undo": ["edit undo", StringID.ShortcutUndo],
  106. "Redo": ["edit redo", StringID.ShortcutRedo],
  107. "-1": null,
  108. "Cut": ["edit cut", StringID.ShortcutCut],
  109. "Copy": ["edit copy", StringID.ShortcutCopy],
  110. "Paste": ["edit paste", StringID.ShortcutPaste],
  111. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  112. "-2": null,
  113. "Find": ["edit find", StringID.ShortcutFind],
  114. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  115. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  116. "-3": null,
  117. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  118. "-4": null,
  119. "Play": ["edit play", StringID.ShortcutPlay]
  120. };
  121. var toolsItems = {
  122. "Toggle Profiler": ["tools toggle profiler"]
  123. }
  124. var developerItems = {
  125. "Show Console": ["developer show console"]
  126. }
  127. var fileItems = {
  128. "New Project": ["file new project"],
  129. "Open Project": ["file open project"],
  130. "Save Project": ["file save project"],
  131. "-1": null,
  132. "Close Project": ["file close project"],
  133. "-2": null,
  134. "Save File": ["file save file"],
  135. "Save All Files": ["file save all"],
  136. "Close File": ["file close file"]
  137. }