feat: add rename and move prompt functionality to context menu and API

This commit is contained in:
THE_BEAST\me
2026-03-07 12:48:44 -05:00
parent e20f6523d9
commit 10cb9d2bb0
3 changed files with 84 additions and 1 deletions
+1 -1
View File
@@ -292,7 +292,7 @@ Preference settings can be found in ComfyUI Settings → Prompt Manager
### version 1.17.5
- **Browser Context Menu Enhancements**
- Added "Delete Prompt" option to prompt right-click menu in the thumbnail browser
- Added "Delete Prompt", "Rename and Move Prompt" option to prompt right-click menu in the thumbnail browser
- Added "Delete Category", "Rename Category" options to category right-click menu
- Added "+" button at the end of the category list to create new categories directly from the browser
- All browser operations preserve unsaved prompt state (text, loras, trigger words are not reset)
+38
View File
@@ -5192,6 +5192,44 @@ function showThumbnailContextMenu(event, node, category, promptName, onUpdate) {
nsfwItem.style.color = isNSFW ? '#f66' : '#ccc';
menu.appendChild(nsfwItem);
// Rename / Move Prompt
const renameDivider = document.createElement("div");
renameDivider.style.cssText = `height: 1px; background: #444; margin: 4px 0;`;
menu.appendChild(renameDivider);
menu.appendChild(createMenuItem("✏️ Rename / Move", async () => {
const allCategories = Object.keys(node.prompts).filter(c => c !== "__meta__").sort((a, b) => a.localeCompare(b));
const result = await showPromptWithCategory(
"Rename / Move Prompt",
"Prompt name:",
promptName,
allCategories,
category,
promptData?.nsfw || false
);
if (result && result.name && result.name.trim()) {
const newName = result.name.trim();
const newCat = result.category;
if (newName === promptName && newCat === category) return;
try {
const resp = await fetch("/prompt-manager-advanced/rename-prompt", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ category: category, old_name: promptName, new_name: newName, new_category: newCat })
});
const data = await resp.json();
if (data.success) {
node.prompts = data.prompts;
onUpdate();
} else {
await showInfo("Error", data.error);
}
} catch (err) {
console.error("[PromptManagerAdvanced] Error renaming prompt:", err);
}
}
}));
// Delete Prompt
const deleteDivider = document.createElement("div");
deleteDivider.style.cssText = `height: 1px; background: #444; margin: 4px 0;`;
+45
View File
@@ -1226,6 +1226,51 @@ async def delete_prompt_advanced(request):
return server.web.json_response({"success": False, "error": str(e)}, status=500)
@server.PromptServer.instance.routes.post("/prompt-manager-advanced/rename-prompt")
async def rename_prompt_advanced(request):
"""API endpoint to rename/move a prompt, optionally to a different category"""
try:
data = await request.json()
category = data.get("category", "").strip()
old_name = data.get("old_name", "").strip()
new_name = data.get("new_name", "").strip()
new_category = data.get("new_category", "").strip() or category
if not category or not old_name or not new_name:
return server.web.json_response({"success": False, "error": "Category, old name, and new name are required"})
prompts = PromptManagerAdvanced.load_prompts()
if category not in prompts or old_name not in prompts[category]:
return server.web.json_response({"success": False, "error": "Prompt not found"})
if new_category not in prompts:
return server.web.json_response({"success": False, "error": f"Category '{new_category}' not found"})
# Check for name conflicts in the target category
# If same category, exclude the old name from conflict check
target_prompts = prompts[new_category]
if category == new_category:
existing_lower = {k.lower(): k for k in target_prompts.keys() if k != "__meta__" and k.lower() != old_name.lower()}
else:
existing_lower = {k.lower(): k for k in target_prompts.keys() if k != "__meta__"}
if new_name.lower() in existing_lower:
return server.web.json_response({
"success": False,
"error": f"A prompt named '{existing_lower[new_name.lower()]}' already exists in '{new_category}'"
})
prompts[new_category][new_name] = prompts[category][old_name]
del prompts[category][old_name]
PromptManagerAdvanced.save_prompts(prompts)
return server.web.json_response({"success": True, "prompts": prompts, "new_name": new_name, "new_category": new_category})
except Exception as e:
print(f"[PromptManagerAdvanced] Error in rename_prompt API: {e}")
return server.web.json_response({"success": False, "error": str(e)}, status=500)
@server.PromptServer.instance.routes.post("/prompt-manager-advanced/check-loras")
async def check_loras_advanced(request):
"""API endpoint to check which LoRAs are available in the system"""