Skip to content

Commit

Permalink
Show convert to widget option slot context menu (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Feb 12, 2025
1 parent a861a07 commit 8bb785c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
"@comfyorg/comfyui-electron-types": "^0.4.16",
"@comfyorg/litegraph": "^0.8.77",
"@comfyorg/litegraph": "^0.8.78",
"@primevue/forms": "^4.2.5",
"@primevue/themes": "^4.2.5",
"@sentry/vue": "^8.48.0",
Expand Down
32 changes: 25 additions & 7 deletions src/extensions/core/widgetInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type {
IWidget,
LiteGraphCanvasEvent
} from '@comfyorg/litegraph'
import type { IFoundSlot } from '@comfyorg/litegraph'

import { useNodeDefStore } from '@/stores/nodeDefStore'
import { useSettingStore } from '@/stores/settingStore'
import type { InputSpec } from '@/types/apiTypes'

import { app } from '../../scripts/app'
Expand Down Expand Up @@ -718,17 +720,16 @@ export function mergeIfValid(
return { customConfig }
}

let useConversionSubmenusSetting
app.registerExtension({
name: 'Comfy.WidgetInputs',
init() {
useConversionSubmenusSetting = app.ui.settings.addSetting({
settings: [
{
id: 'Comfy.NodeInputConversionSubmenus',
name: 'In the node context menu, place the entries that convert between input/widget in sub-menus.',
type: 'boolean',
defaultValue: true
})
},
}
],
setup() {
app.canvas.getWidgetLinkType = function (widget, node) {
const nodeDefStore = useNodeDefStore()
Expand Down Expand Up @@ -777,6 +778,23 @@ app.registerExtension({
convertToInput(this, widget, config)
return true
}

nodeType.prototype.getExtraSlotMenuOptions = function (
this: LGraphNode,
slot: IFoundSlot
) {
if (!slot.input || !slot.input.widget) return []

const widget = this.widgets.find((w) => w.name === slot.input.widget.name)
if (!widget) return []
return [
{
content: `Convert to widget`,
callback: () => convertToWidget(this, widget)
}
]
}

nodeType.prototype.getExtraMenuOptions = function (_, options) {
const r = origGetExtraMenuOptions
? origGetExtraMenuOptions.apply(this, arguments)
Expand Down Expand Up @@ -832,7 +850,7 @@ app.registerExtension({

//Convert.. main menu
if (toInput.length) {
if (useConversionSubmenusSetting.value) {
if (useSettingStore().get('Comfy.NodeInputConversionSubmenus')) {
options.push({
content: 'Convert Widget to Input',
submenu: {
Expand All @@ -844,7 +862,7 @@ app.registerExtension({
}
}
if (toWidget.length) {
if (useConversionSubmenusSetting.value) {
if (useSettingStore().get('Comfy.NodeInputConversionSubmenus')) {
options.push({
content: 'Convert Input to Widget',
submenu: {
Expand Down

0 comments on commit 8bb785c

Please sign in to comment.