Fix comboboxes that surpass threshold but do not contain any folders. Fixes #143

This commit is contained in:
rgthree
2024-02-20 21:22:27 -05:00
parent 4f94342357
commit c60802bf45
4 changed files with 43 additions and 14 deletions
+7
View File
@@ -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",
+14 -7
View File
@@ -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
})));
+7
View File
@@ -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",
+15 -7
View File
@@ -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
})));