MainFrameMenu.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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("ExitRequested");
  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 openProject = () => this.sendEvent(EditorEvents.LoadProject, { path: path });
  133. if (ToolCore.toolSystem.project) {
  134. this.subscribeToEvent(EditorEvents.ProjectClosed, () => {
  135. this.unsubscribeFromEvent(EditorEvents.ProjectClosed);
  136. openProject();
  137. });
  138. this.sendEvent(EditorEvents.CloseProject);
  139. } else {
  140. openProject();
  141. }
  142. return true;
  143. }
  144. if (refid == "file close project") {
  145. this.sendEvent(EditorEvents.CloseProject);
  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(EditorEvents.SaveAllResources);
  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. }
  200. } else if (target.id == "menu build popup") {
  201. if (refid == "build build") {
  202. EditorUI.getModelOps().showBuild();
  203. return true;
  204. } else if (refid == "build settings") {
  205. EditorUI.getModelOps().showBuildSettings();
  206. return true;
  207. }
  208. } else if (target.id == "menu help popup") {
  209. if (refid == "about atomic editor") {
  210. EditorUI.getModelOps().showAbout();
  211. return true;
  212. }
  213. if (refid == "manage license") {
  214. EditorUI.getModelOps().showManageLicense();
  215. return true;
  216. }
  217. if (refid == "help forums") {
  218. Atomic.fileSystem.systemOpen("http://atomicgameengine.com/forum/");
  219. return true;
  220. } else if (refid == "help chat") {
  221. Atomic.fileSystem.systemOpen("https://gitter.im/AtomicGameEngine/AtomicGameEngine/");
  222. return true;
  223. }
  224. else if (refid == "help getting started") {
  225. Atomic.fileSystem.systemOpen("http://atomicgameengine.com/learn/");
  226. return true;
  227. } else if (refid == "help github") {
  228. Atomic.fileSystem.systemOpen("https://github.com/AtomicGameEngine/AtomicGameEngine/");
  229. return true;
  230. } else if (refid == "help api") {
  231. var url = "file://" + ToolCore.toolEnvironment.toolDataDir + "Docs/JSDocs/Atomic.html";
  232. Atomic.fileSystem.systemOpen(url);
  233. return true;
  234. }
  235. } else {
  236. console.log("Menu: " + target.id + " clicked");
  237. }
  238. }
  239. }
  240. export = MainFrameMenu;
  241. // initialization
  242. var StringID = strings.StringID;
  243. var editItems = {
  244. "Undo": ["edit undo", StringID.ShortcutUndo],
  245. "Redo": ["edit redo", StringID.ShortcutRedo],
  246. "-1": null,
  247. "Cut": ["edit cut", StringID.ShortcutCut],
  248. "Copy": ["edit copy", StringID.ShortcutCopy],
  249. "Paste": ["edit paste", StringID.ShortcutPaste],
  250. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  251. "-2": null,
  252. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  253. "-3": null,
  254. "Find": ["edit find", StringID.ShortcutFind],
  255. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  256. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  257. "-4": null,
  258. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  259. "-5": null,
  260. "Play": ["edit play", StringID.ShortcutPlay],
  261. "Pause/Resume": ["edit pause", StringID.ShortcutPause],
  262. "Step": ["edit step", StringID.ShortcutStep],
  263. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  264. "-6": null,
  265. "Snap Settings": ["edit snap settings"]
  266. };
  267. var toolsItems = {
  268. "Toggle Profiler": ["tools toggle profiler"]
  269. };
  270. var buildItems = {
  271. "Build": ["build build", StringID.ShortcutBuild],
  272. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  273. };
  274. var developerItems = {
  275. "Show Console": ["developer show console"],
  276. "Clear Preferences": ["developer clear preferences"], //Adds clear preference to developer menu items list
  277. "Debug": {
  278. "UI Debugger": ["developer show uidebugger"],
  279. "Asset Database": {
  280. "Scan": ["developer assetdatabase scan"],
  281. "Force Reimport": ["developer assetdatabase force"]
  282. }
  283. }
  284. };
  285. var fileItems = {
  286. "New Project": ["file new project"],
  287. "Open Project": ["file open project"],
  288. "Save Project": ["file save project"],
  289. "-1": null,
  290. "Close Project": ["file close project"],
  291. "-2": null,
  292. "Save File": ["file save file", StringID.ShortcutSaveFile],
  293. "Save All Files": ["file save all"],
  294. "Close File": ["file close file", StringID.ShortcutCloseFile],
  295. "-3": null,
  296. "Quit": "quit"
  297. };
  298. var helpItems = {
  299. "Getting Started": "help getting started",
  300. "API Documentation": ["help api"],
  301. "-1": null,
  302. "Atomic Chat": ["help chat"],
  303. "Atomic Forums": ["help forums"],
  304. "-2": null,
  305. "Atomic Game Engine on GitHub": ["help github"],
  306. "About Atomic Editor": "about atomic editor"
  307. };