MainFrameMenu.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. } else if (target.id == "menu tools popup") {
  124. if (refid == "tools toggle profiler") {
  125. Atomic.ui.toggleDebugHud();
  126. return true;
  127. }
  128. } else if (target.id == "menu build popup") {
  129. if (refid == "build build") {
  130. EditorUI.getModelOps().showBuild();
  131. return true;
  132. } else if (refid == "build settings") {
  133. EditorUI.getModelOps().showBuildSettings();
  134. return true;
  135. }
  136. } else if (target.id == "menu help popup") {
  137. if (refid == "about atomic editor") {
  138. EditorUI.getModelOps().showAbout();
  139. return true;
  140. }
  141. if (refid == "manage license") {
  142. EditorUI.getModelOps().showManageLicense();
  143. return true;
  144. }
  145. if (refid == "help forums") {
  146. Atomic.fileSystem.systemOpen("http://atomicgameengine.com/forum/")
  147. return true;
  148. } else if (refid == "help chat") {
  149. Atomic.fileSystem.systemOpen("https://gitter.im/AtomicGameEngine/AtomicGameEngine/")
  150. return true;
  151. } else if (refid == "help github") {
  152. Atomic.fileSystem.systemOpen("https://github.com/AtomicGameEngine/AtomicGameEngine/")
  153. return true;
  154. } else if (refid == "help api") {
  155. var url = "file://" + ToolCore.toolEnvironment.toolDataDir + "Docs/JSDocs/Atomic.html";
  156. Atomic.fileSystem.systemOpen(url);
  157. return true;
  158. }
  159. }
  160. }
  161. }
  162. export = MainFrameMenu;
  163. // initialization
  164. var StringID = strings.StringID;
  165. var editItems = {
  166. "Undo": ["edit undo", StringID.ShortcutUndo],
  167. "Redo": ["edit redo", StringID.ShortcutRedo],
  168. "-1": null,
  169. "Cut": ["edit cut", StringID.ShortcutCut],
  170. "Copy": ["edit copy", StringID.ShortcutCopy],
  171. "Paste": ["edit paste", StringID.ShortcutPaste],
  172. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  173. "-2": null,
  174. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  175. "-3": null,
  176. "Find": ["edit find", StringID.ShortcutFind],
  177. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  178. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  179. "-4": null,
  180. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  181. "-5": null,
  182. "Play": ["edit play", StringID.ShortcutPlay],
  183. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  184. "-6": null,
  185. "Snap Settings": ["edit snap settings"]
  186. };
  187. var toolsItems = {
  188. "Toggle Profiler": ["tools toggle profiler"]
  189. }
  190. var buildItems = {
  191. "Build": ["build build", StringID.ShortcutBuild],
  192. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  193. }
  194. var developerItems = {
  195. "Show Console": ["developer show console"]
  196. }
  197. var fileItems = {
  198. "New Project": ["file new project"],
  199. "Open Project": ["file open project"],
  200. "Save Project": ["file save project"],
  201. "-1": null,
  202. "Close Project": ["file close project"],
  203. "-2": null,
  204. "Save File": ["file save file", StringID.ShortcutSaveFile],
  205. "Save All Files": ["file save all"],
  206. "Close File": ["file close file", StringID.ShortcutCloseFile],
  207. "-3": null,
  208. "Quit": "quit"
  209. }
  210. var helpItems = {
  211. "Check for Updates": "check update",
  212. "API Documentation": ["help api"],
  213. "-1": null,
  214. "Atomic Chat": ["help chat"],
  215. "Atomic Forums": ["help forums"],
  216. "-2": null,
  217. "Atomic Game Engine on GitHub": ["help github"],
  218. "About Atomic Editor": "about atomic editor",
  219. "-3": null,
  220. "Manage License": "manage license"
  221. }