MainFrameMenu.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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.RequestProjectLoadEventData({ 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 == "toggle theme") {
  162. Preferences.getInstance().toggleTheme();
  163. return true;
  164. }
  165. if (refid == "toggle codeeditor") {
  166. var ctheme = EditorUI.getEditor().getApplicationPreference( "codeEditor","theme", "");
  167. if ( ctheme == "vs-dark" )
  168. EditorUI.getEditor().setApplicationPreference( "codeEditor","theme","vs");
  169. else
  170. EditorUI.getEditor().setApplicationPreference( "codeEditor","theme","vs-dark");
  171. return true;
  172. }
  173. if (refid == "developer show console") {
  174. Atomic.ui.showConsole(true);
  175. return true;
  176. }
  177. if (refid == "developer show uidebugger") {
  178. if (Atomic.engine.debugBuild) {
  179. Atomic.UI.debugShowSettingsWindow(EditorUI.getView());
  180. }
  181. else {
  182. EditorUI.showModalError("Debug Build Required",
  183. "UIDebugger currently requires a Debug engine build");
  184. }
  185. return true;
  186. }
  187. if (refid == "developer assetdatabase scan") {
  188. ToolCore.assetDatabase.scan();
  189. return true;
  190. }
  191. if (refid == "developer assetdatabase force") {
  192. ToolCore.assetDatabase.reimportAllAssets();
  193. return true;
  194. }
  195. //Sets all value in prefs.json to default and shuts down the editor.
  196. if (refid == "developer clear preferences") {
  197. var myPrefs = Preferences.getInstance();
  198. myPrefs.useDefaultConfig();
  199. myPrefs.saveEditorWindowData(myPrefs.editorWindow);
  200. myPrefs.savePlayerWindowData(myPrefs.playerWindow);
  201. Atomic.getEngine().exit();
  202. return true;
  203. }
  204. // If we got here, then we may have been injected by a plugin. Notify the plugins
  205. return ServiceLocator.uiServices.menuItemClicked(refid);
  206. } else if (target.id == "menu tools popup") {
  207. if (refid == "tools toggle profiler") {
  208. Atomic.ui.toggleDebugHud();
  209. return true;
  210. } if (refid == "tools perf profiler") {
  211. Atomic.ui.debugHudProfileMode = Atomic.DebugHudProfileMode.DEBUG_HUD_PROFILE_PERFORMANCE;
  212. Atomic.ui.showDebugHud(true);
  213. return true;
  214. } else if (refid == "tools metrics profiler") {
  215. Atomic.ui.debugHudProfileMode = Atomic.DebugHudProfileMode.DEBUG_HUD_PROFILE_METRICS;
  216. Atomic.ui.showDebugHud(true);
  217. return true;
  218. } else if (refid.indexOf("tools log") != -1) {
  219. let logName = refid.indexOf("editor") != -1 ? "AtomicEditor" : "AtomicPlayer";
  220. let logFolder = Atomic.fileSystem.getAppPreferencesDir(logName, "Logs");
  221. Atomic.fileSystem.systemOpen(logFolder);
  222. }
  223. } else if (target.id == "menu build popup") {
  224. if (refid == "build build") {
  225. EditorUI.getModelOps().showBuild();
  226. return true;
  227. } else if (refid == "build settings") {
  228. EditorUI.getModelOps().showBuildSettings();
  229. return true;
  230. }
  231. } else if (target.id == "menu help popup") {
  232. if (refid == "about atomic editor") {
  233. EditorUI.getModelOps().showAbout();
  234. return true;
  235. }
  236. if (refid == "help what new") {
  237. EditorUI.getModelOps().showNewBuildWindow(false);
  238. return true;
  239. }
  240. let urlLookup = {
  241. "help doc wiki" : "https://github.com/AtomicGameEngine/AtomicGameEngine/wiki/",
  242. "help chat" : "https://gitter.im/AtomicGameEngine/AtomicGameEngine/",
  243. "help api js" : "http://docs.atomicgameengine.com/api/modules/atomic.html",
  244. "help api csharp" : "http://docs.atomicgameengine.com/csharp/AtomicEngine/",
  245. "help api cplusplus" : "http://docs.atomicgameengine.com/cpp",
  246. "help support" : "https://discourse.atomicgameengine.com/",
  247. "help github" : "https://github.com/AtomicGameEngine/AtomicGameEngine/"
  248. };
  249. if (urlLookup[refid]) {
  250. Atomic.fileSystem.systemOpen(urlLookup[refid]);
  251. return true;
  252. }
  253. return false;
  254. } else {
  255. // console.log("Menu: " + target.id + " clicked");
  256. }
  257. }
  258. }
  259. export = MainFrameMenu;
  260. // initialization
  261. var StringID = strings.StringID;
  262. var editItems = {
  263. "Undo": ["edit undo", StringID.ShortcutUndo],
  264. "Redo": ["edit redo", StringID.ShortcutRedo],
  265. "-1": null,
  266. "Cut": ["edit cut", StringID.ShortcutCut],
  267. "Copy": ["edit copy", StringID.ShortcutCopy],
  268. "Paste": ["edit paste", StringID.ShortcutPaste],
  269. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  270. "-2": null,
  271. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  272. "-3": null,
  273. "Find": ["edit find", StringID.ShortcutFind],
  274. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  275. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  276. "-4": null,
  277. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  278. "-5": null,
  279. "Play": ["edit play", StringID.ShortcutPlay],
  280. "Pause/Resume": ["edit pause", StringID.ShortcutPause],
  281. "Step": ["edit step", StringID.ShortcutStep],
  282. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  283. "-6": null,
  284. "Snap Settings": ["edit snap settings"]
  285. };
  286. var toolsItems = {
  287. "Profiler": {
  288. "Toggle HUD": ["tools toggle profiler"],
  289. "Profile Performance": ["tools perf profiler"],
  290. "Profile Metrics": ["tools metrics profiler"]
  291. },
  292. "Logs": {
  293. "Player Log": ["tools log player"],
  294. "Editor Log": ["tools log editor"]
  295. }
  296. };
  297. var buildItems = {
  298. "Build": ["build build", StringID.ShortcutBuild],
  299. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  300. };
  301. var developerItems = {
  302. "Toggle Theme": ["toggle theme"],
  303. "Toggle Code Editor Theme": ["toggle codeeditor"],
  304. "Show Console": ["developer show console"],
  305. "Clear Preferences": ["developer clear preferences"], //Adds clear preference to developer menu items list
  306. "Debug": {
  307. "UI Debugger": ["developer show uidebugger"],
  308. "Asset Database": {
  309. "Scan": ["developer assetdatabase scan"],
  310. "Force Reimport": ["developer assetdatabase force"]
  311. }
  312. }
  313. };
  314. var fileItems = {
  315. "New Project": ["file new project"],
  316. "Open Project": ["file open project"],
  317. "Save Project": ["file save project"],
  318. "-1": null,
  319. "Close Project": ["file close project"],
  320. "-2": null,
  321. "Save File": ["file save file", StringID.ShortcutSaveFile],
  322. "Save All Files": ["file save all"],
  323. "Close File": ["file close file", StringID.ShortcutCloseFile],
  324. "-3": null,
  325. "Quit": "quit"
  326. };
  327. var helpItems = {
  328. "Atomic Community Support": ["help support"],
  329. "Atomic Chat": ["help chat"],
  330. "-1": null,
  331. "Documentation Wiki": "help doc wiki",
  332. "API References": {
  333. "JavaScript & TypeScript": ["help api js"],
  334. "C#": ["help api csharp"],
  335. "C++": ["help api cplusplus"]
  336. },
  337. "-2": null,
  338. "Atomic Game Engine on GitHub": ["help github"],
  339. "-3": null,
  340. "What's New": "help what new",
  341. "About Atomic Editor": "about atomic editor"
  342. };