async function generateMenuJSON() {
try {
const delimiter = "_BTT_SEQ_PASTE_DELIMITER_";
const stackVariable = "sequentialPasteStack";
const orderVariable = "pasteOrderMode";
const enterModeVariable = "pasteAndEnterMode";
const ignoreModeVariable = "ignoreCopyMode"; // New variable
const newLineModeVariable = "newLineDetection";
const templateItemUUIDString = "62373239-24D8-429D-8292-1EA154CEC86E";
const fifoIconSymbol = "sfsymbol::arrow.up.arrow.down";
const lifoIconSymbol = "sfsymbol::square.stack.3d.up.fill";
const enterModeActiveSymbol = "sfsymbol::document.badge.plus.fill";
const enterModeDeactiveSymbol = "sfsymbol::moonphase.new.moon";
const undoLastPasteIcon = "sfsymbol::arrow.uturn.backward.circle.fill";
const ignoreOnIcon = "sfsymbol::notequal.square.fill"; // Icon for when ignoring is ON
const ignoreOffIcon = "sfsymbol::doc.on.doc"; // Icon for when ignoring is OFF (capturing)
const pasteAllButtonIcon = "sfsymbol::scissors.badge.ellipsis";
const newLineOnIcon = "sfsymbol::lineweight"; // Icon for when ignoring is ON
const newLineOffIcon = "sfsymbol::plus.square"; // Icon for when ignoring is OFF (capturing)
// 1. Get the state for both toggles.
const currentOrder = await get_string_variable({ variableName: orderVariable }) || "FIFO";
const enterMode = await get_string_variable({ variableName: enterModeVariable }) || "off";
const ignoreMode = await get_string_variable({ variableName: ignoreModeVariable }) || "off";
const newLineMode = await get_string_variable({ variableName: newLineModeVariable }) || "off";
// 2. Create the toggle buttons.
const orderToggleButton = {
"templateItemUUID": templateItemUUIDString,
"title": { "text": ``, "size": 2, "color": "#A9A9A9" },
"backgroundColor": "30,30,30,255",
"BTTMenuElementTooltip" : "MyToolTip",
"action": {
"named": "togglePasteOrder"
},
"icon": currentOrder === "FIFO" ? fifoIconSymbol : lifoIconSymbol
};
const enterToggleButton = {
"templateItemUUID": templateItemUUIDString,
"title": { "text": ``, "size": 10, "color": "#A9A9A9" },
"backgroundColor": "30,30,30,255",
"action": {
"named": "toggleEnterPaste"
},
"icon": enterMode === "off" ? enterModeDeactiveSymbol : enterModeActiveSymbol
};
const undoPasteButton = {
"templateItemUUID": templateItemUUIDString,
"title": { "text": ``, "size": 2, "color": "#A9A9A9" },
"backgroundColor": "30,30,30,255",
"action": {
"named": "undoLastPaste"
},
"icon": undoLastPasteIcon
};
const ignoreCopyButton = {
"templateItemUUID": templateItemUUIDString,
"title": { "text": ``, "size": 10, "color": "#A9A9A9" },
"action": { "named": "toggleIgnoreCopy" }, "icon": ignoreMode === "on" ? ignoreOnIcon : ignoreOffIcon
};
const pasteAllButton = {
"templateItemUUID": templateItemUUIDString,
"title": { "text": ``, "size": 10, "color": "#A9A9A9" },
"action": { "named": "pasteAll" }, "icon": pasteAllButtonIcon
};
const newLineDetection = {
"templateItemUUID": templateItemUUIDString,
"title": { "text": ``, "size": 10, "color": "#A9A9A9" },
"action": { "named": "toggleNewLineDetection" }, "icon": newLineMode === "on" ? newLineOnIcon : newLineOffIcon
};
// This array holds our control buttons.
const controlButtons = [orderToggleButton, enterToggleButton, undoPasteButton, ignoreCopyButton, newLineDetection, pasteAllButton];
const stackContent = await get_string_variable({ variableName: stackVariable });
if (!stackContent || stackContent.trim() === "") {
await set_persistent_string_variable({ variableName: "pasteQueueStatus", to: "empty" });
return JSON.stringify(controlButtons); // Show controls even if empty.
}
const itemsArray = stackContent.split(delimiter).filter(line => line.trim() !== '');
if (itemsArray.length <= 1) {
await set_persistent_string_variable({ variableName: "pasteQueueStatus", to: "empty" });
} else {
await set_persistent_string_variable({ variableName: "pasteQueueStatus", to: "not_empty" });
}
if (itemsArray.length === 0) {
return JSON.stringify(controlButtons);
}
const orderedArray = currentOrder === "FIFO" ? itemsArray.reverse() : itemsArray;
const pasteItems = orderedArray.map((line,index) => {
const displayLine = line.length > 30 ? line.substring(0, 30) + '...' : line;
if(index === 0){
return {
"templateItemUUID": "FBA5D74D-5C46-453D-BF8B-ED836E659AD9",
"title": displayLine,
"backgroundColor": "50,50,50,255"
};
} else {
return {
"templateItemUUID": "F7582E57-F563-466E-8E3A-60B2D1B9A2FF",
"title": { "text": displayLine, "size": 14, "color": "#FFFFFF" },
"backgroundColor": "50,50,50,255"
};
}
});
// Combine control buttons with the paste items for the final menu.
const finalMenu = [...controlButtons, ...pasteItems];
return JSON.stringify(finalMenu);
} catch (error) {
console.error("Error generating menu JSON:", error);
await set_persistent_string_variable({ variableName: "pasteQueueStatus", to: "empty" });
return JSON.stringify([]);
}
}
This is currently not working. When adding the text, it shows the Menu item without the title
@Andreas_Hegenberg Any updates about this?? Title or the text stopped showing