Home Reference Source

cables_dev/cables_ui/src/ui/components/tabs/tab_history.js

  1. import undo from "../../utils/undo.js";
  2. export default class MetaHistory
  3. {
  4. constructor(tabs)
  5. {
  6. this.html = "";
  7. this._tab = new CABLES.UI.Tab("History", { "icon": "list", "infotext": "tab_history", "padding": true });
  8. tabs.addTab(this._tab);
  9. undo.setCallback(this.update.bind(this));
  10. this.update();
  11. this._tab.on("onActivate", () => { this.update(); });
  12. }
  13. update()
  14. {
  15. if (!this._tab.isVisible()) return;
  16. this.html = "<h2>Undo History</h2>";
  17. this.html += "<span onclick=\"CABLES.UI.undo.undo();\" class=\"iconbutton\"><span class=\"icon icon-arrow-left\" ></span></span>";
  18. this.html += "<span onclick=\"CABLES.UI.undo.redo();\" class=\"iconbutton\"><span class=\"icon icon-arrow-right\"></span></span>";
  19. const commands = undo.getCommands();
  20. this.html += "&nbsp;&nbsp;&nbsp;" + (undo.getIndex() + 1) + " / " + (commands.length) + "<br/><br/>";
  21. let groupSummary = [];
  22. let lastGroup = null;
  23. for (let i = -1; i < commands.length; i++)
  24. {
  25. let cmd = null;
  26. if (i == -1) cmd = { "groupName": "Open patch", "group": true };
  27. else cmd = commands[i];
  28. let style = "";
  29. if (!cmd.group || i == 0 || (i > 0 && lastGroup && lastGroup != cmd.group)) style += "margin-top:4px;";
  30. if (undo.getIndex() == i) style += "border-left:4px solid var(--color-10);background-color:var(--color-04);";
  31. else if (undo.getIndex() < i) style += "opacity:0.4;border-left:4px solid var(--color-06);background-color:var(--color-03);";
  32. else style += "border-left:4px solid var(--color-08);background-color:var(--color-03);";
  33. groupSummary.push(cmd.title);
  34. if (!cmd.group || cmd.groupName) this.html += "<div style=\"padding:2px;padding-left:7px;" + style + "\">";
  35. if (!cmd.group)
  36. {
  37. this.html += "<b>" + cmd.title + "</b>";
  38. groupSummary = [];
  39. }
  40. if (cmd.groupName)
  41. {
  42. if (i != -1 && groupSummary.length > 1)
  43. {
  44. groupSummary.length = Math.min(groupSummary.length, 5);
  45. this.html += groupSummary.join(", ");
  46. this.html += "...<br/>";
  47. }
  48. this.html += "<b>" + cmd.groupName + "</b>";
  49. lastGroup = cmd.group;
  50. groupSummary = [];
  51. }
  52. this.html += "</div>";
  53. }
  54. this._tab.html(this.html);
  55. }
  56. show()
  57. {
  58. this.update();
  59. }
  60. }