From b2722ac4cc31518370e5b9ca6f4314c7e26d931e Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Thu, 15 May 2025 11:10:07 +1000 Subject: [PATCH] Add convert to subgraph command --- src/composables/useCoreCommands.ts | 24 +++++++++++++++++++++++- src/constants/coreKeybindings.ts | 8 ++++++++ src/locales/en/main.json | 4 +++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index 46070dfe98..e15bbdd272 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -17,7 +17,7 @@ import { useDialogService } from '@/services/dialogService' import { useLitegraphService } from '@/services/litegraphService' import { useWorkflowService } from '@/services/workflowService' import type { ComfyCommand } from '@/stores/commandStore' -import { useTitleEditorStore } from '@/stores/graphStore' +import { useCanvasStore, useTitleEditorStore } from '@/stores/graphStore' import { useQueueSettingsStore, useQueueStore } from '@/stores/queueStore' import { useSettingStore } from '@/stores/settingStore' import { useToastStore } from '@/stores/toastStore' @@ -34,6 +34,7 @@ export function useCoreCommands(): ComfyCommand[] { const colorPaletteStore = useColorPaletteStore() const firebaseAuthActions = useFirebaseAuthActions() const toastStore = useToastStore() + const canvasStore = useCanvasStore() const getTracker = () => workflowStore.activeWorkflow?.changeTracker const getSelectedNodes = (): LGraphNode[] => { @@ -673,6 +674,27 @@ export function useCoreCommands(): ComfyCommand[] { function: async () => { await firebaseAuthActions.logout() } + }, + { + id: 'Comfy.Graph.ConvertToSubgraph', + icon: 'pi pi-sitemap', + label: 'Convert Selection to Subgraph', + versionAdded: '1.20.1', + function: () => { + const canvas = canvasStore.getCanvas() + const res = canvas.graph?.convertToSubgraph(canvas.selectedItems) + if (!res) { + toastStore.add({ + severity: 'error', + summary: t('toastMessages.cannotCreateSubgraph'), + detail: t('toastMessages.failedToConvertToSubgraph'), + life: 3000 + }) + return + } + const { node } = res + canvas.select(node) + } } ] diff --git a/src/constants/coreKeybindings.ts b/src/constants/coreKeybindings.ts index 0d59173aa1..34f2cc39e2 100644 --- a/src/constants/coreKeybindings.ts +++ b/src/constants/coreKeybindings.ts @@ -173,5 +173,13 @@ export const CORE_KEYBINDINGS: Keybinding[] = [ key: 'f' }, commandId: 'Workspace.ToggleFocusMode' + }, + { + combo: { + key: 'e', + ctrl: true, + shift: true + }, + commandId: 'Comfy.Graph.ConvertToSubgraph' } ] diff --git a/src/locales/en/main.json b/src/locales/en/main.json index eb5a182fd4..a9219265cc 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -1268,7 +1268,9 @@ "failedToPurchaseCredits": "Failed to purchase credits: {error}", "unauthorizedDomain": "Your domain {domain} is not authorized to use this service. Please contact {email} to add your domain to the whitelist.", "useApiKeyTip": "Tip: Can't access normal login? Use the Comfy API Key option.", - "nothingSelected": "Nothing selected" + "nothingSelected": "Nothing selected", + "cannotCreateSubgraph": "Cannot create subgraph", + "failedToConvertToSubgraph": "Failed to convert items to subgraph" }, "auth": { "apiKey": {