From 3e94994e9b6fa89ceb8f98bcfd51b001381460bf Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:44:14 -0400 Subject: [PATCH 1/4] add background delete --- src/command/config/file.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/command/config/file.ts b/src/command/config/file.ts index cb4bda2..2b29475 100644 --- a/src/command/config/file.ts +++ b/src/command/config/file.ts @@ -194,12 +194,41 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic }); } }), + // delete ... items.length > 0 ? [ separator(), quickPickItem({ - label: "$(lightbulb) To modify or remove an image, select the row and press enter", + label: "$(trash) Delete a background", ui: item.ui!, - handle: (item: CommandQuickPickItem) => menu(item) + handle: (item: CommandQuickPickItem) => { + const items: CommandQuickPickItem[] = (get(`${item.ui!}Backgrounds`) as string[]) + .filter(unique) + .map(file => quickPickItem({ + label: file.replace(/(\${\w+})/g, "\\$1"), + value: file, + ui: item.ui, + description: `${str.s(glob.count(file), "matching file")}` + })); + + vscode.window.showQuickPick( + items, + { + ...options, + title: t("Delete", item.ui!), + placeHolder: "Files", + canPickMany: true + } + ).then((selected?: CommandQuickPickItem[]) => { + if(selected){ + let promise: Promise = Promise.resolve(); + for(const file of selected) + promise = promise.then(() => remove(item.ui!, file.value!, true)); // append promise to chain + promise = promise + .then(() => selected.length > 0 && notify()) + .then(() => cm({label: '␀', ui: item.ui!})) // reopen menu + } + }); + } }) ] : [] ], From 8b4ebd98261755def44edf482d7d0d40b6778953 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:59:21 -0400 Subject: [PATCH 2/4] swap CQPI with UI --- src/command/config.ts | 56 +++++++++++++++++------------------ src/command/config/align.ts | 42 +++++++++++++------------- src/command/config/blur.ts | 13 ++++---- src/command/config/file.ts | 56 +++++++++++++++++------------------ src/command/config/opacity.ts | 17 +++++------ src/command/config/repeat.ts | 22 +++++++------- src/command/config/size.ts | 28 +++++++++--------- src/command/config/time.ts | 13 ++++---- src/vs/quickpick.ts | 4 +-- 9 files changed, 124 insertions(+), 127 deletions(-) diff --git a/src/command/config.ts b/src/command/config.ts index 201c794..287d861 100644 --- a/src/command/config.ts +++ b/src/command/config.ts @@ -20,7 +20,7 @@ import * as vscode from "vscode"; import { get, UI } from "../vs/vsconfig"; import { pkg } from "../vs/package"; -import { CommandQuickPickItem, quickPickItem, separator, showQuickPick } from "../vs/quickpick"; +import { quickPickItem, separator, showQuickPick } from "../vs/quickpick"; import * as file from "./config/file"; import * as align from "./config/align"; @@ -50,7 +50,7 @@ export const config: vscode.Disposable = vscode.commands.registerCommand("backgr `${get("backgroundSize", "window")} Size` + ` • ` + `${get("backgroundChangeTime", "window")} second${get("backgroundChangeTime", "window") === 1 ? '' : 's'}`, ui: "window", - handle: menu + handle: () => menu("window") }), quickPickItem({ label: "$(multiple-windows) Editor", @@ -62,7 +62,7 @@ export const config: vscode.Disposable = vscode.commands.registerCommand("backgr `${get("backgroundSize", "editor")} Size` + ` • ` + `${get("backgroundChangeTime", "editor")} second${get("backgroundChangeTime", "editor") === 1 ? '' : 's'}`, ui: "editor", - handle: menu + handle: () => menu("editor") }), quickPickItem({ label: "$(layout-sidebar-left) Sidebar", @@ -74,7 +74,7 @@ export const config: vscode.Disposable = vscode.commands.registerCommand("backgr `${get("backgroundSize", "sidebar")} Size` + ` • ` + `${get("backgroundChangeTime", "sidebar")} second${get("backgroundChangeTime", "sidebar") === 1 ? '' : 's'}`, ui: "sidebar", - handle: menu + handle: () => menu("sidebar") }), quickPickItem({ label: "$(layout-panel) Panel", @@ -86,7 +86,7 @@ export const config: vscode.Disposable = vscode.commands.registerCommand("backgr `${get("backgroundSize", "panel")} Size` + ` • ` + `${get("backgroundChangeTime", "panel")} second${get("backgroundChangeTime", "panel") === 1 ? '' : 's'}`, ui: "panel", - handle: menu + handle: () => menu("panel") }), separator(), // extension options @@ -130,61 +130,61 @@ export const title: (s: string, ui?: UI) => string = (s: string, ui?: UI) => ui // menu -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { +export const menu: (ui: UI) => void = (ui: UI) => { showQuickPick([ quickPickItem({ label: "$(file-media) File", - description: `${str.s(get(`${item.ui!}Backgrounds`), "Glob")} (${str.s(glob.count(get(`${item.ui!}Backgrounds`)), "Background")})`, + description: `${str.s(get(`${ui}Backgrounds`), "Glob")} (${str.s(glob.count(get(`${ui}Backgrounds`)), "Background")})`, detail: "Select background image files", - ui: item.ui!, - handle: file.menu + ui, + handle: () => file.menu(ui) }), separator(), quickPickItem({ label: "$(arrow-both) Alignment", - description: `${get("backgroundAlignment", item.ui!)}`, + description: `${get("backgroundAlignment", ui)}`, detail: "Background image alignment", - ui: item.ui!, - handle: align.menu + ui, + handle: () => align.menu(ui) }), quickPickItem({ label: "$(eye) Blur", - description: `${get("backgroundBlur", item.ui!)}`, + description: `${get("backgroundBlur", ui)}`, detail: "Background image blur", - ui: item.ui!, - handle: blur.menu + ui, + handle: () => blur.menu(ui) }), quickPickItem({ label: "$(color-mode) Opacity", - description: `${get("backgroundOpacity", item.ui!)}`, + description: `${get("backgroundOpacity", ui)}`, detail: "Background image opacity", - ui: item.ui!, - handle: opacity.menu + ui, + handle: () => opacity.menu(ui) }), quickPickItem({ label: "$(multiple-windows) Repeat", - description: `${get("backgroundRepeat", item.ui!)}`, + description: `${get("backgroundRepeat", ui)}`, detail: "Background image repeat", - ui: item.ui!, - handle: repeat.menu + ui, + handle: () => repeat.menu(ui) }), quickPickItem({ label: "$(screen-full) Size", - description: `${get("backgroundSize", item.ui!)}`, + description: `${get("backgroundSize", ui)}`, detail: "Background image size", - ui: item.ui!, - handle: size.menu + ui, + handle: () => size.menu(ui) }), quickPickItem({ label: "$(clock) Time", - description: `${get("backgroundChangeTime", item.ui!)} second${get("backgroundChangeTime", item.ui!) === 1 ? '' : 's'}`, + description: `${get("backgroundChangeTime", ui)} second${get("backgroundChangeTime", ui) === 1 ? '' : 's'}`, detail: "How often to change the background", - ui: item.ui!, - handle: time.menu + ui, + handle: () => time.menu(ui) }) ], { ...options, - title: `${str.capitalize(item.ui!)} ${options.title}`, + title: `${str.capitalize(ui)} ${options.title}`, }); }; \ No newline at end of file diff --git a/src/command/config/align.ts b/src/command/config/align.ts index 5577153..dc067cf 100644 --- a/src/command/config/align.ts +++ b/src/command/config/align.ts @@ -18,7 +18,7 @@ import { config, Props } from "../../vs/package"; import { showInputBox } from "../../vs/inputbox"; -import { get, update, updateFromLabel } from "../../vs/vsconfig"; +import { get, UI, update, updateFromLabel } from "../../vs/vsconfig"; import { CommandQuickPickItem, quickPickItem, separator, showQuickPick } from "../../vs/quickpick"; import { menu as cm, options, title } from "../config"; @@ -31,46 +31,46 @@ const prop: Props = config("backgroundAlignment"); const handle: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { updateFromLabel("backgroundAlignment", item, item.ui!) - .then(() => cm(item)); // reopen menu + .then(() => cm(item.ui!)); // reopen menu }; -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { - const current: string = get("backgroundAlignment", item.ui!) as string; +export const menu: (ui: UI) => void = (ui: UI) => { + const current: string = get("backgroundAlignment", ui) as string; showQuickPick([ // top - quickPickItem({ label: prop.items!.enum![0], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![1], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![2], handle, ui: item.ui! }, current), + quickPickItem({ label: prop.items!.enum![0], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![1], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![2], onclick: handle, ui }, current), separator(), // center - quickPickItem({ label: prop.items!.enum![3], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![4], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![5], handle, ui: item.ui! }, current), + quickPickItem({ label: prop.items!.enum![3], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![4], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![5], onclick: handle, ui }, current), separator(), // bottom - quickPickItem({ label: prop.items!.enum![6], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![7], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![8], handle, ui: item.ui! }, current), + quickPickItem({ label: prop.items!.enum![6], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![7], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![8], onclick: handle, ui }, current), separator(), // manual - quickPickItem({ label: prop.items!.enum![9], description: "Manual position", ui: item.ui!, handle: (item: CommandQuickPickItem) => { - const currentValue: string = get("backgroundAlignmentValue", item.ui!); + quickPickItem({ label: prop.items!.enum![9], description: "Manual position", ui, onclick: (item: CommandQuickPickItem) => { + const currentValue: string = get("backgroundAlignmentValue", ui); showInputBox({ - title: title("Alignment", item.ui!), + title: title("Alignment", ui), placeHolder: "Background position", value: currentValue, prompt: `Background position (${currentValue}). The literal value for the 'background-position' css property.`, validateInput: (value: string) => !validCSS(value) ? "Invalid CSS" : null, handle: (value: string) => { if(validCSS(value)){ - let changed: boolean = get("backgroundAlignment", item.ui!) !== prop.items!.enum![9] || currentValue !== value; + let changed: boolean = get("backgroundAlignment", ui) !== prop.items!.enum![9] || currentValue !== value; - update("backgroundAlignment", prop.items!.enum![9], item.ui!, true) - .then(() => update("backgroundAlignmentValue", value, item.ui!, true)) + update("backgroundAlignment", prop.items!.enum![9], ui, true) + .then(() => update("backgroundAlignmentValue", value, ui, true)) .then(() => { changed && notify(); - cm(item); // reopen menu + cm(ui); // reopen menu }); } } @@ -79,7 +79,7 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic ], { ...options, - title: title("Alignment", item.ui!), + title: title("Alignment", ui), placeHolder: "Background alignment" }); }; \ No newline at end of file diff --git a/src/command/config/blur.ts b/src/command/config/blur.ts index 1a0fba2..8888551 100644 --- a/src/command/config/blur.ts +++ b/src/command/config/blur.ts @@ -17,27 +17,26 @@ */ import { showInputBox } from "../../vs/inputbox"; -import { get, update } from "../../vs/vsconfig"; -import { CommandQuickPickItem } from "../../vs/quickpick"; +import { UI, get, update } from "../../vs/vsconfig"; import { menu as cm, title } from "../config"; import { validCSS } from "../../lib/str"; // -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { - const current: string = get("backgroundBlur", item.ui!) as string; +export const menu: (ui: UI) => void = (ui: UI) => { + const current: string = get("backgroundBlur", ui) as string; showInputBox({ - title: title("Blur", item.ui!), + title: title("Blur", ui), placeHolder: "Background blur", value: current, prompt: `Background blur (${current})`, validateInput: (value: string) => !validCSS(value) ? "Invalid CSS" : null, handle: (value: string) => { if(validCSS(value)) - update("backgroundBlur", value, item.ui!) - .then(() => cm(item)); // reopen menu + update("backgroundBlur", value, ui) + .then(() => cm(ui)); // reopen menu } }); }; \ No newline at end of file diff --git a/src/command/config/file.ts b/src/command/config/file.ts index 2b29475..15c356f 100644 --- a/src/command/config/file.ts +++ b/src/command/config/file.ts @@ -39,7 +39,7 @@ export const add: (ui: UI, glob: string, skipWarning?: boolean) => Promise const files: string[] = get(`${ui}Backgrounds`) as string[]; files.push(glob); await update(`${ui}Backgrounds`, files.filter(unique), undefined, skipWarning); - skipWarning || cm({label: '␀', ui}); // reopen menu + skipWarning || cm(ui); // reopen menu }; export const replace: (ui: UI, old: string, glob: string, skipWarning?: boolean) => Promise = async (ui: UI, old: string, glob: string, skipWarning: boolean = false) => { @@ -48,12 +48,12 @@ export const replace: (ui: UI, old: string, glob: string, skipWarning?: boolean) if(files[i] === old) files[i] = glob; await update(`${ui}Backgrounds`, files.filter(unique), undefined, skipWarning || old === glob); - skipWarning || cm({label: '␀', ui}); // reopen menu + skipWarning || cm(ui); // reopen menu }; export const remove: (ui: UI, glob: string, skipWarning?: boolean) => Promise = async (ui: UI, glob: string, skipWarning: boolean = false) => { await update(`${ui}Backgrounds`, (get(`${ui}Backgrounds`) as string[]).filter((f) => f !== glob).filter(unique), undefined, skipWarning); - skipWarning || cm({label: '␀', ui}); // reopen files + skipWarning || cm(ui); // reopen files }; // extensions https://github.com/microsoft/vscode/blob/main/src/vs/platform/protocol/electron-main/protocolMainService.ts#L27 @@ -87,16 +87,16 @@ const updateItem: (ui: UI, item: CommandQuickPickItem) => void = (ui: UI, item: // files -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { +export const menu: (ui: UI) => void = (ui: UI) => { // existing items - const items: CommandQuickPickItem[] = (get(`${item.ui!}Backgrounds`) as string[]) + const items: CommandQuickPickItem[] = (get(`${ui}Backgrounds`) as string[]) .filter(unique) .map(file => quickPickItem({ label: file.replace(/(\${\w+})/g, "\\$1"), value: file, - ui: item.ui, + ui, description: `${str.s(glob.count(file), "matching file")}`, - handle: (item: CommandQuickPickItem) => updateItem(item.ui!, item) + onclick: (item: CommandQuickPickItem) => updateItem(ui, item) })); // show menu @@ -107,8 +107,8 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic // add quickPickItem({ label: "$(file-add) Add a File", - ui: item.ui!, - handle: (item: CommandQuickPickItem) => { + ui, + onclick: (item: CommandQuickPickItem) => { vscode.window.showOpenDialog({ canSelectFiles: true, canSelectFolders: false, @@ -119,18 +119,18 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic if(files){ let promise: Promise = Promise.resolve(); for(const file of files) - promise = promise.then(() => add(item.ui!, file.fsPath.replace(/\\/g, '/'), true)); // append promise to chain + promise = promise.then(() => add(ui, file.fsPath.replace(/\\/g, '/'), true)); // append promise to chain promise = promise .then(() => files.length > 0 && notify()) - .then(() => cm({label: '␀', ui: item.ui!})) // reopen menu + .then(() => cm(ui)) // reopen menu } }); } }), quickPickItem({ label: "$(file-directory-create) Add a Folder", - ui: item.ui!, - handle: (item: CommandQuickPickItem) => { + ui: ui, + onclick: (item: CommandQuickPickItem) => { vscode.window.showOpenDialog({ canSelectFiles: false, canSelectFolders: true, @@ -140,18 +140,18 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic if(files){ let promise: Promise = Promise.resolve(); for(const file of files) - promise = promise.then(() => add(item.ui!, `${file.fsPath.replace(/\\/g, '/')}/**`, true)); // append promise to chain + promise = promise.then(() => add(ui, `${file.fsPath.replace(/\\/g, '/')}/**`, true)); // append promise to chain promise = promise .then(() => files.length > 0 && notify()) - .then(() => cm({label: '␀', ui: item.ui!})) // reopen menu + .then(() => cm(ui)) // reopen menu } }); } }), quickPickItem({ label: "$(kebab-horizontal) Add a Glob", - ui: item.ui!, - handle: (item: CommandQuickPickItem) => { + ui, + onclick: (item: CommandQuickPickItem) => { vscode.window.showInputBox({ title: "Add File", placeHolder: "File path or glob", @@ -166,14 +166,14 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic } }).then((glob?: string) => { if(glob) - add(item.ui!, glob); + add(ui, glob); }); } }), quickPickItem({ label: "$(ports-open-browser-icon) Add a URL", - ui: item.ui!, - handle: (item: CommandQuickPickItem) => { + ui, + onclick: (item: CommandQuickPickItem) => { vscode.window.showInputBox({ title: "Add URL", placeHolder: "Image URL", @@ -190,7 +190,7 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic } }).then((url?: string) => { if(url) - add(item.ui!, url); + add(ui, url); }); } }), @@ -199,9 +199,9 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic separator(), quickPickItem({ label: "$(trash) Delete a background", - ui: item.ui!, - handle: (item: CommandQuickPickItem) => { - const items: CommandQuickPickItem[] = (get(`${item.ui!}Backgrounds`) as string[]) + ui: ui, + onclick: (item: CommandQuickPickItem) => { + const items: CommandQuickPickItem[] = (get(`${ui}Backgrounds`) as string[]) .filter(unique) .map(file => quickPickItem({ label: file.replace(/(\${\w+})/g, "\\$1"), @@ -214,7 +214,7 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic items, { ...options, - title: t("Delete", item.ui!), + title: t("Delete", ui), placeHolder: "Files", canPickMany: true } @@ -222,10 +222,10 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic if(selected){ let promise: Promise = Promise.resolve(); for(const file of selected) - promise = promise.then(() => remove(item.ui!, file.value!, true)); // append promise to chain + promise = promise.then(() => remove(ui, file.value!, true)); // append promise to chain promise = promise .then(() => selected.length > 0 && notify()) - .then(() => cm({label: '␀', ui: item.ui!})) // reopen menu + .then(() => cm(ui)) // reopen menu } }); } @@ -234,7 +234,7 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic ], { ...options, - title: t("Files", item.ui!), + title: t("Files", ui), placeHolder: "Files" }); }; \ No newline at end of file diff --git a/src/command/config/opacity.ts b/src/command/config/opacity.ts index 443ddc1..9986093 100644 --- a/src/command/config/opacity.ts +++ b/src/command/config/opacity.ts @@ -19,19 +19,18 @@ import * as vscode from "vscode"; import { showInputBox } from "../../vs/inputbox"; -import { get, update } from "../../vs/vsconfig"; -import { CommandQuickPickItem } from "../../vs/quickpick"; +import { UI, get, update } from "../../vs/vsconfig"; import { round } from "../../lib/round"; import { menu as cm, title } from "../config"; // -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { - const current: number = round(get("backgroundOpacity", item.ui!) as number, 2); +export const menu: (ui: UI) => void = (ui: UI) => { + const current: number = round(get("backgroundOpacity", ui) as number, 2); showInputBox({ - title: title("Opacity", item.ui!), + title: title("Opacity", ui), placeHolder: "Background opacity", value: current.toString(), prompt: `Background opacity (${current}). 0 is fully visible and 1 is invisible.`, @@ -47,8 +46,8 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic if(!isNaN(+value)){ const o: number = Math.min(Math.max(round(+value, 2), 0), 1); if(o > .1){ - update("backgroundOpacity", o, item.ui!) - .then(() => cm(item)); // reopen menu + update("backgroundOpacity", o, ui) + .then(() => cm(ui)); // reopen menu }else{ vscode.window.showWarningMessage( "An opacity of " + o + " might make it difficult to see the UI, " + @@ -57,8 +56,8 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic "Yes" ).then((c?: "Yes") => { if(c === "Yes") - update("backgroundOpacity", o, item.ui!) - .then(() => cm(item)); // reopen menu + update("backgroundOpacity", o, ui) + .then(() => cm(ui)); // reopen menu }); } } diff --git a/src/command/config/repeat.ts b/src/command/config/repeat.ts index d547e3a..9d3e5cc 100644 --- a/src/command/config/repeat.ts +++ b/src/command/config/repeat.ts @@ -18,7 +18,7 @@ import { config, Props } from "../../vs/package"; -import { get, updateFromLabel } from "../../vs/vsconfig"; +import { get, UI, updateFromLabel } from "../../vs/vsconfig"; import { CommandQuickPickItem, quickPickItem, showQuickPick } from "../../vs/quickpick"; import { menu as cm, options, title } from "../config"; @@ -29,23 +29,23 @@ const prop: Props = config("backgroundRepeat"); const handle: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { updateFromLabel("backgroundRepeat", item, item.ui!) - .then(() => cm(item)); // reopen menu + .then(() => cm(item.ui!)); // reopen menu }; -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { - const current: string = get("backgroundRepeat", item.ui!) as string; +export const menu: (ui: UI) => void = (ui: UI) => { + const current: string = get("backgroundRepeat", ui) as string; showQuickPick([ - quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], handle: handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], handle: handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], handle: handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], handle: handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![4], description: prop.items!.enumDescriptions![4], handle: handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![5], description: prop.items!.enumDescriptions![5], handle: handle, ui: item.ui! }, current), + quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![4], description: prop.items!.enumDescriptions![4], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![5], description: prop.items!.enumDescriptions![5], onclick: handle, ui }, current), ], { ...options, - title: title("Repeat", item.ui!), + title: title("Repeat", ui), placeHolder: "Background repeat", }); }; \ No newline at end of file diff --git a/src/command/config/size.ts b/src/command/config/size.ts index 50b85c9..e502372 100644 --- a/src/command/config/size.ts +++ b/src/command/config/size.ts @@ -18,7 +18,7 @@ import { config, Props } from "../../vs/package"; import { showInputBox } from "../../vs/inputbox"; -import { get, update, updateFromLabel } from "../../vs/vsconfig"; +import { get, UI, update, updateFromLabel } from "../../vs/vsconfig"; import { CommandQuickPickItem, quickPickItem, separator, showQuickPick } from "../../vs/quickpick"; import { menu as cm, options, title as t } from "../config"; @@ -31,23 +31,23 @@ const prop: Props = config("backgroundSize"); const handle: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { updateFromLabel("backgroundSize", item, item.ui!) - .then(() => cm(item)); // reopen menu + .then(() => cm(item.ui!)); // reopen menu }; -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { - const current: string = get("backgroundSize", item.ui!) as string; +export const menu: (ui: UI) => void = (ui: UI) => { + const current: string = get("backgroundSize", ui) as string; - const title: string = t("Size", item.ui!); + const title: string = t("Size", ui); showQuickPick([ // size - quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], handle, ui: item.ui! }, current), - quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], handle, ui: item.ui! }, current), + quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], onclick: handle, ui }, current), separator(), // manual - quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], ui: item.ui!, handle: (item: CommandQuickPickItem) => { - const currentValue: string = get("backgroundSizeValue", item.ui!); + quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], ui: ui, onclick: (item: CommandQuickPickItem) => { + const currentValue: string = get("backgroundSizeValue", ui); showInputBox({ title, placeHolder: "Background size", @@ -56,13 +56,13 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic validateInput: (value: string) => !validCSS(value) ? "Invalid CSS" : null, handle: (value: string) => { if(validCSS(value)){ - let changed: boolean = get("backgroundSize", item.ui!) !== prop.items!.enum![3] || currentValue !== value; + let changed: boolean = get("backgroundSize", ui) !== prop.items!.enum![3] || currentValue !== value; - update("backgroundSize", prop.items!.enum![3], item.ui!, true) - .then(() => update("backgroundSizeValue", value, item.ui!, true)) + update("backgroundSize", prop.items!.enum![3], ui, true) + .then(() => update("backgroundSizeValue", value, ui, true)) .then(() => { changed && notify(); - cm(item); // reopen menu + cm(ui); // reopen menu }); } } diff --git a/src/command/config/time.ts b/src/command/config/time.ts index fc1d7cf..a7ea5b2 100644 --- a/src/command/config/time.ts +++ b/src/command/config/time.ts @@ -17,19 +17,18 @@ */ import { showInputBox } from "../../vs/inputbox"; -import { get, update } from "../../vs/vsconfig"; -import { CommandQuickPickItem } from "../../vs/quickpick"; +import { UI, get, update } from "../../vs/vsconfig"; import { round } from "../../lib/round"; import { menu as cm, title } from "../config"; // -export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) => { - const current: number = round(get("backgroundChangeTime", item.ui!) as number, 2); +export const menu: (ui: UI) => void = (ui: UI) => { + const current: number = round(get("backgroundChangeTime", ui) as number, 2); showInputBox({ - title: title("Change Time", item.ui!), + title: title("Change Time", ui), placeHolder: "Background change time", value: current.toString(), prompt: `Background change time (${current}). How long in seconds before the background should automatically change. Set to 0 to always use the same image.`, @@ -44,8 +43,8 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic handle: (value: string) => { if(!isNaN(+value)){ const o: number = Math.max(round(+value, 2), 0); - update("backgroundChangeTime", o, item.ui!) - .then(() => cm(item)); // reopen menu + update("backgroundChangeTime", o, ui) + .then(() => cm(ui)); // reopen menu } } }); diff --git a/src/vs/quickpick.ts b/src/vs/quickpick.ts index 8ebf7d1..d68450d 100644 --- a/src/vs/quickpick.ts +++ b/src/vs/quickpick.ts @@ -23,7 +23,7 @@ import { UI } from "./vsconfig"; // types export interface CommandQuickPickItem extends vscode.QuickPickItem { - handle?: (item: CommandQuickPickItem) => void; + onclick?: (item: CommandQuickPickItem) => void; value?: string, ui?: UI } @@ -32,7 +32,7 @@ export interface CommandQuickPickItem extends vscode.QuickPickItem { export const showQuickPick: (items: CommandQuickPickItem[], options?: vscode.QuickPickOptions) => void = (items: CommandQuickPickItem[], options: vscode.QuickPickOptions = {}) => { vscode.window.showQuickPick(items, options).then((item?: CommandQuickPickItem) => { - item && item.handle && new Promise(() => item.handle!(item)); // run then in a promise + item && item.onclick && new Promise(() => item.onclick!(item)); // run then in a promise }); } From 5c36f70ecac200fc9bea26512f7ad3ea2cd7f503 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Wed, 9 Aug 2023 17:00:01 -0400 Subject: [PATCH 3/4] fix uncommited files --- src/command/config/align.ts | 20 ++++++++++---------- src/command/config/file.ts | 12 ++++++------ src/command/config/repeat.ts | 12 ++++++------ src/command/config/size.ts | 8 ++++---- src/vs/quickpick.ts | 4 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/command/config/align.ts b/src/command/config/align.ts index dc067cf..e4b2eab 100644 --- a/src/command/config/align.ts +++ b/src/command/config/align.ts @@ -39,22 +39,22 @@ export const menu: (ui: UI) => void = (ui: UI) => { showQuickPick([ // top - quickPickItem({ label: prop.items!.enum![0], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![1], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![2], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![0], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![1], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![2], handle, ui }, current), separator(), // center - quickPickItem({ label: prop.items!.enum![3], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![4], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![5], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![3], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![4], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![5], handle, ui }, current), separator(), // bottom - quickPickItem({ label: prop.items!.enum![6], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![7], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![8], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![6], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![7], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![8], handle, ui }, current), separator(), // manual - quickPickItem({ label: prop.items!.enum![9], description: "Manual position", ui, onclick: (item: CommandQuickPickItem) => { + quickPickItem({ label: prop.items!.enum![9], description: "Manual position", ui, handle: (item: CommandQuickPickItem) => { const currentValue: string = get("backgroundAlignmentValue", ui); showInputBox({ title: title("Alignment", ui), diff --git a/src/command/config/file.ts b/src/command/config/file.ts index 15c356f..1298da0 100644 --- a/src/command/config/file.ts +++ b/src/command/config/file.ts @@ -96,7 +96,7 @@ export const menu: (ui: UI) => void = (ui: UI) => { value: file, ui, description: `${str.s(glob.count(file), "matching file")}`, - onclick: (item: CommandQuickPickItem) => updateItem(ui, item) + handle: (item: CommandQuickPickItem) => updateItem(ui, item) })); // show menu @@ -108,7 +108,7 @@ export const menu: (ui: UI) => void = (ui: UI) => { quickPickItem({ label: "$(file-add) Add a File", ui, - onclick: (item: CommandQuickPickItem) => { + handle: (item: CommandQuickPickItem) => { vscode.window.showOpenDialog({ canSelectFiles: true, canSelectFolders: false, @@ -130,7 +130,7 @@ export const menu: (ui: UI) => void = (ui: UI) => { quickPickItem({ label: "$(file-directory-create) Add a Folder", ui: ui, - onclick: (item: CommandQuickPickItem) => { + handle: (item: CommandQuickPickItem) => { vscode.window.showOpenDialog({ canSelectFiles: false, canSelectFolders: true, @@ -151,7 +151,7 @@ export const menu: (ui: UI) => void = (ui: UI) => { quickPickItem({ label: "$(kebab-horizontal) Add a Glob", ui, - onclick: (item: CommandQuickPickItem) => { + handle: (item: CommandQuickPickItem) => { vscode.window.showInputBox({ title: "Add File", placeHolder: "File path or glob", @@ -173,7 +173,7 @@ export const menu: (ui: UI) => void = (ui: UI) => { quickPickItem({ label: "$(ports-open-browser-icon) Add a URL", ui, - onclick: (item: CommandQuickPickItem) => { + handle: (item: CommandQuickPickItem) => { vscode.window.showInputBox({ title: "Add URL", placeHolder: "Image URL", @@ -200,7 +200,7 @@ export const menu: (ui: UI) => void = (ui: UI) => { quickPickItem({ label: "$(trash) Delete a background", ui: ui, - onclick: (item: CommandQuickPickItem) => { + handle: (item: CommandQuickPickItem) => { const items: CommandQuickPickItem[] = (get(`${ui}Backgrounds`) as string[]) .filter(unique) .map(file => quickPickItem({ diff --git a/src/command/config/repeat.ts b/src/command/config/repeat.ts index 9d3e5cc..e6bd42e 100644 --- a/src/command/config/repeat.ts +++ b/src/command/config/repeat.ts @@ -36,12 +36,12 @@ export const menu: (ui: UI) => void = (ui: UI) => { const current: string = get("backgroundRepeat", ui) as string; showQuickPick([ - quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![4], description: prop.items!.enumDescriptions![4], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![5], description: prop.items!.enumDescriptions![5], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], handle: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], handle: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], handle: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], handle: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![4], description: prop.items!.enumDescriptions![4], handle: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![5], description: prop.items!.enumDescriptions![5], handle: handle, ui }, current), ], { ...options, diff --git a/src/command/config/size.ts b/src/command/config/size.ts index e502372..3031820 100644 --- a/src/command/config/size.ts +++ b/src/command/config/size.ts @@ -41,12 +41,12 @@ export const menu: (ui: UI) => void = (ui: UI) => { showQuickPick([ // size - quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], onclick: handle, ui }, current), - quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], onclick: handle, ui }, current), + quickPickItem({ label: prop.items!.enum![0], description: prop.items!.enumDescriptions![0], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![1], description: prop.items!.enumDescriptions![1], handle, ui }, current), + quickPickItem({ label: prop.items!.enum![2], description: prop.items!.enumDescriptions![2], handle, ui }, current), separator(), // manual - quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], ui: ui, onclick: (item: CommandQuickPickItem) => { + quickPickItem({ label: prop.items!.enum![3], description: prop.items!.enumDescriptions![3], ui: ui, handle: (item: CommandQuickPickItem) => { const currentValue: string = get("backgroundSizeValue", ui); showInputBox({ title, diff --git a/src/vs/quickpick.ts b/src/vs/quickpick.ts index d68450d..8ebf7d1 100644 --- a/src/vs/quickpick.ts +++ b/src/vs/quickpick.ts @@ -23,7 +23,7 @@ import { UI } from "./vsconfig"; // types export interface CommandQuickPickItem extends vscode.QuickPickItem { - onclick?: (item: CommandQuickPickItem) => void; + handle?: (item: CommandQuickPickItem) => void; value?: string, ui?: UI } @@ -32,7 +32,7 @@ export interface CommandQuickPickItem extends vscode.QuickPickItem { export const showQuickPick: (items: CommandQuickPickItem[], options?: vscode.QuickPickOptions) => void = (items: CommandQuickPickItem[], options: vscode.QuickPickOptions = {}) => { vscode.window.showQuickPick(items, options).then((item?: CommandQuickPickItem) => { - item && item.onclick && new Promise(() => item.onclick!(item)); // run then in a promise + item && item.handle && new Promise(() => item.handle!(item)); // run then in a promise }); } From a6ff5b173dcfa1eceb03598f9605e84568025ea3 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Wed, 9 Aug 2023 17:22:48 -0400 Subject: [PATCH 4/4] replace promise loop with grouped async update --- src/command/config/file.ts | 49 +++++++++++++++----------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/command/config/file.ts b/src/command/config/file.ts index 1298da0..b6efe58 100644 --- a/src/command/config/file.ts +++ b/src/command/config/file.ts @@ -27,7 +27,6 @@ import * as glob from "../../lib/glob"; import { unique } from "../../lib/unique"; import { menu as cm, options, title as t } from "../config"; -import { notify } from "../install"; // config @@ -36,11 +35,15 @@ export const view: (ui: UI) => string[] = (ui: UI) => { } export const add: (ui: UI, glob: string, skipWarning?: boolean) => Promise = async (ui: UI, glob: string, skipWarning: boolean = false) => { + await addMultiple(ui, [glob], skipWarning); +} + +export const addMultiple: (ui: UI, globs: string[], skipWarning?: boolean) => Promise = async (ui: UI, globs: string[], skipWarning: boolean = false) => { const files: string[] = get(`${ui}Backgrounds`) as string[]; - files.push(glob); + files.push(...globs); await update(`${ui}Backgrounds`, files.filter(unique), undefined, skipWarning); skipWarning || cm(ui); // reopen menu -}; +} export const replace: (ui: UI, old: string, glob: string, skipWarning?: boolean) => Promise = async (ui: UI, old: string, glob: string, skipWarning: boolean = false) => { const files: string[] = get(`${ui}Backgrounds`) as string[]; @@ -52,9 +55,13 @@ export const replace: (ui: UI, old: string, glob: string, skipWarning?: boolean) }; export const remove: (ui: UI, glob: string, skipWarning?: boolean) => Promise = async (ui: UI, glob: string, skipWarning: boolean = false) => { - await update(`${ui}Backgrounds`, (get(`${ui}Backgrounds`) as string[]).filter((f) => f !== glob).filter(unique), undefined, skipWarning); - skipWarning || cm(ui); // reopen files -}; + await removeMultiple(ui, [glob], skipWarning); +} + +export const removeMultiple: (ui: UI, globs: string[], skipWarning?: boolean) => Promise = async (ui: UI, globs: string[], skipWarning: boolean = false) => { + await update(`${ui}Backgrounds`, (get(`${ui}Backgrounds`) as string[]).filter((f) => !globs.includes(f)).filter(unique), undefined, skipWarning); + skipWarning || cm(ui); // reopen menu +} // extensions https://github.com/microsoft/vscode/blob/main/src/vs/platform/protocol/electron-main/protocolMainService.ts#L27 @@ -116,14 +123,8 @@ export const menu: (ui: UI) => void = (ui: UI) => { openLabel: "Select Image", filters: {"Images": extensions()} }).then((files?: vscode.Uri[]) => { - if(files){ - let promise: Promise = Promise.resolve(); - for(const file of files) - promise = promise.then(() => add(ui, file.fsPath.replace(/\\/g, '/'), true)); // append promise to chain - promise = promise - .then(() => files.length > 0 && notify()) - .then(() => cm(ui)) // reopen menu - } + if(files) + addMultiple(ui, files.map((f) => f.fsPath.replace(/\\/g, '/'))); }); } }), @@ -137,14 +138,8 @@ export const menu: (ui: UI) => void = (ui: UI) => { canSelectMany: true, openLabel: "Select Folder" }).then((files?: vscode.Uri[]) => { - if(files){ - let promise: Promise = Promise.resolve(); - for(const file of files) - promise = promise.then(() => add(ui, `${file.fsPath.replace(/\\/g, '/')}/**`, true)); // append promise to chain - promise = promise - .then(() => files.length > 0 && notify()) - .then(() => cm(ui)) // reopen menu - } + if(files) + addMultiple(ui, files.map((f) => `${f.fsPath.replace(/\\/g, '/')}/**`)); }); } }), @@ -219,14 +214,8 @@ export const menu: (ui: UI) => void = (ui: UI) => { canPickMany: true } ).then((selected?: CommandQuickPickItem[]) => { - if(selected){ - let promise: Promise = Promise.resolve(); - for(const file of selected) - promise = promise.then(() => remove(ui, file.value!, true)); // append promise to chain - promise = promise - .then(() => selected.length > 0 && notify()) - .then(() => cm(ui)) // reopen menu - } + if(selected) + removeMultiple(ui, selected.map((f) => f.value!)); }); } })