MainFrameMenu.ts 7.8 KB

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