MainFrameMenu.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import strings = require("../../EditorStrings");
  23. import EditorEvents = require("../../../editor/EditorEvents");
  24. import EditorUI = require("../../EditorUI");
  25. import MenuItemSources = require("./MenuItemSources");
  26. class MainFrameMenu extends Atomic.ScriptObject {
  27. constructor() {
  28. super();
  29. MenuItemSources.createMenuItemSource("menu edit", editItems);
  30. MenuItemSources.createMenuItemSource("menu file", fileItems);
  31. MenuItemSources.createMenuItemSource("menu build", buildItems);
  32. MenuItemSources.createMenuItemSource("menu tools", toolsItems);
  33. MenuItemSources.createMenuItemSource("menu developer", developerItems);
  34. MenuItemSources.createMenuItemSource("menu help", helpItems);
  35. }
  36. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  37. if (target.id == "menu edit popup") {
  38. if (refid == "edit play") {
  39. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  40. return true;
  41. }
  42. if (refid == "edit play debug") {
  43. EditorUI.getShortcuts().invokePlayOrStopPlayer(true);
  44. return true;
  45. }
  46. if (refid == "edit format code") {
  47. EditorUI.getShortcuts().invokeFormatCode();
  48. return true;
  49. }
  50. if (refid == "edit undo") {
  51. EditorUI.getShortcuts().invokeUndo();
  52. return true;
  53. }
  54. if (refid == "edit redo") {
  55. EditorUI.getShortcuts().invokeRedo();
  56. return true;
  57. }
  58. if (refid == "edit cut") {
  59. EditorUI.getShortcuts().invokeCut();
  60. return true;
  61. }
  62. if (refid == "edit copy") {
  63. EditorUI.getShortcuts().invokeCopy();
  64. return true;
  65. }
  66. if (refid == "edit paste") {
  67. EditorUI.getShortcuts().invokePaste();
  68. return true;
  69. }
  70. if (refid == "edit select all") {
  71. EditorUI.getShortcuts().invokeSelectAll();
  72. return true;
  73. }
  74. if (refid == "edit snap settings") {
  75. EditorUI.getModelOps().showSnapSettings();
  76. return true;
  77. }
  78. if (refid == "edit frame selected") {
  79. EditorUI.getShortcuts().invokeFrameSelected();
  80. return true;
  81. }
  82. return false;
  83. } else if (target.id == "menu file popup") {
  84. if (refid == "quit") {
  85. this.sendEvent("ExitRequested");
  86. return true;
  87. }
  88. if (refid == "file new project") {
  89. if (ToolCore.toolSystem.project) {
  90. EditorUI.showModalError("Project Open",
  91. "Please close the current project before creating a new one");
  92. return true;
  93. }
  94. var mo = EditorUI.getModelOps();
  95. mo.showNewProject();
  96. return true;
  97. }
  98. if (refid == "file open project") {
  99. var utils = new Editor.FileUtils();
  100. var path = utils.openProjectFileDialog();
  101. if (path == "") {
  102. return true;
  103. }
  104. var openProject = () => this.sendEvent(EditorEvents.LoadProject, { path: path });
  105. if (ToolCore.toolSystem.project) {
  106. this.subscribeToEvent(EditorEvents.ProjectClosed, () => {
  107. this.unsubscribeFromEvent(EditorEvents.ProjectClosed);
  108. openProject();
  109. });
  110. this.sendEvent(EditorEvents.CloseProject);
  111. } else {
  112. openProject();
  113. }
  114. return true;
  115. }
  116. if (refid == "file close project") {
  117. this.sendEvent(EditorEvents.CloseProject);
  118. return true;
  119. }
  120. if (refid == "file save file") {
  121. EditorUI.getShortcuts().invokeFileSave();
  122. return true;
  123. }
  124. if (refid == "file close file") {
  125. EditorUI.getShortcuts().invokeFileClose();
  126. return true;
  127. }
  128. if (refid == "file save all") {
  129. this.sendEvent(EditorEvents.SaveAllResources);
  130. return true;
  131. }
  132. return false;
  133. } else if (target.id == "menu developer popup") {
  134. if (refid == "developer show console") {
  135. Atomic.ui.showConsole(true);
  136. return true;
  137. }
  138. if (refid == "developer show uidebugger") {
  139. if (Atomic.engine.debugBuild) {
  140. Atomic.UI.debugShowSettingsWindow(EditorUI.getView());
  141. }
  142. else {
  143. EditorUI.showModalError("Debug Build Required",
  144. "UIDebugger currently requires a Debug engine build");
  145. }
  146. return true;
  147. }
  148. if (refid == "developer assetdatabase scan") {
  149. ToolCore.assetDatabase.scan();
  150. }
  151. if (refid == "developer assetdatabase force") {
  152. ToolCore.assetDatabase.reimportAllAssets();
  153. }
  154. } else if (target.id == "menu tools popup") {
  155. if (refid == "tools toggle profiler") {
  156. Atomic.ui.toggleDebugHud();
  157. return true;
  158. }
  159. } else if (target.id == "menu build popup") {
  160. if (refid == "build build") {
  161. EditorUI.getModelOps().showBuild();
  162. return true;
  163. } else if (refid == "build settings") {
  164. EditorUI.getModelOps().showBuildSettings();
  165. return true;
  166. }
  167. } else if (target.id == "menu help popup") {
  168. if (refid == "about atomic editor") {
  169. EditorUI.getModelOps().showAbout();
  170. return true;
  171. }
  172. if (refid == "manage license") {
  173. EditorUI.getModelOps().showManageLicense();
  174. return true;
  175. }
  176. if (refid == "help forums") {
  177. Atomic.fileSystem.systemOpen("http://atomicgameengine.com/forum/");
  178. return true;
  179. } else if (refid == "help chat") {
  180. Atomic.fileSystem.systemOpen("https://gitter.im/AtomicGameEngine/AtomicGameEngine/");
  181. return true;
  182. } else if (refid == "help github") {
  183. Atomic.fileSystem.systemOpen("https://github.com/AtomicGameEngine/AtomicGameEngine/");
  184. return true;
  185. } else if (refid == "help api") {
  186. var url = "file://" + ToolCore.toolEnvironment.toolDataDir + "Docs/JSDocs/Atomic.html";
  187. Atomic.fileSystem.systemOpen(url);
  188. return true;
  189. }
  190. }
  191. }
  192. }
  193. export = MainFrameMenu;
  194. // initialization
  195. var StringID = strings.StringID;
  196. var editItems = {
  197. "Undo": ["edit undo", StringID.ShortcutUndo],
  198. "Redo": ["edit redo", StringID.ShortcutRedo],
  199. "-1": null,
  200. "Cut": ["edit cut", StringID.ShortcutCut],
  201. "Copy": ["edit copy", StringID.ShortcutCopy],
  202. "Paste": ["edit paste", StringID.ShortcutPaste],
  203. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  204. "-2": null,
  205. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  206. "-3": null,
  207. "Find": ["edit find", StringID.ShortcutFind],
  208. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  209. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  210. "-4": null,
  211. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  212. "-5": null,
  213. "Play": ["edit play", StringID.ShortcutPlay],
  214. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  215. "-6": null,
  216. "Snap Settings": ["edit snap settings"]
  217. };
  218. var toolsItems = {
  219. "Toggle Profiler": ["tools toggle profiler"]
  220. };
  221. var buildItems = {
  222. "Build": ["build build", StringID.ShortcutBuild],
  223. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  224. };
  225. var developerItems = {
  226. "Show Console": ["developer show console"],
  227. "Debug": {
  228. "UI Debugger": ["developer show uidebugger"],
  229. "Asset Database": {
  230. "Scan": ["developer assetdatabase scan"],
  231. "Force Reimport": ["developer assetdatabase force"]
  232. }
  233. }
  234. };
  235. var fileItems = {
  236. "New Project": ["file new project"],
  237. "Open Project": ["file open project"],
  238. "Save Project": ["file save project"],
  239. "-1": null,
  240. "Close Project": ["file close project"],
  241. "-2": null,
  242. "Save File": ["file save file", StringID.ShortcutSaveFile],
  243. "Save All Files": ["file save all"],
  244. "Close File": ["file close file", StringID.ShortcutCloseFile],
  245. "-3": null,
  246. "Quit": "quit"
  247. };
  248. var helpItems = {
  249. "Check for Updates": "check update",
  250. "API Documentation": ["help api"],
  251. "-1": null,
  252. "Atomic Chat": ["help chat"],
  253. "Atomic Forums": ["help forums"],
  254. "-2": null,
  255. "Atomic Game Engine on GitHub": ["help github"],
  256. "About Atomic Editor": "about atomic editor"
  257. };