MainFrameMenu.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import strings = require("./EditorStrings");
  2. import EditorEvents = require("../editor/EditorEvents");
  3. import EditorUI = require("./EditorUI");
  4. class MainFrameMenu extends Atomic.ScriptObject {
  5. constructor() {
  6. super();
  7. this.srcLookup["menu atomic editor"] = this.createMenuItemSource(editorItems);
  8. this.srcLookup["menu edit"] = this.createMenuItemSource(editItems);
  9. this.srcLookup["menu file"] = this.createMenuItemSource(fileItems);
  10. }
  11. handlePopupMenu(target: Atomic.UIWidget, refid: string): boolean {
  12. if (target.id == "menu atomic editor popup") {
  13. if (refid == "quit") {
  14. this.sendEvent(EditorEvents.Quit);
  15. return true;
  16. }
  17. } else if (target.id == "menu edit popup") {
  18. if (refid == "edit play") {
  19. new ToolCore.PlayCmd().run();
  20. return true;
  21. }
  22. return false;
  23. } else if (target.id == "menu file popup") {
  24. if (refid == "file new project") {
  25. var mo = EditorUI.getModelOps();
  26. mo.showNewProject();
  27. return true;
  28. }
  29. if (refid == "file save file") {
  30. //TODO: this is horrible
  31. //if (this.resourceframe.currentResourceEditor)
  32. // this.resourceframe.currentResourceEditor.save();
  33. return true;
  34. }
  35. return false;
  36. }
  37. }
  38. getMenuItemSource(id: string): Atomic.UIMenuItemSource {
  39. return this.srcLookup[id];
  40. }
  41. createMenuItemSource(items: any): Atomic.UIMenuItemSource {
  42. var src = new UIMenuItemSource();
  43. for (var key in items) {
  44. if (items.hasOwnProperty(key)) {
  45. var value = items[key];
  46. if (typeof value === 'string') {
  47. src.addItem(new UIMenuItem(key, value));
  48. } else if (value == null) {
  49. src.addItem(new UIMenuItem(key));
  50. }
  51. else if (typeof value === 'object' && value.length == 1) {
  52. src.addItem(new UIMenuItem(key, value[0]));
  53. } else if (typeof value === 'object' && value.length == 2) {
  54. src.addItem(new UIMenuItem(key, value[0], strings.EditorString.GetString(value[1])));
  55. }
  56. }
  57. }
  58. return src;
  59. }
  60. srcLookup = {};
  61. }
  62. export = MainFrameMenu;
  63. // initialization
  64. var UIMenuItemSource = Atomic.UIMenuItemSource;
  65. var UIMenuItem = Atomic.UIMenuItem;
  66. var StringID = strings.StringID;
  67. var editorItems = {
  68. "About Atomic Editor": "about atomic editor",
  69. "-1": null,
  70. "Manage License": "manage license",
  71. "-2": null,
  72. "Check for Updates": "check update",
  73. "-3": null,
  74. "Quit": "quit"
  75. };
  76. var editItems = {
  77. "Undo": ["edit undo", StringID.ShortcutUndo],
  78. "Redo": ["edit redo", StringID.ShortcutRedo],
  79. "-1": null,
  80. "Cut": ["edit cut", StringID.ShortcutCut],
  81. "Copy": ["edit copy", StringID.ShortcutCopy],
  82. "Paste": ["edit paste", StringID.ShortcutPaste],
  83. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  84. "-2": null,
  85. "Find": ["edit find", StringID.ShortcutFind],
  86. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  87. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  88. "-3": null,
  89. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  90. "-4": null,
  91. "Play": ["edit play", StringID.ShortcutPlay]
  92. };
  93. var fileItems = {
  94. "New Project": ["file new project"],
  95. "Open Project": ["file open project"],
  96. "Save Project": ["file save project"],
  97. "-1": null,
  98. "Close Project": ["file close project"],
  99. "-2": null,
  100. "Save File": ["file save file"],
  101. "Close File": ["file close file"]
  102. }