MainFrameMenu.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import strings = require("ui/EditorStrings");
  2. import EditorEvents = require("editor/EditorEvents");
  3. import EditorUI = require("ui/EditorUI");
  4. import MenuItemSources = require("./MenuItemSources");
  5. class MainFrameMenu extends Atomic.ScriptObject {
  6. constructor() {
  7. super();
  8. MenuItemSources.createMenuItemSource("menu atomic editor", editorItems);
  9. MenuItemSources.createMenuItemSource("menu edit", editItems);
  10. MenuItemSources.createMenuItemSource("menu file", fileItems);
  11. MenuItemSources.createMenuItemSource("menu build", buildItems);
  12. MenuItemSources.createMenuItemSource("menu tools", toolsItems);
  13. MenuItemSources.createMenuItemSource("menu developer", developerItems);
  14. }
  15. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  16. if (target.id == "menu atomic editor popup") {
  17. if (refid == "about atomic editor") {
  18. EditorUI.getModelOps().showAbout();
  19. return true;
  20. }
  21. if (refid == "manage license") {
  22. EditorUI.getModelOps().showManageLicense();
  23. return true;
  24. }
  25. if (refid == "quit") {
  26. this.sendEvent(EditorEvents.Quit);
  27. return true;
  28. }
  29. } else if (target.id == "menu edit popup") {
  30. if (refid == "edit play") {
  31. EditorUI.getShortcuts().invokePlay();
  32. return true;
  33. }
  34. if (refid == "edit format code") {
  35. EditorUI.getShortcuts().invokeFormatCode();
  36. return true;
  37. }
  38. return false;
  39. } else if (target.id == "menu file popup") {
  40. if (refid == "file new project") {
  41. if (ToolCore.toolSystem.project) {
  42. EditorUI.showModalError("Project Open",
  43. "Please close the current project before creating a new one");
  44. return true;
  45. }
  46. var mo = EditorUI.getModelOps();
  47. mo.showNewProject();
  48. return true;
  49. }
  50. if (refid == "file open project") {
  51. if (ToolCore.toolSystem.project) {
  52. EditorUI.showModalError("Project Open",
  53. "Please close the current project before opening new one");
  54. return true;
  55. }
  56. var utils = new Editor.FileUtils();
  57. var path = utils.openProjectFileDialog();
  58. if (path) {
  59. this.sendEvent(EditorEvents.LoadProject, { path: path });
  60. }
  61. return true;
  62. }
  63. if (refid == "file close project") {
  64. this.sendEvent(EditorEvents.CloseProject);
  65. return true;
  66. }
  67. if (refid == "file save file") {
  68. EditorUI.getShortcuts().invokeFileSave();
  69. return true;
  70. }
  71. if (refid == "file close file") {
  72. EditorUI.getShortcuts().invokeFileClose();
  73. return true;
  74. }
  75. if (refid == "file save all") {
  76. this.sendEvent(EditorEvents.SaveAllResources);
  77. return true;
  78. }
  79. return false;
  80. } else if (target.id == "menu developer popup") {
  81. if (refid == "developer show console") {
  82. Atomic.ui.showConsole(true);
  83. return true;
  84. }
  85. } else if (target.id == "menu tools popup") {
  86. if (refid == "tools toggle profiler") {
  87. Atomic.ui.toggleDebugHud();
  88. return true;
  89. }
  90. } else if (target.id == "menu build popup") {
  91. if (refid == "build build") {
  92. var buildNotification = new Atomic.UIMessageWindow(EditorUI.getMainFrame(), "build_notify");
  93. buildNotification.show("Build Notification", "Building is currently unavailable in this development snapshot.", Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 300, 140);
  94. return true;
  95. }
  96. }
  97. }
  98. }
  99. export = MainFrameMenu;
  100. // initialization
  101. var StringID = strings.StringID;
  102. var editorItems = {
  103. "About Atomic Editor": "about atomic editor",
  104. "-1": null,
  105. "Manage License": "manage license",
  106. "-2": null,
  107. "Check for Updates": "check update",
  108. "-3": null,
  109. "Quit": "quit"
  110. };
  111. var editItems = {
  112. "Undo": ["edit undo", StringID.ShortcutUndo],
  113. "Redo": ["edit redo", StringID.ShortcutRedo],
  114. "-1": null,
  115. "Cut": ["edit cut", StringID.ShortcutCut],
  116. "Copy": ["edit copy", StringID.ShortcutCopy],
  117. "Paste": ["edit paste", StringID.ShortcutPaste],
  118. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  119. "-2": null,
  120. "Find": ["edit find", StringID.ShortcutFind],
  121. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  122. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  123. "-3": null,
  124. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  125. "-4": null,
  126. "Play": ["edit play", StringID.ShortcutPlay]
  127. };
  128. var toolsItems = {
  129. "Toggle Profiler": ["tools toggle profiler"]
  130. }
  131. var buildItems = {
  132. "Build": ["build build"]
  133. }
  134. var developerItems = {
  135. "Show Console": ["developer show console"]
  136. }
  137. var fileItems = {
  138. "New Project": ["file new project"],
  139. "Open Project": ["file open project"],
  140. "Save Project": ["file save project"],
  141. "-1": null,
  142. "Close Project": ["file close project"],
  143. "-2": null,
  144. "Save File": ["file save file"],
  145. "Save All Files": ["file save all"],
  146. "Close File": ["file close file"]
  147. }