MainFrameMenu.ts 14 KB

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