Skip to content

Commit a832141

Browse files
AustinMrozgithub-actions
andauthored
Support renaming widgets (#6752)
![widget-rename_00002](https://github.com/user-attachments/assets/65205d3e-2c03-480d-916e-0dae89ddbdd9) Widget labels are saved by serializing the value on inputs. This requires minor changes to ensure widgets inputs are serialized when required. Currently only exposed by right clicking on widgets directly. Should probably be added to the subgraph config panel in the future. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6752-Support-renaming-widgets-2b06d73d36508196bff2e511c6e7b89b) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <github-actions@github.com>
1 parent d1f0211 commit a832141

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed
1.36 KB
Loading
1.29 KB
Loading
1.36 KB
Loading

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,9 @@ export class LGraphNode
835835
for (const w of this.widgets) {
836836
if (!w) continue
837837

838+
const input = this.inputs.find((i) => i.widget?.name === w.name)
839+
if (input?.label) w.label = input.label
840+
838841
if (
839842
w.options?.property &&
840843
this.properties[w.options.property] != undefined

src/locales/en/main.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@
402402
"Copy Image": "Copy Image",
403403
"Save Image": "Save Image",
404404
"Rename": "Rename",
405+
"RenameWidget": "Rename Widget",
405406
"Copy": "Copy",
406407
"Duplicate": "Duplicate",
407408
"Paste": "Paste",

src/services/litegraphService.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { useToastStore } from '@/platform/updates/common/toastStore'
3333
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
3434
import type { NodeId } from '@/platform/workflow/validation/schemas/workflowSchema'
3535
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
36+
import { useDialogService } from '@/services/dialogService'
3637
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
3738
import type {
3839
ComfyNodeDef as ComfyNodeDefV2,
@@ -822,14 +823,31 @@ export const useLitegraphService = () => {
822823
}
823824
)
824825
}
825-
if (this.graph && !this.graph.isRootGraph) {
826-
const [x, y] = canvas.graph_mouse
827-
const overWidget = this.getWidgetOnPos(x, y, true)
828-
if (overWidget) {
826+
const [x, y] = canvas.graph_mouse
827+
const overWidget = this.getWidgetOnPos(x, y, true)
828+
if (overWidget) {
829+
const input = this.inputs.find(
830+
(inp) => inp.widget?.name === overWidget.name
831+
)
832+
if (input)
833+
options.unshift({
834+
content: `${t('contextMenu.RenameWidget')}: ${overWidget.label ?? overWidget.name}`,
835+
callback: async () => {
836+
const newLabel = await useDialogService().prompt({
837+
title: t('g.rename'),
838+
message: t('g.enterNewName') + ':',
839+
defaultValue: overWidget.label ?? overWidget.name
840+
})
841+
if (!newLabel) return
842+
overWidget.label = newLabel
843+
input.label = newLabel
844+
useCanvasStore().canvas?.setDirty(true)
845+
}
846+
})
847+
if (this.graph && !this.graph.isRootGraph) {
829848
addWidgetPromotionOptions(options, overWidget, this)
830849
}
831850
}
832-
833851
return []
834852
}
835853
}

src/utils/litegraphUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export function compressWidgetInputSlots(graph: ISerialisedGraph) {
204204
}
205205

206206
function matchesLegacyApi(input: ISerialisableNodeInput) {
207-
return !(input.widget && input.link === null)
207+
return !(input.widget && input.link === null && !input.label)
208208
}
209209

210210
/**

0 commit comments

Comments
 (0)