MainFrameMenu.ts 3.4 KB

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