MainFrameMenu.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import strings = require("./EditorStrings");
  2. import EditorEvents = require("../editor/EditorEvents");
  3. import EditorUI = require("./EditorUI");
  4. import MenuItemSources = require("./menus/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. this.subscribeToEvent("WidgetEvent", (ev: Atomic.UIWidgetEvent) => {
  12. if (ev.type == Atomic.UI_EVENT_TYPE_SHORTCUT) {
  13. if (ev.refid == "save") {
  14. this.sendEvent(EditorEvents.SaveResource);
  15. return true;
  16. }
  17. }
  18. })
  19. }
  20. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  21. if (target.id == "menu atomic editor popup") {
  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. new ToolCore.PlayCmd().run();
  29. return true;
  30. }
  31. return false;
  32. } else if (target.id == "menu file popup") {
  33. if (refid == "file new project") {
  34. var mo = EditorUI.getModelOps();
  35. mo.showNewProject();
  36. return true;
  37. }
  38. if (refid == "file save file") {
  39. this.sendEvent(EditorEvents.SaveResource);
  40. return true;
  41. }
  42. return false;
  43. }
  44. }
  45. }
  46. export = MainFrameMenu;
  47. // initialization
  48. var StringID = strings.StringID;
  49. var editorItems = {
  50. "About Atomic Editor": "about atomic editor",
  51. "-1": null,
  52. "Manage License": "manage license",
  53. "-2": null,
  54. "Check for Updates": "check update",
  55. "-3": null,
  56. "Quit": "quit"
  57. };
  58. var editItems = {
  59. "Undo": ["edit undo", StringID.ShortcutUndo],
  60. "Redo": ["edit redo", StringID.ShortcutRedo],
  61. "-1": null,
  62. "Cut": ["edit cut", StringID.ShortcutCut],
  63. "Copy": ["edit copy", StringID.ShortcutCopy],
  64. "Paste": ["edit paste", StringID.ShortcutPaste],
  65. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  66. "-2": null,
  67. "Find": ["edit find", StringID.ShortcutFind],
  68. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  69. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  70. "-3": null,
  71. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  72. "-4": null,
  73. "Play": ["edit play", StringID.ShortcutPlay]
  74. };
  75. var fileItems = {
  76. "New Project": ["file new project"],
  77. "Open Project": ["file open project"],
  78. "Save Project": ["file save project"],
  79. "-1": null,
  80. "Close Project": ["file close project"],
  81. "-2": null,
  82. "Save File": ["file save file"],
  83. "Close File": ["file close file"]
  84. }