MainFrameMenu.ts 7.0 KB

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