Hey, in the simple example script below, if I check the state of a menu command before and after opening/closing a simple modal, the values are different (true before and false after).
The command in question is the ‘Undo’ command and it is ‘enabled’ before the modal execution according the menu command info provided by menuBarInfo
…
I’ve included the console dump attached below too… Any ideas?
I forgot to me mention, this only happens for some commands, and the command state is true when checked from the debug console after the palette is closed…
Thanks in advance for your help!
const { core } = require("photoshop");
const { entrypoints } = require("uxp");
console.log("loading plugin");
entrypoints.setup({
commands: {
launchPalette: () => launchPalette(),
},
});
async function launchPalette() {
console.log("launching palette");
// check command state before modal
const before = await core.getMenuCommandState({ commandID: 101 });
console.log("command state (before modal):", before);
// open modal
const result = await openProgrammaticDialog();
console.log("modal result:", result);
// check command state after modal
const after = await core.getMenuCommandState({ commandID: 101 });
console.log("command state (after modal):", after);
}
// programmatic dialog
const openProgrammaticDialog = async () => {
const theDialog = document.createElement("dialog");
const doButton = document.createElement("sp-button");
const doNotButton = document.createElement("sp-button");
doButton.textContent = "Do!";
doButton.setAttribute("variant", "cta");
doNotButton.textContent = "Do Not.";
doNotButton.setAttribute("variant", "secondary");
doButton.onclick = () => {
theDialog.close("ok");
};
doNotButton.onclick = () => {
theDialog.close("reasonCanceled");
};
theDialog.appendChild(doNotButton);
theDialog.appendChild(doButton);
document.body.appendChild(theDialog);
const r = await theDialog.uxpShowModal({ title: "Programmatic Dialog" });
theDialog.remove();
return r;
};
Console Log Dump:
main.js:13 launching palette
main.js:17 command state (before modal): [true]
main.js:21 modal result: ok
main.js:25 command state (after modal): [false]