MainFrameMenu.ts 8.8 KB

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