Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu to delete backgrounds #185

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/command/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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}`,
});
};
42 changes: 21 additions & 21 deletions src/command/config/align.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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], 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], 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], 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], 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], 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: item.ui!, handle: (item: CommandQuickPickItem) => {
const currentValue: string = get("backgroundAlignmentValue", item.ui!);
quickPickItem({ label: prop.items!.enum![9], description: "Manual position", ui, handle: (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
});
}
}
Expand All @@ -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"
});
};
13 changes: 6 additions & 7 deletions src/command/config/blur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
};
Loading