From c60802bf4582ef88e7e8dce9738cae00562a822f Mon Sep 17 00:00:00 2001 From: rgthree Date: Tue, 20 Feb 2024 21:22:27 -0500 Subject: [PATCH] Fix comboboxes that surpass threshold but do not contain any folders. Fixes #143 --- src_web/comfyui/config.ts | 7 +++++++ src_web/comfyui/menu_auto_nest.ts | 21 ++++++++++++++------- web/comfyui/config.js | 7 +++++++ web/comfyui/menu_auto_nest.js | 22 +++++++++++++++------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src_web/comfyui/config.ts b/src_web/comfyui/config.ts index 5526373..b2795d9 100644 --- a/src_web/comfyui/config.ts +++ b/src_web/comfyui/config.ts @@ -77,6 +77,13 @@ const CONFIGURABLE: { features: ConfigurationSchema[] } = { description: "When a large, flat list of values contain sub-directories, auto nest them. (Like, for " + "a large list of checkpoints).", + subconfig: [ + { + key: "features.menu_auto_nest.threshold", + type: ConfigType.NUMBER, + label: "Number of items needed to trigger nesting.", + }, + ], }, { key: "features.show_alerts_for_corrupt_workflows", diff --git a/src_web/comfyui/menu_auto_nest.ts b/src_web/comfyui/menu_auto_nest.ts index a81b2d6..35230e4 100644 --- a/src_web/comfyui/menu_auto_nest.ts +++ b/src_web/comfyui/menu_auto_nest.ts @@ -35,6 +35,7 @@ app.registerExtension({ const [n, v] = logger.infoParts('Skipping context menu auto nesting for incompatible menu.'); console[n]?.(...v); } + console.log('just pass through.') return existingContextMenu.apply(this as any, [...arguments] as any); } @@ -42,6 +43,7 @@ app.registerExtension({ const compatValues = values as unknown as string[]; const originalValues = [...compatValues]; const folders: {[key:string]: string[]} = {}; + const specialOps: string[] = []; const folderless: string[] = []; for (const value of compatValues) { const splitBy = value.indexOf('/') > -1 ? '/' : '\\'; @@ -50,17 +52,19 @@ app.registerExtension({ const key = valueSplit.shift()!; folders[key] = folders[key] || []; folders[key]!.push(valueSplit.join(splitBy)); + } else if (value === 'CHOOSE' || value.startsWith('DISABLE ')) { + specialOps.push(value); } else { folderless.push(value); } } - const oldcallback = options.callback; - options.callback = null; - const newCallback = (item: ContextMenuItem, options: any) => { - oldcallback(originalValues.find(i => i.endsWith(item!.content), options)); - }; const foldersCount = Object.values(folders).length; - if (Object.values(folders).length > 0) { + if (foldersCount > 0) { + const oldcallback = options.callback; + options.callback = null; + const newCallback = (item: ContextMenuItem, options: any) => { + oldcallback(originalValues.find(i => i.endsWith(item!.content), options)); + }; const [n, v] = logger.infoParts(`Nested folders found (${foldersCount}).`); console[n]?.(...v); const newValues: ContextMenuItem[] = []; @@ -77,7 +81,10 @@ app.registerExtension({ } }); } - values = newValues.concat(folderless.map(f => ({ + values = ([] as ContextMenuItem[]).concat(specialOps.map(f => ({ + content: f, + callback: newCallback + })), newValues, folderless.map(f => ({ content: f, callback: newCallback }))); diff --git a/web/comfyui/config.js b/web/comfyui/config.js index f2784bd..800c43b 100644 --- a/web/comfyui/config.js +++ b/web/comfyui/config.js @@ -58,6 +58,13 @@ const CONFIGURABLE = { label: "(Menu) Auto Nest Subdirectories", description: "When a large, flat list of values contain sub-directories, auto nest them. (Like, for " + "a large list of checkpoints).", + subconfig: [ + { + key: "features.menu_auto_nest.threshold", + type: ConfigType.NUMBER, + label: "Number of items needed to trigger nesting.", + }, + ], }, { key: "features.show_alerts_for_corrupt_workflows", diff --git a/web/comfyui/menu_auto_nest.js b/web/comfyui/menu_auto_nest.js index 253aa5d..e7b5c0c 100644 --- a/web/comfyui/menu_auto_nest.js +++ b/web/comfyui/menu_auto_nest.js @@ -18,11 +18,13 @@ app.registerExtension({ const [n, v] = logger.infoParts('Skipping context menu auto nesting for incompatible menu.'); (_a = console[n]) === null || _a === void 0 ? void 0 : _a.call(console, ...v); } + console.log('just pass through.'); return existingContextMenu.apply(this, [...arguments]); } const compatValues = values; const originalValues = [...compatValues]; const folders = {}; + const specialOps = []; const folderless = []; for (const value of compatValues) { const splitBy = value.indexOf('/') > -1 ? '/' : '\\'; @@ -32,17 +34,20 @@ app.registerExtension({ folders[key] = folders[key] || []; folders[key].push(valueSplit.join(splitBy)); } + else if (value === 'CHOOSE' || value.startsWith('DISABLE ')) { + specialOps.push(value); + } else { folderless.push(value); } } - const oldcallback = options.callback; - options.callback = null; - const newCallback = (item, options) => { - oldcallback(originalValues.find(i => i.endsWith(item.content), options)); - }; const foldersCount = Object.values(folders).length; - if (Object.values(folders).length > 0) { + if (foldersCount > 0) { + const oldcallback = options.callback; + options.callback = null; + const newCallback = (item, options) => { + oldcallback(originalValues.find(i => i.endsWith(item.content), options)); + }; const [n, v] = logger.infoParts(`Nested folders found (${foldersCount}).`); (_b = console[n]) === null || _b === void 0 ? void 0 : _b.call(console, ...v); const newValues = []; @@ -59,7 +64,10 @@ app.registerExtension({ } }); } - values = newValues.concat(folderless.map(f => ({ + values = [].concat(specialOps.map(f => ({ + content: f, + callback: newCallback + })), newValues, folderless.map(f => ({ content: f, callback: newCallback })));