Home Reference Source

cables_dev/cables_ui/src/ui/components/opparampanel/op_parampanel.js

  1. import { Logger, ele, Events } from "cables-shared-client";
  2. import { Op, Port, utils } from "cables";
  3. import { getHandleBarHtml } from "../../utils/handlebars.js";
  4. import { GuiText } from "../../text.js";
  5. import { PortHtmlGenerator } from "./op_params_htmlgen.js";
  6. import ParamsListener from "./params_listener.js";
  7. import gluiconfig from "../../glpatch/gluiconfig.js";
  8. import GlPatch from "../../glpatch/glpatch.js";
  9. import { notify } from "../../elements/notification.js";
  10. import namespace from "../../namespaceutils.js";
  11. import Gui, { gui } from "../../gui.js";
  12. import { platform } from "../../platform.js";
  13. import { contextMenu } from "../../elements/contextmenu.js";
  14. import { UserSettings, userSettings } from "../usersettings.js";
  15. import { CmdOps } from "../../commands/cmd_op.js";
  16. import uiconfig from "../../uiconfig.js";
  17. /** Panel showing the parameters (ports) of the selected op. */
  18. class OpParampanel extends Events
  19. {
  20. /**
  21. * @param {string} eleid
  22. */
  23. constructor(eleid = null)
  24. {
  25. super();
  26. this.panelId = utils.simpleId();
  27. this._eleId = eleid;
  28. this._log = new Logger("OpParampanel");
  29. this._htmlGen = new PortHtmlGenerator(this.panelId);
  30. /** @type {Op} */
  31. this._currentOp = null;
  32. this._eventPrefix = utils.shortId();
  33. /** @type {Port} */
  34. this._portLineDragPort = null;
  35. this._portLineDragListening = false;
  36. /** @type {Array<Port>} */
  37. this._portsIn = [];
  38. /** @type {Array<Port>} */
  39. this._portsOut = [];
  40. this._paramsListener = new ParamsListener(this.panelId);
  41. this._portUiAttrListeners = [];
  42. this._startedGlobalListeners = false;
  43. this.reloadListener = null;
  44. }
  45. _startPortLineDragListeners()
  46. {
  47. if (this._portLineDragListening) return;
  48. const elPatchViews = document.getElementById("patchviews");
  49. if (!elPatchViews) return;
  50. this._portLineDragListening = true;
  51. document.addEventListener("pointerup", () => { this._portLineDragPort = null; });
  52. elPatchViews.addEventListener("pointerenter", (e) =>
  53. {
  54. const port = this._portLineDragPort;
  55. if (!port) return;
  56. this._portLineDragPort = null;
  57. if (!gui.patchView._patchRenderer.getOp) return;
  58. const glOp = gui.patchView._patchRenderer.getOp(port.op.id);
  59. if (!glOp) return;
  60. const glPort = glOp.getGlPort(port.name);
  61. if (glPort) gui.patchView._patchRenderer.emitEvent(GlPatch.EVENT_MOUSE_DOWN_OVER_PORT, glPort, glOp.id, port.name, e);
  62. });
  63. }
  64. get op()
  65. {
  66. return this._currentOp;
  67. }
  68. /**
  69. * @param {string} eleid
  70. */
  71. setParentElementId(eleid)
  72. {
  73. this._eleId = eleid;
  74. }
  75. dispose()
  76. {
  77. this._stopListeners();
  78. }
  79. clear()
  80. {
  81. this._stopListeners();
  82. this._currentOp = null;
  83. }
  84. refresh()
  85. {
  86. this.show(this._currentOp);
  87. }
  88. /**
  89. * @param {import("cables/src/core/core_patch.js").OpUiAttribs} attr
  90. */
  91. _onUiAttrChangeOp(attr)
  92. {
  93. if (attr.hasOwnProperty("uierrors")) this.updateUiErrors();
  94. }
  95. /**
  96. * @param {object} attr
  97. * @param {Port} port
  98. */
  99. _onUiAttrChangePort(attr, port)
  100. {
  101. if (!attr) return;
  102. if (attr.hasOwnProperty("greyout")) this.refreshDelayed();
  103. // todo: only update this part of the html
  104. if (attr.hasOwnProperty("hover"))
  105. {
  106. const portParamRow = ele.byClass("paramport_1_" + port.id);
  107. if (portParamRow)
  108. {
  109. if (attr.hover) portParamRow.classList.add("hoverPort");
  110. else portParamRow.classList.remove("hoverPort");
  111. }
  112. }
  113. }
  114. /**
  115. * @param {Op<any>} [op]
  116. */
  117. _stopListeners(op)
  118. {
  119. op = op || this._currentOp;
  120. if (!op) return;
  121. for (let i = 0; i < this._portUiAttrListeners.length; i++)
  122. {
  123. const listener = this._portUiAttrListeners[i];
  124. listener.port.off(listener.listenId);
  125. }
  126. this._portUiAttrListeners.length = 0;
  127. this.onOpUiAttrChange = op.off(this.onOpUiAttrChange);
  128. }
  129. /**
  130. * @param {Op<any>} op
  131. */
  132. _startListeners(op)
  133. {
  134. if (!op)
  135. {
  136. this._stopListeners();
  137. return;
  138. }
  139. if (!this.hasExposeListener)
  140. {
  141. this.hasExposeListener = gui.corePatch().on(Port.EVENT_SUBPATCH_EXPOSE,
  142. (subpatchid) =>
  143. {
  144. if (
  145. op &&
  146. op.storage && op.storage.subPatchVer &&
  147. op.patchId.get() === subpatchid
  148. )
  149. {
  150. op.refreshParams();
  151. }
  152. });
  153. }
  154. this.onOpUiAttrChange = op.on(Op.EVENT_UIATTR_CHANGE, this._onUiAttrChangeOp.bind(this));
  155. for (let i = 0; i < this._portsIn.length; i++)
  156. {
  157. const listenId = this._portsIn[i].on(
  158. Port.EVENT_UIATTRCHANGE,
  159. this._onUiAttrChangePort.bind(this),
  160. this._eventPrefix);
  161. this._portUiAttrListeners.push({ "listenId": listenId, "port": this._portsIn[i] });
  162. }
  163. }
  164. refreshDelayed()
  165. {
  166. clearTimeout(this.refreshTimeout);
  167. this.refreshTimeout = setTimeout(() =>
  168. {
  169. this.show(this._currentOp);
  170. }, 50);
  171. }
  172. /**
  173. * @param {Port} port
  174. */
  175. _checkPortTypes(port)
  176. {
  177. if (port.type == Port.TYPE_NUMBER && typeof port.get() == "string")
  178. {
  179. this.op.setUiError("typeerr", "Wrong type! String in number " + port.name, 0);
  180. }
  181. }
  182. /**
  183. * @param {Op|String} op
  184. */
  185. show(op)
  186. {
  187. if (!gui.finishedLoading()) return;
  188. if (!this._startedGlobalListeners)
  189. {
  190. this._startedGlobalListeners = true;
  191. gui.corePatch().on("bookmarkschanged", () => { gui.bookmarks.needRefreshSubs = true; this._startedGlobalListeners = true; if (!this._currentOp) gui.patchParamPanel.show(true); });
  192. gui.corePatch().on("subpatchesChanged", () => { gui.bookmarks.needRefreshSubs = true; this._startedGlobalListeners = true; if (!this._currentOp) gui.patchParamPanel.show(true); });
  193. gui.corePatch().on("subpatchCreated", () => { gui.bookmarks.needRefreshSubs = true; this._startedGlobalListeners = true; if (!this._currentOp) gui.patchParamPanel.show(true); });
  194. gui.corePatch().on("patchLoadEnd", () => { gui.bookmarks.needRefreshSubs = true; this._startedGlobalListeners = true; if (!this._currentOp) gui.patchParamPanel.show(true); });
  195. }
  196. if (this.reloadListener)
  197. this.reloadListener = gui.corePatch().on("opReloaded", () =>
  198. {
  199. this.refreshDelayed();
  200. });
  201. const perf = gui.uiProfiler.start("[opparampanel] show");
  202. if (typeof op == "string") op = gui.corePatch().getOpById(op);
  203. if (!gui.showingtwoMetaPanel && gui.metaTabs.getActiveTab() && gui.metaTabs.getActiveTab().title != "op")
  204. gui.metaTabs.activateTabByName("op");
  205. if (this._currentOp) this._stopListeners();
  206. this._currentOp = op;
  207. if (!op) return;
  208. op.setUiError("typeerr", null);
  209. this._portsIn = op.portsIn;
  210. this._portsOut = op.portsOut;
  211. if (op.storage && op.storage.subPatchVer && op.patchId)
  212. {
  213. const ports = gui.patchView.getSubPatchExposedPorts(op.patchId.get());
  214. for (let i = 0; i < ports.length; i++)
  215. {
  216. if (ports[i].direction === Port.DIR_IN && this._portsIn.indexOf(ports[i]) == -1) this._portsIn.push(ports[i]);
  217. if (ports[i].direction === Port.DIR_OUT && this._portsOut.indexOf(ports[i]) == -1) this._portsOut.push(ports[i]);
  218. }
  219. }
  220. this._startListeners(this._currentOp);
  221. op.emitEvent("uiParamPanel", op);
  222. const perfHtml = gui.uiProfiler.start("[opparampanel] build html ");
  223. gui.opHistory.push(op.id);
  224. gui.setTransformGizmo(null);
  225. gui.emitEvent(Gui.EVENT_OP_SELECTIONCHANGED, op);
  226. this.emitEvent("opSelected", op);
  227. // op.isServerOp = gui.serverOps.isServerOp(op.objName);
  228. /*
  229. * show first anim in timeline
  230. * if (self.timeLine)
  231. * {
  232. * let foundAnim = false;
  233. * for (let i = 0; i < this._portsIn.length; i++)
  234. * {
  235. * if (this._portsIn[i].isAnimated())
  236. * {
  237. * self.timeLine.setAnim(this._portsIn[i].anim, {
  238. * "name": this._portsIn[i].name,
  239. * });
  240. * foundAnim = true;
  241. * continue;
  242. * }
  243. * }
  244. * if (!foundAnim) self.timeLine.setAnim(null);
  245. * }
  246. */
  247. this._portsIn.sort(function (a, b) { return (a.uiAttribs.order || 0) - (b.uiAttribs.order || 0); });
  248. let html = this._htmlGen.getHtmlOpHeader(op);
  249. gui.showInfo(GuiText.patchSelectedOp);
  250. if (this._portsIn.length > 0)
  251. {
  252. const perfLoop = gui.uiProfiler.start("[opparampanel] _showOpParamsLOOP IN");
  253. html += this._htmlGen.getHtmlHeaderPorts("in", "Input");
  254. html += this._htmlGen.getHtmlInputPorts(this._portsIn);
  255. perfLoop.finish();
  256. }
  257. if (this._portsOut.length > 0)
  258. {
  259. html += this._htmlGen.getHtmlHeaderPorts("out", "Output");
  260. const perfLoopOut = gui.uiProfiler.start("[opparampanel] _showOpParamsLOOP OUT");
  261. html += this._htmlGen.getHtmlOutputPorts(this._portsOut);
  262. perfLoopOut.finish();
  263. }
  264. html += getHandleBarHtml("params_op_foot", { "commentColors": uiconfig.commentColors, "op": op, "showDevInfos": userSettings.get(UserSettings.PREF_DEVINFOS) });
  265. const el = document.getElementById(this._eleId || gui.getParamPanelEleId());
  266. if (el) el.innerHTML = html;
  267. else return;
  268. this._paramsListener.init({ "op": op, "element": el });
  269. perfHtml.finish();
  270. this.updateUiAttribs();
  271. for (let i = 0; i < this._portsIn.length; i++)
  272. {
  273. this._checkPortTypes(this._portsIn[i]);
  274. if (this._portsIn[i].uiAttribs.display && this._portsIn[i].uiAttribs.display == "file")
  275. {
  276. let shortName = String(this._portsIn[i].get() || "Open Filemanager");
  277. if (shortName.indexOf("/") > -1) shortName = shortName.substr(shortName.lastIndexOf("/") + 1);
  278. if (op.getSubPatch())
  279. {
  280. const subouterOp = gui.corePatch().getSubPatchOuterOp(op.getSubPatch());
  281. if (subouterOp)
  282. {
  283. const subOuterName = subouterOp.objName;
  284. if (!namespace.isPatchOp(subOuterName) &&
  285. this._portsIn[i].get() &&
  286. namespace.isCoreOp(subOuterName) &&
  287. namespace.isExtensionOp(subOuterName) &&
  288. String(this._portsIn[i].get()).startsWith("/assets/") &&
  289. !this._portsIn[i].isLinked())
  290. this._portsIn[i].op.setUiError("nonpatchopassets", "This Operator uses assets from a patch, this file will probably not be found when exporting the patch or using in standalone etc.!", 1);
  291. }
  292. }
  293. let eleOpen = ele.byId("portOpenAsset_" + i);
  294. let srcEle = ele.byId("portFilename_" + i + "_src");
  295. let buttonOpensFilemanager = true;
  296. if (srcEle)
  297. {
  298. let src = "";
  299. let fn = this._portsIn[i].get() || "";
  300. if (fn == "" || fn == 0)src = "";
  301. else if (!fn.startsWith("/")) src = "relative";
  302. if (fn.startsWith("/")) src = "abs";
  303. if (fn.startsWith("./")) src = "current dir";
  304. if (fn.startsWith("file:")) src = "file";
  305. if (fn.startsWith("data:")) src = "dataUrl";
  306. let openSrc = "";
  307. let openOnClick = "";
  308. if (fn.startsWith("http://") || fn.startsWith("https://"))
  309. {
  310. buttonOpensFilemanager = false;
  311. const parts = fn.split("/");
  312. if (parts && parts.length > 1) src = "ext: " + parts[2];
  313. openSrc = fn;
  314. }
  315. if ((fn.startsWith("file:") || fn.startsWith("/") || fn.startsWith("./")) && platform.isElectron())
  316. {
  317. openOnClick = "CABLES.CMD.ELECTRON.openFileManager('" + fn + "')";
  318. }
  319. if (fn.startsWith("/assets/" + gui.project()._id)) src = "this patch";
  320. if (fn.startsWith("/assets/") && !fn.startsWith("/assets/" + gui.project()._id))
  321. {
  322. const parts = fn.split("/");
  323. if (parts && parts.length > 1)
  324. {
  325. src = "<a target=\"_blank\" class=\"link\" href=\"" + platform.getCablesUrl() + "/edit/" + parts[2] + "\">other patch</a>";
  326. src += " <a target=\"_blank\" class=\"button-small\" id=\"copyToPatch" + i + "\">copy</a>";
  327. }
  328. }
  329. if (fn.startsWith("/assets/"))
  330. openSrc = platform.getCablesUrl() + "/asset/patches/?filename=" + fn;
  331. if (fn.startsWith("/assets/library/")) src = "lib";
  332. if (src != "") src = "[ " + src + " ]";
  333. if (eleOpen)
  334. {
  335. if (openOnClick) eleOpen.setAttribute("onclick", openOnClick);
  336. if (openSrc) eleOpen.setAttribute("href", openSrc);
  337. if (!openOnClick && !openSrc) eleOpen.remove();
  338. }
  339. srcEle.innerHTML = src;
  340. ele.clickable(ele.byId("copyToPatch" + i), () =>
  341. {
  342. gui.getFileManager(null, true).copyFileToPatch(fn);
  343. });
  344. }
  345. const filenameButton = ele.byId("portFilename_" + i);
  346. if (filenameButton)
  347. {
  348. filenameButton.innerHTML = "<span class=\"button-small tt\" data-tt=\"" + this._portsIn[i].get() + "\" style=\"text-transform:none;\"><span style=\"pointer-events:none;\" class=\"icon icon-file\"></span>" + shortName + "</span>";
  349. filenameButton.addEventListener("pointerdown", () =>
  350. {
  351. if (buttonOpensFilemanager)
  352. {
  353. // open filemananger
  354. ele.byId("portFilename_" + i + "_src").innerHTML = "";
  355. ele.byId("fileInputContainer_" + i).classList.remove("hidden");
  356. filenameButton.classList.add("hidden");
  357. CABLES.platform.showFileSelect(".portFileVal_" + i, this._portsIn[i].uiAttribs.filter || null, op.id, "portFileVal_" + i + "_preview");
  358. }
  359. else
  360. {
  361. // edit url
  362. ele.byId("portFilenameButton_" + i).classList.toggle("hidden");
  363. ele.byId("fileInputContainer_" + i).classList.toggle("hidden");
  364. }
  365. });
  366. }
  367. else
  368. {
  369. // no filenamebutton, probably because port is linked...
  370. }
  371. }
  372. const portIn = this._portsIn[i];
  373. ele.on(document.getElementById("portLineTitle_in_" + i), "pointerdown", () => { this._portLineDragPort = portIn; }, { "passive": false });
  374. }
  375. for (let ipo = 0; ipo < this._portsOut.length; ipo++)
  376. {
  377. this._checkPortTypes(this._portsOut[ipo]);
  378. this._showOpParamsCbPortDelete(ipo, op);
  379. (function (index)
  380. {
  381. const elem = ele.byId("portTitle_out_" + index);
  382. if (elem)elem.addEventListener("click", (_e) =>
  383. {
  384. const p = this._portsOut[index];
  385. if (!p.uiAttribs.hidePort)
  386. gui.opSelect().show({ "x": p.parent.uiAttribs.translate.x + index * (gluiconfig.portWidth + gluiconfig.portPadding), "y": p.op.uiAttribs.translate.y + 50 }, op, p);
  387. }, { "passive": false });
  388. else this._log.warn("ele not found: portTitle_out_" + index);
  389. }.bind(this)(ipo));
  390. const portOut = this._portsOut[ipo];
  391. ele.on(document.getElementById("portLineTitle_out_" + ipo), "pointerdown", () => { this._portLineDragPort = portOut; }, { "passive": false });
  392. }
  393. this._startPortLineDragListeners();
  394. ele.clickable(ele.byId("parampanel_manage_op"), () => { CABLES.CMD.OP.manageOp(op.opId); });
  395. ele.clickable(ele.byId("parampanel_edit_op"), CABLES.CMD.OP.editOp);
  396. ele.clickable(ele.byId("watchOpSerialized"), CABLES.CMD.DEBUG.watchOpSerialized);
  397. ele.clickable(ele.byId("watchOpUiAttribs"), CABLES.CMD.DEBUG.watchOpUiAttribs);
  398. ele.clickable(ele.byId("watchOpDocsJson"), CABLES.CMD.DEBUG.watchOpDocsJson);
  399. ele.forEachClass("portCopyClipboard", (ell) =>
  400. {
  401. ele.on(ell, "click", (e, target) =>
  402. {
  403. if (!navigator.clipboard) return;
  404. const cop = gui.corePatch().getOpById(target.dataset.opid);
  405. const port = cop.getPortByName(target.dataset.portname);
  406. navigator.clipboard
  407. .writeText(String(port.get()))
  408. .then(() =>
  409. {
  410. notify("Copied value to clipboard");
  411. })
  412. .catch((err) =>
  413. {
  414. this._log.warn("copy to clipboard failed", err);
  415. });
  416. e.preventDefault();
  417. }, { "passive": false });
  418. });
  419. if (gui.serverOps.opIdsChangedOnServer[op.opId])
  420. {
  421. ele.clickable(ele.byId("parampanel_loadchangedop_" + op.opId), () =>
  422. {
  423. gui.serverOps.execute(op.opId, () =>
  424. {
  425. delete gui.serverOps.opIdsChangedOnServer[op.opId];
  426. this.refresh();
  427. });
  428. });
  429. }
  430. perf.finish();
  431. }
  432. updateUiErrors()
  433. {
  434. if (!this._currentOp) return;
  435. const el = document.getElementById("op_params_uierrors");
  436. if (!this._currentOp.uiAttribs.uierrors || this._currentOp.uiAttribs.uierrors.length == 0)
  437. {
  438. if (el)el.innerHTML = "";
  439. return;
  440. }
  441. // else
  442. // if (document.getElementsByClassName("warning-error") != this._currentOp.uiAttribs.uierrors.length)
  443. // {
  444. // if (el) el.innerHTML = "";
  445. // }
  446. if (!el)
  447. {
  448. this._log.warn("no uiErrors html ele?!");
  449. }
  450. else
  451. {
  452. for (let i = 0; i < this._currentOp.uiAttribs.uierrors.length; i++)
  453. {
  454. const err = this._currentOp.uiAttribs.uierrors[i];
  455. let div = document.getElementById("uierror_" + err.id);
  456. let str = "";
  457. if (err.level == 0) str += "<b>Hint: </b>";
  458. if (err.level == 1) str += "<b>Warning: </b>";
  459. if (err.level == 2) str += "<b>Error: </b>";
  460. if (err.level == 3) str += "<b>Not working: </b>";
  461. str += err.txt;
  462. if (err.options)
  463. {
  464. if (err.options.button)
  465. str += "&nbsp;<a class=\"button-small\" id=\"err_button_" + err.id + "\">" + err.options.button + "</a>";
  466. }
  467. if (!div)
  468. {
  469. div = document.createElement("div");
  470. div.id = "uierror_" + err.id;
  471. div.classList.add("warning-error");
  472. if (utils.isNumeric(err.level))
  473. div.classList.add("warning-error-level" + err.level);
  474. else
  475. {
  476. console.error("err level not numeric", err.level);
  477. console.log((new Error().stack));
  478. }
  479. el.appendChild(div);
  480. }
  481. div.innerHTML = str;
  482. }
  483. gui.patchView.checkPatchErrors();
  484. }
  485. for (let i = 0; i < this._currentOp.uiAttribs.uierrors.length; i++)
  486. {
  487. if (this._currentOp.uiAttribs.uierrors[i].options.button)
  488. ele.clickable(ele.byId("err_button_" + this._currentOp.uiAttribs.uierrors[i].id), () =>
  489. {
  490. if (this._currentOp.uiAttribs.uierrors[i].options.buttonCb) this._currentOp.uiAttribs.uierrors[i].options.buttonCb();
  491. else this._log.log("uierror button has no callback");
  492. });
  493. }
  494. }
  495. updateUiAttribs()
  496. {
  497. if (gui.patchView.isPasting) return;
  498. if (!this._currentOp) return;
  499. this._uiAttrFpsLast = this._uiAttrFpsLast || performance.now();
  500. this._uiAttrFpsCount++;
  501. if (performance.now() - this._uiAttrFpsLast > 1000)
  502. {
  503. this._uiAttrFpsLast = performance.now();
  504. if (this._uiAttrFpsCount >= 10) this._log.log("many ui attr updates! ", this._uiAttrFpsCount, this._currentOp.name);
  505. this._uiAttrFpsCount = 0;
  506. }
  507. const perf = gui.uiProfiler.start("[opparampanel] updateUiAttribs");
  508. let el = null;
  509. // el = document.getElementById("options_warning");
  510. // if (el)
  511. // {
  512. // if (!this._currentOp.uiAttribs.warning || this._currentOp.uiAttribs.warning.length === 0) el.style.display = "none";
  513. // else
  514. // {
  515. // el.style.display = "block";
  516. // if (el) el.innerHTML = this._currentOp.uiAttribs.warning;
  517. // }
  518. // }
  519. // el = document.getElementById("options_hint");
  520. // if (el)
  521. // {
  522. // if (!this._currentOp.uiAttribs.hint || this._currentOp.uiAttribs.hint.length === 0) el.style.display = "none";
  523. // else
  524. // {
  525. // el.style.display = "block";
  526. // if (el) el.innerHTML = this._currentOp.uiAttribs.hint;
  527. // }
  528. // }
  529. // el = document.getElementById("options_error");
  530. // if (el)
  531. // {
  532. // if (!this._currentOp.uiAttribs.error || this._currentOp.uiAttribs.error.length === 0) el.style.display = "none";
  533. // else
  534. // {
  535. // el.style.display = "block";
  536. // if (el) el.innerHTML = this._currentOp.uiAttribs.error;
  537. // }
  538. // }
  539. // el = document.getElementById("options_info");
  540. // if (el)
  541. // {
  542. // if (!this._currentOp.uiAttribs.info) el.style.display = "none";
  543. // else
  544. // {
  545. // el.style.display = "block";
  546. // el.innerHTML = "<div class=\"panelhead\">info</div><div class=\"panel\">" + this._currentOp.uiAttribs.info + "</div>";
  547. // }
  548. // }
  549. this.updateUiErrors();
  550. perf.finish();
  551. }
  552. /**
  553. * @param {number} index
  554. * @param {Op<any>} op
  555. */
  556. _showOpParamsCbPortDelete(index, op)
  557. {
  558. const el = ele.byId("portdelete_out_" + index);
  559. if (el)el.addEventListener("click", (e) =>
  560. {
  561. this._portsOut[index].removeLinks();
  562. this.show(op);
  563. });
  564. }
  565. /**
  566. * @param {string} t
  567. */
  568. setCurrentOpTags(t)
  569. {
  570. if (this._currentOp)
  571. {
  572. console.log(t.split(","));
  573. this._currentOp.tags = t.split(",");
  574. }
  575. else
  576. {
  577. this._log.warn("no current op tags");
  578. }
  579. }
  580. setCurrentOpComment(v)
  581. {
  582. if (this._currentOp)
  583. {
  584. this._currentOp.uiAttr({ "comment": v });
  585. if (v.length == 0) this._currentOp.uiAttr({ "comment": null });
  586. this._currentOp.patch.emitEvent("commentChanged");
  587. // gui.setStateUnsaved({ "op": this._currentOp });
  588. gui.savedState.setUnSaved("op comment", this._currentOp.uiAttribs.subPatch);
  589. }
  590. else
  591. {
  592. this._log.warn("no current op comment");
  593. }
  594. }
  595. /**
  596. * @param {string} t
  597. */
  598. setCurrentOpTitle(t)
  599. {
  600. if (this._currentOp) this._currentOp.setTitle(t);
  601. if (this._currentOp && this._currentOp.storage && this._currentOp.storage.subPatchVer)
  602. this._currentOp.patch.emitEvent("subpatchesChanged");
  603. }
  604. /**
  605. * @param {Op<any>} op
  606. */
  607. isCurrentOp(op)
  608. {
  609. return this._currentOp == op;
  610. }
  611. /**
  612. * @param {string} opid
  613. */
  614. isCurrentOpId(opid)
  615. {
  616. if (!this._currentOp) return false;
  617. return this._currentOp.id == opid;
  618. }
  619. // OLD SUBPATCH LIST!!!!!! REMOVE
  620. // subPatchContextMenu(el)
  621. // {
  622. // const outer = gui.patchView.getSubPatchOuterOp(el.dataset.id);
  623. // const items = [];
  624. // if (outer && outer.storage && outer.storage.blueprint)
  625. // {
  626. // items.push({
  627. // "title": "Goto Blueprint Op",
  628. // "func": function ()
  629. // {
  630. // // gui.patchView.focusSubpatchOp(el.dataset.id);
  631. // }
  632. // });
  633. // items.push({
  634. // "title": "Update Blueprint",
  635. // "func": function ()
  636. // {
  637. // const bp = gui.patchView.getBlueprintOpFromBlueprintSubpatchId(el.dataset.id);
  638. // if (bp) gui.patchView.updateBlueprints([bp]);
  639. // }
  640. // });
  641. // items.push({
  642. // "title": "Open Patch",
  643. // "iconClass": "icon icon-external",
  644. // "func": function ()
  645. // {
  646. // const url = platform.getCablesUrl() + "/edit/" + outer.storage.blueprint.patchId;
  647. // window.open(url, "_blank");
  648. // }
  649. // });
  650. // }
  651. // else
  652. // {
  653. // items.push({
  654. // "title": "Rename",
  655. // "func": function ()
  656. // {
  657. // gui.patchView.focusSubpatchOp(el.dataset.id);
  658. // CABLES.CMD.PATCH.setOpTitle();
  659. // }
  660. // });
  661. // items.push({
  662. // "title": "Goto Subpatch Op",
  663. // "func": function ()
  664. // {
  665. // gui.patchView.focusSubpatchOp(el.dataset.id);
  666. // }
  667. // });
  668. // if (el.dataset.subpatchver == "2" && el.dataset.blueprintver != 2)
  669. // items.push({
  670. // "title": "Create op from subpatch",
  671. // "func": function ()
  672. // {
  673. // gui.serverOps.createBlueprint2Op(el.dataset.id);
  674. // // gui.patchView.focusSubpatchOp(el.dataset.id);
  675. // }
  676. // });
  677. // if (el.dataset.blueprintver == 2)
  678. // {
  679. // items.push({
  680. // "title": "Save Blueprint Op",
  681. // "func": function ()
  682. // {
  683. // const op = gui.patchView.getSubPatchOuterOp(el.dataset.id);
  684. // gui.serverOps.updateSubPatchOpAttachment(op, { "oldSubId": el.dataset.id });
  685. // // gui.patchView.focusSubpatchOp(el.dataset.id);
  686. // }
  687. // });
  688. // }
  689. // }
  690. // contextMenu.show({ "items": items }, el);
  691. // }
  692. /**
  693. * @param {HTMLElement} el
  694. */
  695. opContextMenu(el)
  696. {
  697. const items = [];
  698. // const opname = this._currentOp.objName;
  699. const opid = this._currentOp.id;
  700. items.push({
  701. "title": "Set title",
  702. "func": CABLES.CMD.PATCH.setOpTitle
  703. });
  704. items.push({
  705. "title": "Set default values",
  706. "func": function ()
  707. {
  708. gui.patchView.resetOpValues(opid);
  709. }
  710. });
  711. items.push({
  712. "title": "Bookmark",
  713. "func": function ()
  714. {
  715. gui.bookmarks.add();
  716. }
  717. });
  718. items.push({
  719. "title": "Manage Op Code",
  720. "func": function ()
  721. {
  722. CmdOps.manageOp();
  723. }
  724. });
  725. items.push({
  726. "title": "Clone Op",
  727. "func": function ()
  728. {
  729. CmdOps.cloneSelectedOp();
  730. }
  731. });
  732. contextMenu.show({ "items": items }, el);
  733. }
  734. getCurrentOp()
  735. {
  736. return this._currentOp;
  737. }
  738. hidePorts()
  739. {
  740. // console.log("arrrrrr", arr);
  741. // for (let i = 0; i < arr.length; i++)
  742. // {
  743. // const p = this.op.getPort(arr[i]);
  744. // p.setUiAttribs({ "hidePort": true });
  745. // }
  746. }
  747. }
  748. export default OpParampanel;