-
Notifications
You must be signed in to change notification settings - Fork 13
ui_2
chrisgoringe edited this page Sep 25, 2023
·
5 revisions
I'm indebted to the author of ttN for writing really clear code that I learned a lot from...
In the init() of your extension (code summarized from ttN)
const getNodeMenuOptions = LGraphCanvas.prototype.getNodeMenuOptions; // store the existing method
LGraphCanvas.prototype.getNodeMenuOptions = function (node) { // replace it
const options = getNodeMenuOptions.apply(this, arguments); // start by calling the stored one
node.setDirtyCanvas(true, true); // force a redraw of (foreground, background)
options.splice(options.length - 1, 0, // splice a new option in at the end
{
content: "My Menu Option", // with a name
callback: () => { myFunction(node); } // and a callback
},
null // (don't think this is needed for splice?)
);
return options; // and return the options
};