MainFrameMenu.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. constructor() {
  29. super();
  30. MenuItemSources.createMenuItemSource("menu edit", editItems);
  31. MenuItemSources.createMenuItemSource("menu file", fileItems);
  32. MenuItemSources.createMenuItemSource("menu build", buildItems);
  33. MenuItemSources.createMenuItemSource("menu tools", toolsItems);
  34. MenuItemSources.createMenuItemSource("menu developer", developerItems);
  35. MenuItemSources.createMenuItemSource("menu help", helpItems);
  36. }
  37. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  38. if (target.id == "menu edit popup") {
  39. if (refid == "edit play") {
  40. EditorUI.getShortcuts().invokePlayOrStopPlayer();
  41. return true;
  42. }
  43. if (refid == "edit play debug") {
  44. EditorUI.getShortcuts().invokePlayOrStopPlayer(true);
  45. return true;
  46. }
  47. if (refid == "edit format code") {
  48. EditorUI.getShortcuts().invokeFormatCode();
  49. return true;
  50. }
  51. if (refid == "edit undo") {
  52. EditorUI.getShortcuts().invokeUndo();
  53. return true;
  54. }
  55. if (refid == "edit redo") {
  56. EditorUI.getShortcuts().invokeRedo();
  57. return true;
  58. }
  59. if (refid == "edit cut") {
  60. EditorUI.getShortcuts().invokeCut();
  61. return true;
  62. }
  63. if (refid == "edit copy") {
  64. EditorUI.getShortcuts().invokeCopy();
  65. return true;
  66. }
  67. if (refid == "edit paste") {
  68. EditorUI.getShortcuts().invokePaste();
  69. return true;
  70. }
  71. if (refid == "edit select all") {
  72. EditorUI.getShortcuts().invokeSelectAll();
  73. return true;
  74. }
  75. if (refid == "edit snap settings") {
  76. EditorUI.getModelOps().showSnapSettings();
  77. return true;
  78. }
  79. if (refid == "edit frame selected") {
  80. EditorUI.getShortcuts().invokeFrameSelected();
  81. return true;
  82. }
  83. return false;
  84. } else if (target.id == "menu file popup") {
  85. if (refid == "quit") {
  86. this.sendEvent("ExitRequested");
  87. return true;
  88. }
  89. if (refid == "file new project") {
  90. if (ToolCore.toolSystem.project) {
  91. EditorUI.showModalError("Project Open",
  92. "Please close the current project before creating a new one");
  93. return true;
  94. }
  95. var mo = EditorUI.getModelOps();
  96. mo.showNewProject();
  97. return true;
  98. }
  99. if (refid == "file open project") {
  100. var utils = new Editor.FileUtils();
  101. var path = utils.openProjectFileDialog();
  102. if (path == "") {
  103. return true;
  104. }
  105. var openProject = () => this.sendEvent(EditorEvents.LoadProject, { path: path });
  106. if (ToolCore.toolSystem.project) {
  107. this.subscribeToEvent(EditorEvents.ProjectClosed, () => {
  108. this.unsubscribeFromEvent(EditorEvents.ProjectClosed);
  109. openProject();
  110. });
  111. this.sendEvent(EditorEvents.CloseProject);
  112. } else {
  113. openProject();
  114. }
  115. return true;
  116. }
  117. if (refid == "file close project") {
  118. this.sendEvent(EditorEvents.CloseProject);
  119. return true;
  120. }
  121. if (refid == "file save file") {
  122. EditorUI.getShortcuts().invokeFileSave();
  123. return true;
  124. }
  125. if (refid == "file close file") {
  126. EditorUI.getShortcuts().invokeFileClose();
  127. return true;
  128. }
  129. if (refid == "file save all") {
  130. this.sendEvent(EditorEvents.SaveAllResources);
  131. return true;
  132. }
  133. return false;
  134. } else if (target.id == "menu developer popup") {
  135. if (refid == "developer show console") {
  136. Atomic.ui.showConsole(true);
  137. return true;
  138. }
  139. if (refid == "developer show uidebugger") {
  140. if (Atomic.engine.debugBuild) {
  141. Atomic.UI.debugShowSettingsWindow(EditorUI.getView());
  142. }
  143. else {
  144. EditorUI.showModalError("Debug Build Required",
  145. "UIDebugger currently requires a Debug engine build");
  146. }
  147. return true;
  148. }
  149. if (refid == "developer assetdatabase scan") {
  150. ToolCore.assetDatabase.scan();
  151. }
  152. if (refid == "developer assetdatabase force") {
  153. ToolCore.assetDatabase.reimportAllAssets();
  154. }
  155. //Sets all value in prefs.json to default and shuts down the editor.
  156. if (refid == "developer clear preferences") {
  157. var myPrefs = Preferences.getInstance();
  158. myPrefs.useDefaultConfig();
  159. myPrefs.saveEditorWindowData(myPrefs.editorWindow);
  160. myPrefs.savePlayerWindowData(myPrefs.playerWindow);
  161. Atomic.getEngine().exit();
  162. }
  163. } else if (target.id == "menu tools popup") {
  164. if (refid == "tools toggle profiler") {
  165. Atomic.ui.toggleDebugHud();
  166. return true;
  167. }
  168. } else if (target.id == "menu build popup") {
  169. if (refid == "build build") {
  170. EditorUI.getModelOps().showBuild();
  171. return true;
  172. } else if (refid == "build settings") {
  173. EditorUI.getModelOps().showBuildSettings();
  174. return true;
  175. }
  176. } else if (target.id == "menu help popup") {
  177. if (refid == "about atomic editor") {
  178. EditorUI.getModelOps().showAbout();
  179. return true;
  180. }
  181. if (refid == "manage license") {
  182. EditorUI.getModelOps().showManageLicense();
  183. return true;
  184. }
  185. if (refid == "help forums") {
  186. Atomic.fileSystem.systemOpen("http://atomicgameengine.com/forum/");
  187. return true;
  188. } else if (refid == "help chat") {
  189. Atomic.fileSystem.systemOpen("https://gitter.im/AtomicGameEngine/AtomicGameEngine/");
  190. return true;
  191. } else if (refid == "help github") {
  192. Atomic.fileSystem.systemOpen("https://github.com/AtomicGameEngine/AtomicGameEngine/");
  193. return true;
  194. } else if (refid == "help api") {
  195. var url = "file://" + ToolCore.toolEnvironment.toolDataDir + "Docs/JSDocs/Atomic.html";
  196. Atomic.fileSystem.systemOpen(url);
  197. return true;
  198. }
  199. }
  200. }
  201. }
  202. export = MainFrameMenu;
  203. // initialization
  204. var StringID = strings.StringID;
  205. var editItems = {
  206. "Undo": ["edit undo", StringID.ShortcutUndo],
  207. "Redo": ["edit redo", StringID.ShortcutRedo],
  208. "-1": null,
  209. "Cut": ["edit cut", StringID.ShortcutCut],
  210. "Copy": ["edit copy", StringID.ShortcutCopy],
  211. "Paste": ["edit paste", StringID.ShortcutPaste],
  212. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  213. "-2": null,
  214. "Frame Selected": ["edit frame selected", StringID.ShortcutFrameSelected],
  215. "-3": null,
  216. "Find": ["edit find", StringID.ShortcutFind],
  217. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  218. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  219. "-4": null,
  220. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  221. "-5": null,
  222. "Play": ["edit play", StringID.ShortcutPlay],
  223. "Debug (C# Project)": ["edit play debug", StringID.ShortcutPlayDebug],
  224. "-6": null,
  225. "Snap Settings": ["edit snap settings"]
  226. };
  227. var toolsItems = {
  228. "Toggle Profiler": ["tools toggle profiler"]
  229. };
  230. var buildItems = {
  231. "Build": ["build build", StringID.ShortcutBuild],
  232. "Build Settings": ["build settings", StringID.ShortcutBuildSettings]
  233. };
  234. var developerItems = {
  235. "Show Console": ["developer show console"],
  236. "Clear Preferences": ["developer clear preferences"], //Adds clear preference to developer menu items list
  237. "Debug": {
  238. "UI Debugger": ["developer show uidebugger"],
  239. "Asset Database": {
  240. "Scan": ["developer assetdatabase scan"],
  241. "Force Reimport": ["developer assetdatabase force"]
  242. }
  243. }
  244. };
  245. var fileItems = {
  246. "New Project": ["file new project"],
  247. "Open Project": ["file open project"],
  248. "Save Project": ["file save project"],
  249. "-1": null,
  250. "Close Project": ["file close project"],
  251. "-2": null,
  252. "Save File": ["file save file", StringID.ShortcutSaveFile],
  253. "Save All Files": ["file save all"],
  254. "Close File": ["file close file", StringID.ShortcutCloseFile],
  255. "-3": null,
  256. "Quit": "quit"
  257. };
  258. var helpItems = {
  259. "Check for Updates": "check update",
  260. "API Documentation": ["help api"],
  261. "-1": null,
  262. "Atomic Chat": ["help chat"],
  263. "Atomic Forums": ["help forums"],
  264. "-2": null,
  265. "Atomic Game Engine on GitHub": ["help github"],
  266. "About Atomic Editor": "about atomic editor"
  267. };