MainFrameMenu.ts 10 KB

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