MainFrameMenu.ts 8.1 KB

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