MainFrameMenu.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import strings = require("./EditorStrings");
  2. var UIMenuItemSource = Atomic.UIMenuItemSource;
  3. var UIMenuItem = Atomic.UIMenuItem;
  4. var StringID = strings.StringID;
  5. var editorItems = {
  6. "About Atomic Editor": "about atomic editor",
  7. "-1": null,
  8. "Manage License": "manage license",
  9. "-2": null,
  10. "Check for Updates": "check update",
  11. "-3": null,
  12. "Quit": "quit"
  13. };
  14. var editItems = {
  15. "Undo": ["edit undo", StringID.ShortcutUndo],
  16. "Redo": ["edit redo", StringID.ShortcutRedo],
  17. "-1": null,
  18. "Cut": ["edit cut", StringID.ShortcutCut],
  19. "Copy": ["edit copy", StringID.ShortcutCopy],
  20. "Paste": ["edit paste", StringID.ShortcutPaste],
  21. "Select All": ["edit select all", StringID.ShortcutSelectAll],
  22. "-2": null,
  23. "Find": ["edit find", StringID.ShortcutFind],
  24. "Find Next": ["edit find next", StringID.ShortcutFindNext],
  25. "Find Prev": ["edit find prev", StringID.ShortcutFindPrev],
  26. "-3": null,
  27. "Format Code": ["edit format code", StringID.ShortcutBeautify],
  28. "-4": null,
  29. "Play": ["edit play", StringID.ShortcutPlay]
  30. };
  31. var fileItems = {
  32. "New Project": ["file new project"],
  33. "Open Project": ["file open project"],
  34. "Save Project": ["file save project"],
  35. "-1": null,
  36. "Close Project": ["file close project"],
  37. "-2": null,
  38. "Save File": ["file save file"],
  39. "Close File": ["file close file"]
  40. }
  41. var srcLookup = {};
  42. srcLookup["menu atomic editor"] = createMenuItemSource(editorItems);
  43. srcLookup["menu edit"] = createMenuItemSource(editItems);
  44. srcLookup["menu file"] = createMenuItemSource(fileItems);
  45. export function getMenuItemSource(id: string): Atomic.UIMenuItemSource {
  46. return srcLookup[id];
  47. }
  48. function createMenuItemSource(items: any): Atomic.UIMenuItemSource {
  49. var src = new UIMenuItemSource();
  50. for (var key in items) {
  51. if (items.hasOwnProperty(key)) {
  52. var value = items[key];
  53. if (typeof value === 'string') {
  54. src.addItem(new UIMenuItem(key, value));
  55. } else if (value == null) {
  56. src.addItem(new UIMenuItem(key));
  57. }
  58. else if (typeof value === 'object' && value.length == 1) {
  59. src.addItem(new UIMenuItem(key, value[0]));
  60. } else if (typeof value === 'object' && value.length == 2) {
  61. src.addItem(new UIMenuItem(key, value[0], strings.EditorString.GetString(value[1])));
  62. }
  63. }
  64. }
  65. return src;
  66. }