From 9845c02811d6c3e9bd4c7a7b3f73d90a254536c2 Mon Sep 17 00:00:00 2001 From: shanexi Date: Tue, 15 Oct 2024 11:41:18 +0800 Subject: [PATCH] Add convert to shellagent widget context menu --- web/shellagent.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/web/shellagent.js b/web/shellagent.js index ee3111b..7c91323 100644 --- a/web/shellagent.js +++ b/web/shellagent.js @@ -48,5 +48,42 @@ app.registerExtension({ ]; } } + + if (nodeData.name.indexOf('ShellAgentPlugin') === -1) { + addMenuHandler(nodeType, function (_, options) { + if (this.widgets) { + let toInput = []; + + for (const w of this.widgets) { + if (["customtext"].indexOf(w.type) > -1) { + toInput.push({ + content: `Input Text -> ${w.name}`, + callback: () => { + alert('Not implemented') + } + }) + } + } + + if (toInput.length) { + options.unshift({ + content: "Convert to ShellAgent", + submenu: { + options: toInput + } + }) + } + } + }) + } }, }); + +function addMenuHandler(nodeType, cb) { + const getOpts = nodeType.prototype.getExtraMenuOptions; + nodeType.prototype.getExtraMenuOptions = function () { + const r = getOpts.apply(this, arguments); + cb.apply(this, arguments); + return r; + }; +} \ No newline at end of file