MainFrameMenu.ts 5.7 KB

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