-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsize.ts
More file actions
71 lines (63 loc) · 3.25 KB
/
Copy pathsize.ts
File metadata and controls
71 lines (63 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (C) 2023 Katsute <https://github.com/Katsute>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import { UI, get, notify, update, updateFromLabel } from "../extension/config";
import { Properties, getConfigurationProperty } from "../extension/package";
import { isValidCSS } from "../lib/css";
import { CommandQuickPickItem, quickPickItem, separator, showInputBox, showQuickPick } from "../lib/vscode";
import { open, title } from "./menu";
const prop: Properties = getConfigurationProperty("backgroundSize");
const handle: (item: CommandQuickPickItem) => void = (item: CommandQuickPickItem) =>
updateFromLabel("backgroundSize", item, item.ui!)
.then(() => open(item.ui!)); // reopen menu
export const show: (ui: UI) => void = (ui: UI) => {
const current: string = get("backgroundSize", ui) as string;
showQuickPick([
// size
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: `(${get("backgroundSizeValue", ui)})`, ui: ui, handle: (item: CommandQuickPickItem) => {
const currentValue: string = get("backgroundSizeValue", ui);
showInputBox({
title: title("Size", ui),
placeHolder: "Background size",
value: currentValue,
prompt: `Background size (${currentValue}). The literal value for the 'background-size' css property.`,
validateInput: (value: string) => !isValidCSS(value) ? "Invalid CSS" : null,
handle: (value: string) => {
if(isValidCSS(value)){
let changed: boolean = get("backgroundSize", ui) !== prop.items!.enum![3] || currentValue !== value;
update("backgroundSize", prop.items!.enum![3], ui, true)
.then(() => update("backgroundSizeValue", value, ui, true))
.then(() => {
changed && notify();
open(ui); // reopen menu
});
}
}
});
}}, current)
],
{
title: title("Size", ui),
matchOnDescription: true,
placeHolder: "Background size"
});
}