From eaf753f79e029879646b059d27d81a1ab0e23ba4 Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:23:32 -0700 Subject: [PATCH] Remove unused prompt code (#10996) --- extensions/notebook/src/prompts/checkbox.ts | 50 ------------ extensions/notebook/src/prompts/expand.ts | 76 ------------------- extensions/notebook/src/prompts/factory.ts | 22 +----- extensions/notebook/src/prompts/input.ts | 59 -------------- extensions/notebook/src/prompts/list.ts | 32 -------- extensions/notebook/src/prompts/password.ts | 14 ---- .../notebook/src/prompts/progressIndicator.ts | 70 ----------------- 7 files changed, 1 insertion(+), 322 deletions(-) delete mode 100644 extensions/notebook/src/prompts/checkbox.ts delete mode 100644 extensions/notebook/src/prompts/expand.ts delete mode 100644 extensions/notebook/src/prompts/input.ts delete mode 100644 extensions/notebook/src/prompts/list.ts delete mode 100644 extensions/notebook/src/prompts/password.ts delete mode 100644 extensions/notebook/src/prompts/progressIndicator.ts diff --git a/extensions/notebook/src/prompts/checkbox.ts b/extensions/notebook/src/prompts/checkbox.ts deleted file mode 100644 index 62a5549217..0000000000 --- a/extensions/notebook/src/prompts/checkbox.ts +++ /dev/null @@ -1,50 +0,0 @@ -// This code is originally from https://github.com/DonJayamanne/bowerVSCode -// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE - -import { window } from 'vscode'; -import Prompt from './prompt'; -import EscapeException from './escapeException'; - -const figures = require('figures'); - -export default class CheckboxPrompt extends Prompt { - - constructor(question: any, ignoreFocusOut?: boolean) { - super(question, ignoreFocusOut); - } - - public render(): any { - let choices = this._question.choices.reduce((result: any, choice: any) => { - let choiceName = choice.name || choice; - result[`${choice.checked === true ? figures.radioOn : figures.radioOff} ${choiceName}`] = choice; - return result; - }, {}); - - let options = this.defaultQuickPickOptions; - options.placeHolder = this._question.message; - - let quickPickOptions = Object.keys(choices); - quickPickOptions.push(figures.tick); - - return window.showQuickPick(quickPickOptions, options) - .then(result => { - if (result === undefined) { - throw new EscapeException(); - } - - if (result !== figures.tick) { - choices[result].checked = !choices[result].checked; - - return this.render(); - } - - return this._question.choices.reduce((result2: any, choice: any) => { - if (choice.checked === true) { - result2.push(choice.value); - } - - return result2; - }, []); - }); - } -} diff --git a/extensions/notebook/src/prompts/expand.ts b/extensions/notebook/src/prompts/expand.ts deleted file mode 100644 index d254ba36e2..0000000000 --- a/extensions/notebook/src/prompts/expand.ts +++ /dev/null @@ -1,76 +0,0 @@ -// This code is originally from https://github.com/DonJayamanne/bowerVSCode -// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE - -import vscode = require('vscode'); -import Prompt from './prompt'; -import EscapeException from './escapeException'; -import { INameValueChoice } from './question'; - -const figures = require('figures'); - -export default class ExpandPrompt extends Prompt { - - constructor(question: any, ignoreFocusOut?: boolean) { - super(question, ignoreFocusOut); - } - - public render(): any { - // label indicates this is a quickpick item. Otherwise it's a name-value pair - if (this._question.choices[0].label) { - return this.renderQuickPick(this._question.choices); - } else { - return this.renderNameValueChoice(this._question.choices); - } - } - - private renderQuickPick(choices: vscode.QuickPickItem[]): any { - let options = this.defaultQuickPickOptions; - options.placeHolder = this._question.message; - - return vscode.window.showQuickPick(choices, options) - .then(result => { - if (result === undefined) { - throw new EscapeException(); - } - - return this.validateAndReturn(result || false); - }); - } - private renderNameValueChoice(choices: INameValueChoice[]): any { - const choiceMap = this._question.choices.reduce((result: any, choice: any) => { - result[choice.name] = choice.value; - return result; - }, {}); - - let options = this.defaultQuickPickOptions; - options.placeHolder = this._question.message; - - return vscode.window.showQuickPick(Object.keys(choiceMap), options) - .then(result => { - if (result === undefined) { - throw new EscapeException(); - } - - // Note: cannot be used with 0 or false responses - let returnVal = choiceMap[result] || false; - return this.validateAndReturn(returnVal); - }); - } - - private validateAndReturn(value: any): any { - if (!this.validate(value)) { - return this.render(); - } - return value; - } - - private validate(value: any): boolean { - const validationError = this._question.validate ? this._question.validate(value || '') : undefined; - - if (validationError) { - this._question.message = `${figures.warning} ${validationError}`; - return false; - } - return true; - } -} diff --git a/extensions/notebook/src/prompts/factory.ts b/extensions/notebook/src/prompts/factory.ts index 250d1b0f33..b245ed2115 100644 --- a/extensions/notebook/src/prompts/factory.ts +++ b/extensions/notebook/src/prompts/factory.ts @@ -4,34 +4,14 @@ // License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE import Prompt from './prompt'; -import InputPrompt from './input'; -import PasswordPrompt from './password'; -import ListPrompt from './list'; import ConfirmPrompt from './confirm'; -import CheckboxPrompt from './checkbox'; -import ExpandPrompt from './expand'; export default class PromptFactory { public static createPrompt(question: any, ignoreFocusOut?: boolean): Prompt { - /** - * TODO: - * - folder - */ - switch (question.type || 'input') { - case 'string': - case 'input': - return new InputPrompt(question, ignoreFocusOut); - case 'password': - return new PasswordPrompt(question, ignoreFocusOut); - case 'list': - return new ListPrompt(question, ignoreFocusOut); + switch (question.type) { case 'confirm': return new ConfirmPrompt(question, ignoreFocusOut); - case 'checkbox': - return new CheckboxPrompt(question, ignoreFocusOut); - case 'expand': - return new ExpandPrompt(question, ignoreFocusOut); default: throw new Error(`Could not find a prompt for question type ${question.type}`); } diff --git a/extensions/notebook/src/prompts/input.ts b/extensions/notebook/src/prompts/input.ts deleted file mode 100644 index eb57f3faee..0000000000 --- a/extensions/notebook/src/prompts/input.ts +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -// This code is originally from https://github.com/DonJayamanne/bowerVSCode -// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE - -import { window, InputBoxOptions } from 'vscode'; -import Prompt from './prompt'; -import EscapeException from './escapeException'; - -const figures = require('figures'); - -export default class InputPrompt extends Prompt { - - protected _options: InputBoxOptions; - - constructor(question: any, ignoreFocusOut?: boolean) { - super(question, ignoreFocusOut); - - this._options = this.defaultInputBoxOptions; - this._options.prompt = this._question.message; - } - - // Helper for callers to know the right type to get from the type factory - public static get promptType(): string { return 'input'; } - - public render(): any { - // Prefer default over the placeHolder, if specified - let placeHolder = this._question.default ? this._question.default : this._question.placeHolder; - - if (this._question.default instanceof Error) { - placeHolder = this._question.default.message; - this._question.default = undefined; - } - - this._options.placeHolder = placeHolder; - - return window.showInputBox(this._options) - .then(result => { - if (result === undefined) { - throw new EscapeException(); - } - - if (result === '') { - // Use the default value, if defined - result = this._question.default || ''; - } - - const validationError = this._question.validate ? this._question.validate(result || '') : undefined; - - if (validationError) { - this._question.default = new Error(`${figures.warning} ${validationError}`); - - return this.render(); - } - - return result; - }); - } -} diff --git a/extensions/notebook/src/prompts/list.ts b/extensions/notebook/src/prompts/list.ts deleted file mode 100644 index a487f8e6a7..0000000000 --- a/extensions/notebook/src/prompts/list.ts +++ /dev/null @@ -1,32 +0,0 @@ -// This code is originally from https://github.com/DonJayamanne/bowerVSCode -// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE - -import { window } from 'vscode'; -import Prompt from './prompt'; -import EscapeException from './escapeException'; - -export default class ListPrompt extends Prompt { - - constructor(question: any, ignoreFocusOut?: boolean) { - super(question, ignoreFocusOut); - } - - public render(): any { - const choices = this._question.choices.reduce((result: any, choice: any) => { - result[choice.name] = choice.value; - return result; - }, {}); - - let options = this.defaultQuickPickOptions; - options.placeHolder = this._question.message; - - return window.showQuickPick(Object.keys(choices), options) - .then(result => { - if (result === undefined) { - throw new EscapeException(); - } - - return choices[result]; - }); - } -} diff --git a/extensions/notebook/src/prompts/password.ts b/extensions/notebook/src/prompts/password.ts deleted file mode 100644 index c379571cf9..0000000000 --- a/extensions/notebook/src/prompts/password.ts +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -// This code is originally from https://github.com/DonJayamanne/bowerVSCode -// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE -import InputPrompt from './input'; - -export default class PasswordPrompt extends InputPrompt { - - constructor(question: any, ignoreFocusOut?: boolean) { - super(question, ignoreFocusOut); - - this._options.password = true; - } -} diff --git a/extensions/notebook/src/prompts/progressIndicator.ts b/extensions/notebook/src/prompts/progressIndicator.ts deleted file mode 100644 index d63b830a08..0000000000 --- a/extensions/notebook/src/prompts/progressIndicator.ts +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -// This code is originally from https://github.com/DonJayamanne/bowerVSCode -// License: https://github.com/DonJayamanne/bowerVSCode/blob/master/LICENSE - -import { window, StatusBarItem, StatusBarAlignment } from 'vscode'; - -export default class ProgressIndicator { - - private _statusBarItem: StatusBarItem; - - constructor() { - this._statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left); - } - - private _tasks: string[] = []; - public beginTask(task: string): void { - this._tasks.push(task); - this.displayProgressIndicator(); - } - - public endTask(task: string): void { - if (this._tasks.length > 0) { - this._tasks.pop(); - } - - this.setMessage(); - } - - private setMessage(): void { - if (this._tasks.length === 0) { - this._statusBarItem.text = ''; - this.hideProgressIndicator(); - return; - } - - this._statusBarItem.text = this._tasks[this._tasks.length - 1]; - this._statusBarItem.show(); - } - - private _interval: any; - private displayProgressIndicator(): void { - this.setMessage(); - this.hideProgressIndicator(); - this._interval = setInterval(() => this.onDisplayProgressIndicator(), 100); - } - private hideProgressIndicator(): void { - if (this._interval) { - clearInterval(this._interval); - this._interval = undefined; - } - this.ProgressCounter = 0; - } - - private ProgressText = ['|', '/', '-', '\\', '|', '/', '-', '\\']; - private ProgressCounter = 0; - private onDisplayProgressIndicator(): void { - if (this._tasks.length === 0) { - return; - } - - let txt = this.ProgressText[this.ProgressCounter]; - this._statusBarItem.text = this._tasks[this._tasks.length - 1] + ' ' + txt; - this.ProgressCounter++; - - if (this.ProgressCounter >= this.ProgressText.length - 1) { - this.ProgressCounter = 0; - } - } -}