diff --git a/package-lock.json b/package-lock.json index 0df19f7..2484cf5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -726,16 +726,30 @@ "dev": true }, "browserslist": { - "version": "4.16.4", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.4.tgz", - "integrity": "sha512-d7rCxYV8I9kj41RH8UKYnvDYCRENUlHRgyXy/Rhr/1BaeLGfiCptEdFE8MIrvGfWbBFNjVYx76SQWvNX1j+/cQ==", + "version": "4.16.6", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", + "integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", "dev": true, "requires": { - "caniuse-lite": "^1.0.30001208", + "caniuse-lite": "^1.0.30001219", "colorette": "^1.2.2", - "electron-to-chromium": "^1.3.712", + "electron-to-chromium": "^1.3.723", "escalade": "^3.1.1", "node-releases": "^1.1.71" + }, + "dependencies": { + "caniuse-lite": { + "version": "1.0.30001230", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", + "integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", + "dev": true + }, + "electron-to-chromium": { + "version": "1.3.742", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.742.tgz", + "integrity": "sha512-ihL14knI9FikJmH2XUIDdZFWJxvr14rPSdOhJ7PpS27xbz8qmaRwCwyg/bmFwjWKmWK9QyamiCZVCvXm5CH//Q==", + "dev": true + } } }, "buffer-crc32": { @@ -784,12 +798,6 @@ "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==", "dev": true }, - "caniuse-lite": { - "version": "1.0.30001209", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001209.tgz", - "integrity": "sha512-2Ktt4OeRM7EM/JaOZjuLzPYAIqmbwQMNnYbgooT+icoRGrKOyAxA1xhlnotBD1KArRSPsuJp3TdYcZYrL7qNxA==", - "dev": true - }, "chainsaw": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz", @@ -1091,12 +1099,6 @@ "readable-stream": "^2.0.2" } }, - "electron-to-chromium": { - "version": "1.3.717", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.717.tgz", - "integrity": "sha512-OfzVPIqD1MkJ7fX+yTl2nKyOE4FReeVfMCzzxQS+Kp43hZYwHwThlGP+EGIZRXJsxCM7dqo8Y65NOX/HP12iXQ==", - "dev": true - }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", diff --git a/package.json b/package.json index 352d03c..63f60e4 100644 --- a/package.json +++ b/package.json @@ -222,6 +222,11 @@ "icon": "$(refresh)", "category": "Appwrite" }, + { + "command": "vscode-appwrite.refreshFunctions", + "title": "Refresh functions", + "icon": "$(refresh)" + }, { "command": "vscode-appwrite.removeProject", "title": "Remove project", diff --git a/src/tree/common/EditableTreeItemBase.ts b/src/tree/common/EditableTreeItemBase.ts new file mode 100644 index 0000000..70bfd00 --- /dev/null +++ b/src/tree/common/EditableTreeItemBase.ts @@ -0,0 +1,13 @@ +import { TreeItem } from "vscode"; + +export abstract class EditableTreeItemBase extends TreeItem { + public abstract setValue(value: T): Promise; + + constructor(contextValuePrefix: string, public readonly value: T, description?: string) { + super(typeof value === "string" ? value : "No label"); + this.contextValue = `editable_${contextValuePrefix}`; + this.description = description ?? contextValuePrefix; + } + + public abstract prompt(): Promise; +} diff --git a/src/tree/common/EnumEditableTreeItem.ts b/src/tree/common/EnumEditableTreeItem.ts new file mode 100644 index 0000000..9969f9b --- /dev/null +++ b/src/tree/common/EnumEditableTreeItem.ts @@ -0,0 +1,38 @@ +import { QuickPickItem, QuickPickOptions, window } from "vscode"; +import { EditableTreeItemBase } from "./EditableTreeItemBase"; + +export abstract class EnumEditableTreeItemBase extends EditableTreeItemBase { + public abstract options: string[] | QuickPickItem[]; + + public quickPickOptions: QuickPickOptions; + + constructor(contextValuePrefix: string, public readonly value: string[], description?: string) { + super(contextValuePrefix, value, description); + this.quickPickOptions = {}; + } + + public async prompt(): Promise { + + const value = await window.showQuickPick( + this.options.map((option: QuickPickItem | string): QuickPickItem => { + if (typeof option === "string") { + return { label: option, picked: this.value.includes(option) }; + } + const picked = this.value.includes(option.label); + return { ...option, picked, alwaysShow: picked }; + }).sort((a, b) => { + if (a.picked) { + return -1; + } + if (b.picked) { + return 1; + } + return 0; + }), + { ...this.quickPickOptions, canPickMany: true } + ); + if (value !== undefined) { + this.setValue(value.map((item) => item.label)); + } + } +} diff --git a/src/tree/common/SimpleEditableTreeItem.ts b/src/tree/common/SimpleEditableTreeItem.ts new file mode 100644 index 0000000..834e299 --- /dev/null +++ b/src/tree/common/SimpleEditableTreeItem.ts @@ -0,0 +1,18 @@ +import { TreeItem, window } from "vscode"; + +export class EditableTreeItem extends TreeItem { + public readonly setValue: (value: string) => Promise; + + constructor(label: string, contextValuePrefix: string, public readonly value: string, setValue: (value: string) => Promise) { + super(label); + this.setValue = setValue; + this.contextValue = `editable_${contextValuePrefix}`; + } + + public async prompt(): Promise { + const value = await window.showInputBox({ value: this.value }); + if (value !== undefined) { + this.setValue(value); + } + } +} diff --git a/src/tree/common/StringEditableTreeItem.ts b/src/tree/common/StringEditableTreeItem.ts new file mode 100644 index 0000000..e4f77b0 --- /dev/null +++ b/src/tree/common/StringEditableTreeItem.ts @@ -0,0 +1,22 @@ +import { InputBoxOptions, window } from "vscode"; +import { EditableTreeItemBase } from "./EditableTreeItemBase"; + +export abstract class StringEditableTreeItemBase extends EditableTreeItemBase { + public abstract setValue(value: string): Promise; + public inputBoxOptions: InputBoxOptions; + + constructor(contextValuePrefix: string, public readonly value: string, description?: string) { + super(contextValuePrefix, value, description); + + this.inputBoxOptions = { + prompt: description, + }; + } + + public async prompt(): Promise { + const value = await window.showInputBox({ value: this.value, ...this.inputBoxOptions }); + if (value !== undefined) { + this.setValue(value); + } + } +}