MainFrameMenu.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. }
  12. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  13. if (target.id == "menu atomic editor popup") {
  14. if (refid == "about atomic editor") {
  15. EditorUI.getModelOps().showAbout();
  16. return true;
  17. }
  18. if (refid == "manage license") {
  19. EditorUI.getModelOps().showManageLicense();
  20. return true;
  21. }
  22. if (refid == "quit") {
  23. this.sendEvent(EditorEvents.Quit);
  24. return true;
  25. }
  26. } else if (target.id == "menu edit popup") {
  27. if (refid == "edit play") {
  28. EditorUI.getShortcuts().invokePlay();
  29. return true;
  30. }
  31. if (refid == "edit format code") {
  32. EditorUI.getShortcuts().invokeFormatCode();
  33. return true;
  34. }
  35. return false;
  36. } else if (target.id == "menu file popup") {
  37. if (refid == "file new project") {
  38. if (ToolCore.toolSystem.project) {
  39. EditorUI.showModalError("Project Open",
  40. "Please close the current project before creating a new one");
  41. return true;
  42. }
  43. var mo = EditorUI.getModelOps();
  44. mo.showNewProject();
  45. return true;
  46. }
  47. if (refid == "file open project") {
  48. if (ToolCore.toolSystem.project) {
  49. EditorUI.showModalError("Project Open",
  50. "Please close the current project before opening new one");
  51. return true;
  52. }
  53. var utils = new Editor.FileUtils();
  54. var path = utils.openProjectFileDialog();
  55. if (path) {
  56. this.sendEvent(EditorEvents.LoadProject, { path: path });
  57. }
  58. return true;
  59. }
  60. if (refid == "file close project") {
  61. this.sendEvent(EditorEvents.CloseProject);
  62. return true;
  63. }
  64. if (refid == "file save file") {
  65. EditorUI.getShortcuts().invokeFileSave();
  66. return true;
  67. }
  68. if (refid == "file close file") {
  69. EditorUI.getShortcuts().invokeFileClose();
  70. return true;
  71. }
  72. if (refid == "file save all") {
  73. this.sendEvent(EditorEvents.SaveAllResources);
  74. return true;
  75. }
  76. return false;
  77. }
  78. }
  79. }
  80. export = MainFrameMenu;
  81. // initialization
  82. var StringID = strings.StringID;
  83. var editorItems = {
  84. "About Atomic Editor": "about atomic editor",
  85. "-1": null,
  86. "Manage License": "manage license",
  87. "-2": null,
  88. "Check for Updates": "check update",
  89. "-3": null,
  90. "Quit": "quit"
  91. };
  92. var editItems = {
  93. "Undo": ["edit undo", StringID.ShortcutUndo],
  94. "Redo": ["edit redo", StringID.ShortcutRedo],
  95. "-1": null,
  96. "Cut": ["edit cut", StringID.ShortcutCut],
  97. "Copy": ["edit copy", StringID.ShortcutCopy],
  98. "Paste": ["edit paste", StringID.ShortcutPaste],
  99. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  100. "-2": null,
  101. "Find": ["edit find", StringID.ShortcutFind],
  102. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  103. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  104. "-3": null,
  105. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  106. "-4": null,
  107. "Play": ["edit play", StringID.ShortcutPlay]
  108. };
  109. var fileItems = {
  110. "New Project": ["file new project"],
  111. "Open Project": ["file open project"],
  112. "Save Project": ["file save project"],
  113. "-1": null,
  114. "Close Project": ["file close project"],
  115. "-2": null,
  116. "Save File": ["file save file"],
  117. "Save All Files": ["file save all"],
  118. "Close File": ["file close file"]
  119. }