Skip to content

canvas_menu

chrisgoringe edited this page Oct 3, 2023 · 1 revision

Adding to the canvas menu

The canvas menu is the one you get if you right-click on the background - to add nodes, etc.. You can add to it:

    async setup() {
        const original_getCanvasMenuOptions = app.canvas.getCanvasMenuOptions;    // save the original function
        app.canvas.getCanvasMenuOptions = function () {
            const options = original_getCanvasMenuOptions.apply(this, arguments); // call the original function
            options.push(null);                          // divider
            options.push({
                content: `Menu item text`,
                disabled: false,                         // or a function determining whether to disable
                callback: () => {
                                       // action when clicked goes in here
                }
            });
            return options;                              // return the menu options with your custom ones added
        }
    }
Clone this wiki locally