MainFrameMenu.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. import Preferences = require("editor/Preferences");
  27. import ServiceLocator from "../../../hostExtensions/ServiceLocator";
  28. class MainFrameMenu extends Atomic.ScriptObject {
  29. private pluginMenuItemSource: Atomic.UIMenuItemSource;
  30. constructor() {
  31. super();
  32. MenuItemSources.createMenuItemSource("menu edit", editItems);
  33. MenuItemSources.createMenuItemSource("menu file", fileItems);
  34. MenuItemSources.createMenuItemSource("menu build", buildItems);
  35. MenuItemSources.createMenuItemSource("menu tools", toolsItems);
  36. MenuItemSources.createMenuItemSource("menu developer", developerItems);
  37. MenuItemSources.createMenuItemSource("menu help", helpItems);
  38. }
  39. createPluginMenuItemSource(id: string, items: any): Atomic.UIMenuItemSource {
  40. if (!this.pluginMenuItemSource) {
  41. var developerMenuItemSource = MenuItemSources.getMenuItemSource("menu developer");
  42. this.pluginMenuItemSource = MenuItemSources.createSubMenuItemSource(developerMenuItemSource, "Plugins", {});
  43. }
  44. return MenuItemSources.createSubMenuItemSource(this.pluginMenuItemSource , id, items);
  45. }
  46. removePluginMenuItemSource(id: string) {
  47. if (this.pluginMenuItemSource) {
  48. this.pluginMenuItemSource.removeItemWithStr(id);
  49. if (0 == this.pluginMenuItemSource.itemCount) {
  50. var developerMenuItemSource = MenuItemSources.getMenuItemSource("menu developer");
  51. developerMenuItemSource.removeItemWithStr("Plugins");
  52. this.pluginMenuItemSource = null;
  53. }
  54. }
  55. }
  56. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  57. if (target.id == "menu edit popup") {
  58. if (refid == "edit play") {
  59. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  60. return true;
  61. }
  62. if (refid == "edit pause") {
  63. EditorUI.getShortcuts().invokePauseOrResumePlayer();
  64. return true;
  65. }
  66. if (refid == "edit step") {
  67. EditorUI.getShortcuts().invokeStepPausedPlayer();
  68. return true;
  69. }
  70. if (refid == "edit play debug") {
  71. EditorUI.getShortcuts().invokePlayOrStopPlayer(true);
  72. return true;
  73. }
  74. if (refid == "edit format code") {
  75. EditorUI.getShortcuts().invokeFormatCode();
  76. return true;
  77. }
  78. if (refid == "edit undo") {
  79. EditorUI.getShortcuts().invokeUndo();
  80. return true;
  81. }
  82. if (refid == "edit redo") {
  83. EditorUI.getShortcuts().invokeRedo();
  84. return true;
  85. }
  86. if (refid == "edit cut") {
  87. EditorUI.getShortcuts().invokeCut();
  88. return true;
  89. }
  90. if (refid == "edit copy") {
  91. EditorUI.getShortcuts().invokeCopy();
  92. return true;
  93. }
  94. if (refid == "edit paste") {
  95. EditorUI.getShortcuts().invokePaste();
  96. return true;
  97. }
  98. if (refid == "edit select all") {
  99. EditorUI.getShortcuts().invokeSelectAll();
  100. return true;
  101. }
  102. if (refid == "edit snap settings") {
  103. EditorUI.getModelOps().showSnapSettings();
  104. return true;
  105. }
  106. if (refid == "edit frame selected") {
  107. EditorUI.getShortcuts().invokeFrameSelected();
  108. return true;
  109. }
  110. return false;
  111. } else if (target.id == "menu file popup") {
  112. if (refid == "quit") {
  113. this.sendEvent(Atomic.ExitRequestedEventType);
  114. return true;
  115. }
  116. if (refid == "file new project") {
  117. if (ToolCore.toolSystem.project) {
  118. EditorUI.showModalError("Project Open",
  119. "Please close the current project before creating a new one");
  120. return true;
  121. }
  122. var mo = EditorUI.getModelOps();
  123. mo.showNewProject();
  124. return true;
  125. }
  126. if (refid == "file open project") {
  127. var utils = new Editor.FileUtils();
  128. var path = utils.openProjectFileDialog();
  129. if (path == "") {
  130. return true;
  131. }
  132. var requestProjectLoad = () => this.sendEvent(EditorEvents.RequestProjectLoad, { path: path });
  133. if (ToolCore.toolSystem.project) {
  134. this.subscribeToEvent(Editor.EditorProjectClosedEvent(() => {
  135. this.unsubscribeFromEvent(Editor.EditorProjectClosedEventType);
  136. requestProjectLoad();
  137. }));
  138. this.sendEvent(Editor.EditorCloseProjectEventType);
  139. } else {
  140. requestProjectLoad();
  141. }
  142. return true;
  143. }
  144. if (refid == "file close project") {
  145. this.sendEvent(Editor.EditorCloseProjectEventType);
  146. return true;
  147. }
  148. if (refid == "file save file") {
  149. EditorUI.getShortcuts().invokeFileSave();
  150. return true;
  151. }
  152. if (refid == "file close file") {
  153. EditorUI.getShortcuts().invokeFileClose();
  154. return true;
  155. }
  156. if (refid == "file save all") {
  157. this.sendEvent(Editor.EditorSaveAllResourcesEventType);
  158. return true;
  159. }
  160. return false;
  161. } else if (target.id == "menu developer popup") {
  162. if (refid == "developer show console") {
  163. Atomic.ui.showConsole(true);
  164. return true;
  165. }
  166. if (refid == "developer show uidebugger") {
  167. if (Atomic.engine.debugBuild) {
  168. Atomic.UI.debugShowSettingsWindow(EditorUI.getView());
  169. }
  170. else {
  171. EditorUI.showModalError("Debug Build Required",
  172. "UIDebugger currently requires a Debug engine build");
  173. }
  174. return true;
  175. }
  176. if (refid == "developer assetdatabase scan") {
  177. ToolCore.assetDatabase.scan();
  178. return true;
  179. }
  180. if (refid == "developer assetdatabase force") {
  181. ToolCore.assetDatabase.reimportAllAssets();
  182. return true;
  183. }
  184. //Sets all value in prefs.json to default and shuts down the editor.
  185. if (refid == "developer clear preferences") {
  186. var myPrefs = Preferences.getInstance();
  187. myPrefs.useDefaultConfig();
  188. myPrefs.saveEditorWindowData(myPrefs.editorWindow);
  189. myPrefs.savePlayerWindowData(myPrefs.playerWindow);
  190. Atomic.getEngine().exit();
  191. return true;
  192. }
  193. // If we got here, then we may have been injected by a plugin. Notify the plugins
  194. return ServiceLocator.uiServices.menuItemClicked(refid);
  195. } else if (target.id == "menu tools popup") {
  196. if (refid == "tools toggle profiler") {
  197. Atomic.ui.toggleDebugHud();
  198. return true;
  199. } if (refid == "tools perf profiler") {
  200. Atomic.ui.debugHudProfileMode = Atomic.DebugHudProfileMode.DEBUG_HUD_PROFILE_PERFORMANCE;
  201. Atomic.ui.showDebugHud(true);
  202. return true;
  203. } else if (refid == "tools metrics profiler") {
  204. Atomic.ui.debugHudProfileMode = Atomic.DebugHudProfileMode.DEBUG_HUD_PROFILE_METRICS;
  205. Atomic.ui.showDebugHud(true);
  206. return true;
  207. } else if (refid.indexOf("tools log") != -1) {
  208. let logName = refid.indexOf("editor") != -1 ? "AtomicEditor" : "AtomicPlayer";
  209. let logFolder = Atomic.fileSystem.getAppPreferencesDir(logName, "Logs");
  210. Atomic.fileSystem.systemOpen(logFolder);
  211. }
  212. } else if (target.id == "menu build popup") {
  213. if (refid == "build build") {
  214. EditorUI.getModelOps().showBuild();
  215. return true;
  216. } else if (refid == "build settings") {
  217. EditorUI.getModelOps().showBuildSettings();
  218. return true;
  219. }
  220. } else if (target.id == "menu help popup") {
  221. if (refid == "about atomic editor") {
  222. EditorUI.getModelOps().showAbout();
  223. return true;
  224. }
  225. if (refid == "help what new") {
  226. EditorUI.getModelOps().showNewBuildWindow(false);
  227. return true;
  228. }
  229. let urlLookup = {
  230. "help doc wiki" : "https://github.com/AtomicGameEngine/AtomicGameEngine/wiki/",
  231. "help chat" : "https://gitter.im/AtomicGameEngine/AtomicGameEngine/",
  232. "help api js" : "http://docs.atomicgameengine.com/api/modules/atomic.html",
  233. "help api csharp" : "http://docs.atomicgameengine.com/csharp/AtomicEngine/",
  234. "help api cplusplus" : "http://docs.atomicgameengine.com/cpp",
  235. "help support" : "https://discourse.atomicgameengine.com/",
  236. "help github" : "https://github.com/AtomicGameEngine/AtomicGameEngine/"
  237. };
  238. if (urlLookup[refid]) {
  239. Atomic.fileSystem.systemOpen(urlLookup[refid]);
  240. return true;
  241. }
  242. return false;
  243. } else {
  244. // console.log("Menu: " + target.id + " clicked");
  245. }
  246. }
  247. }
  248. export = MainFrameMenu;
  249. // initialization
  250. var StringID = strings.StringID;
  251. var editItems = {
  252. "Undo": ["edit undo", StringID.ShortcutUndo],
  253. "Redo": ["edit redo", StringID.ShortcutRedo],
  254. "-1": null,
  255. "Cut": ["edit cut", StringID.ShortcutCut],
  256. "Copy": ["edit copy", StringID.ShortcutCopy],
  257. "Paste": ["edit paste", StringID.ShortcutPaste],
  258. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  259. "-2": null,
  260. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  261. "-3": null,
  262. "Find": ["edit find", StringID.ShortcutFind],
  263. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  264. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  265. "-4": null,
  266. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  267. "-5": null,
  268. "Play": ["edit play", StringID.ShortcutPlay],
  269. "Pause/Resume": ["edit pause", StringID.ShortcutPause],
  270. "Step": ["edit step", StringID.ShortcutStep],
  271. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  272. "-6": null,
  273. "Snap Settings": ["edit snap settings"]
  274. };
  275. var toolsItems = {
  276. "Profiler": {
  277. "Toggle HUD": ["tools toggle profiler"],
  278. "Profile Performance": ["tools perf profiler"],
  279. "Profile Metrics": ["tools metrics profiler"]
  280. },
  281. "Logs": {
  282. "Player Log": ["tools log player"],
  283. "Editor Log": ["tools log editor"]
  284. }
  285. };
  286. var buildItems = {
  287. "Build": ["build build", StringID.ShortcutBuild],
  288. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  289. };
  290. var developerItems = {
  291. "Show Console": ["developer show console"],
  292. "Clear Preferences": ["developer clear preferences"], //Adds clear preference to developer menu items list
  293. "Debug": {
  294. "UI Debugger": ["developer show uidebugger"],
  295. "Asset Database": {
  296. "Scan": ["developer assetdatabase scan"],
  297. "Force Reimport": ["developer assetdatabase force"]
  298. }
  299. }
  300. };
  301. var fileItems = {
  302. "New Project": ["file new project"],
  303. "Open Project": ["file open project"],
  304. "Save Project": ["file save project"],
  305. "-1": null,
  306. "Close Project": ["file close project"],
  307. "-2": null,
  308. "Save File": ["file save file", StringID.ShortcutSaveFile],
  309. "Save All Files": ["file save all"],
  310. "Close File": ["file close file", StringID.ShortcutCloseFile],
  311. "-3": null,
  312. "Quit": "quit"
  313. };
  314. var helpItems = {
  315. "Atomic Community Support": ["help support"],
  316. "Atomic Chat": ["help chat"],
  317. "-1": null,
  318. "Documentation Wiki": "help doc wiki",
  319. "API References": {
  320. "JavaScript & TypeScript": ["help api js"],
  321. "C#": ["help api csharp"],
  322. "C++": ["help api cplusplus"]
  323. },
  324. "-2": null,
  325. "Atomic Game Engine on GitHub": ["help github"],
  326. "-3": null,
  327. "What's New": "help what new",
  328. "About Atomic Editor": "about atomic editor"
  329. };