MainFrameMenu.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 edit", editItems);
  15. MenuItemSources.createMenuItemSource("menu file", fileItems);
  16. MenuItemSources.createMenuItemSource("menu build", buildItems);
  17. MenuItemSources.createMenuItemSource("menu tools", toolsItems);
  18. MenuItemSources.createMenuItemSource("menu developer", developerItems);
  19. MenuItemSources.createMenuItemSource("menu help", helpItems);
  20. }
  21. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  22. if (target.id == "menu edit popup") {
  23. if (refid == "edit play") {
  24. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  25. return true;
  26. }
  27. if (refid == "edit play debug") {
  28. EditorUI.getShortcuts().invokePlayOrStopPlayer(true);
  29. return true;
  30. }
  31. if (refid == "edit format code") {
  32. EditorUI.getShortcuts().invokeFormatCode();
  33. return true;
  34. }
  35. if (refid == "edit undo") {
  36. EditorUI.getShortcuts().invokeUndo();
  37. return true;
  38. }
  39. if (refid == "edit redo") {
  40. EditorUI.getShortcuts().invokeRedo();
  41. return true;
  42. }
  43. if (refid == "edit cut") {
  44. EditorUI.getShortcuts().invokeCut();
  45. return true;
  46. }
  47. if (refid == "edit copy") {
  48. EditorUI.getShortcuts().invokeCopy();
  49. return true;
  50. }
  51. if (refid == "edit paste") {
  52. EditorUI.getShortcuts().invokePaste();
  53. return true;
  54. }
  55. if (refid == "edit select all") {
  56. EditorUI.getShortcuts().invokeSelectAll();
  57. return true;
  58. }
  59. if (refid == "edit snap settings") {
  60. EditorUI.getModelOps().showSnapSettings();
  61. return true;
  62. }
  63. if (refid == "edit frame selected") {
  64. EditorUI.getShortcuts().invokeFrameSelected();
  65. return true;
  66. }
  67. return false;
  68. } else if (target.id == "menu file popup") {
  69. if (refid == "quit") {
  70. this.sendEvent("ExitRequested");
  71. return true;
  72. }
  73. if (refid == "file new project") {
  74. if (ToolCore.toolSystem.project) {
  75. EditorUI.showModalError("Project Open",
  76. "Please close the current project before creating a new one");
  77. return true;
  78. }
  79. var mo = EditorUI.getModelOps();
  80. mo.showNewProject();
  81. return true;
  82. }
  83. if (refid == "file open project") {
  84. var utils = new Editor.FileUtils();
  85. var path = utils.openProjectFileDialog();
  86. if (path == "") {
  87. return true;
  88. }
  89. var openProject = () => this.sendEvent(EditorEvents.LoadProject, { path: path });
  90. if (ToolCore.toolSystem.project) {
  91. this.subscribeToEvent(EditorEvents.ProjectClosed, () => {
  92. this.unsubscribeFromEvent(EditorEvents.ProjectClosed);
  93. openProject();
  94. });
  95. this.sendEvent(EditorEvents.CloseProject);
  96. } else {
  97. openProject();
  98. }
  99. return true;
  100. }
  101. if (refid == "file close project") {
  102. this.sendEvent(EditorEvents.CloseProject);
  103. return true;
  104. }
  105. if (refid == "file save file") {
  106. EditorUI.getShortcuts().invokeFileSave();
  107. return true;
  108. }
  109. if (refid == "file close file") {
  110. EditorUI.getShortcuts().invokeFileClose();
  111. return true;
  112. }
  113. if (refid == "file save all") {
  114. this.sendEvent(EditorEvents.SaveAllResources);
  115. return true;
  116. }
  117. return false;
  118. } else if (target.id == "menu developer popup") {
  119. if (refid == "developer show console") {
  120. Atomic.ui.showConsole(true);
  121. return true;
  122. }
  123. if (refid == "developer show uidebugger") {
  124. if (Atomic.engine.debugBuild) {
  125. Atomic.UI.debugShowSettingsWindow(EditorUI.getView());
  126. }
  127. else {
  128. EditorUI.showModalError("Debug Build Required",
  129. "UIDebugger currently requires a Debug engine build");
  130. }
  131. return true;
  132. }
  133. if (refid == "developer assetdatabase scan") {
  134. ToolCore.assetDatabase.scan();
  135. }
  136. if (refid == "developer assetdatabase force") {
  137. ToolCore.assetDatabase.reimportAllAssets();
  138. }
  139. } else if (target.id == "menu tools popup") {
  140. if (refid == "tools toggle profiler") {
  141. Atomic.ui.toggleDebugHud();
  142. return true;
  143. }
  144. } else if (target.id == "menu build popup") {
  145. if (refid == "build build") {
  146. EditorUI.getModelOps().showBuild();
  147. return true;
  148. } else if (refid == "build settings") {
  149. EditorUI.getModelOps().showBuildSettings();
  150. return true;
  151. }
  152. } else if (target.id == "menu help popup") {
  153. if (refid == "about atomic editor") {
  154. EditorUI.getModelOps().showAbout();
  155. return true;
  156. }
  157. if (refid == "manage license") {
  158. EditorUI.getModelOps().showManageLicense();
  159. return true;
  160. }
  161. if (refid == "help forums") {
  162. Atomic.fileSystem.systemOpen("http://atomicgameengine.com/forum/");
  163. return true;
  164. } else if (refid == "help chat") {
  165. Atomic.fileSystem.systemOpen("https://gitter.im/AtomicGameEngine/AtomicGameEngine/");
  166. return true;
  167. } else if (refid == "help github") {
  168. Atomic.fileSystem.systemOpen("https://github.com/AtomicGameEngine/AtomicGameEngine/");
  169. return true;
  170. } else if (refid == "help api") {
  171. var url = "file://" + ToolCore.toolEnvironment.toolDataDir + "Docs/JSDocs/Atomic.html";
  172. Atomic.fileSystem.systemOpen(url);
  173. return true;
  174. }
  175. }
  176. }
  177. }
  178. export = MainFrameMenu;
  179. // initialization
  180. var StringID = strings.StringID;
  181. var editItems = {
  182. "Undo": ["edit undo", StringID.ShortcutUndo],
  183. "Redo": ["edit redo", StringID.ShortcutRedo],
  184. "-1": null,
  185. "Cut": ["edit cut", StringID.ShortcutCut],
  186. "Copy": ["edit copy", StringID.ShortcutCopy],
  187. "Paste": ["edit paste", StringID.ShortcutPaste],
  188. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  189. "-2": null,
  190. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  191. "-3": null,
  192. "Find": ["edit find", StringID.ShortcutFind],
  193. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  194. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  195. "-4": null,
  196. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  197. "-5": null,
  198. "Play": ["edit play", StringID.ShortcutPlay],
  199. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  200. "-6": null,
  201. "Snap Settings": ["edit snap settings"]
  202. };
  203. var toolsItems = {
  204. "Toggle Profiler": ["tools toggle profiler"]
  205. };
  206. var buildItems = {
  207. "Build": ["build build", StringID.ShortcutBuild],
  208. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  209. };
  210. var developerItems = {
  211. "Show Console": ["developer show console"],
  212. "Debug": {
  213. "UI Debugger": ["developer show uidebugger"],
  214. "Asset Database": {
  215. "Scan": ["developer assetdatabase scan"],
  216. "Force Reimport": ["developer assetdatabase force"]
  217. }
  218. }
  219. };
  220. var fileItems = {
  221. "New Project": ["file new project"],
  222. "Open Project": ["file open project"],
  223. "Save Project": ["file save project"],
  224. "-1": null,
  225. "Close Project": ["file close project"],
  226. "-2": null,
  227. "Save File": ["file save file", StringID.ShortcutSaveFile],
  228. "Save All Files": ["file save all"],
  229. "Close File": ["file close file", StringID.ShortcutCloseFile],
  230. "-3": null,
  231. "Quit": "quit"
  232. };
  233. var helpItems = {
  234. "Check for Updates": "check update",
  235. "API Documentation": ["help api"],
  236. "-1": null,
  237. "Atomic Chat": ["help chat"],
  238. "Atomic Forums": ["help forums"],
  239. "-2": null,
  240. "Atomic Game Engine on GitHub": ["help github"],
  241. "About Atomic Editor": "about atomic editor",
  242. "-3": null,
  243. "Manage License": "manage license"
  244. };