MainFrameMenu.ts 12 KB

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