Skip to content

Commit

Permalink
Prompt and validation message (#48116)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Apr 23, 2018
1 parent a81269e commit 2b4dfcc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/vs/workbench/browser/parts/quickinput/quickInput.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

.quick-input-box {
flex-grow: 1;
}

.quick-input-widget[data-type=selectMany] .quick-input-box {
margin-left: 5px;
}

Expand All @@ -53,6 +56,10 @@
line-height: initial;
}

.quick-input-message {
margin: 0px 11px;
}

.quick-input-progress.monaco-progress-container,
.quick-input-progress.monaco-progress-container .progress-bit {
height: 2px;
Expand Down
35 changes: 28 additions & 7 deletions src/vs/workbench/browser/parts/quickinput/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';
import { chain } from 'vs/base/common/event';
import { Button } from 'vs/base/browser/ui/button/button';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { onUnexpectedError } from 'vs/base/common/errors';

const $ = dom.$;

Expand All @@ -52,13 +53,15 @@ export interface SelectManyParameters<T extends IPickOpenEntry = IPickOpenEntry>
export interface TextInputParameters extends BaseInputParameters {
readonly type: 'textInput';
readonly value?: string;
readonly prompt?: string;
readonly validateInput?: (input: string) => TPromise<string>;
}

interface QuickInputUI {
checkAll: HTMLInputElement;
inputBox: QuickInputBox;
count: CountBadge;
message: HTMLElement;
checkboxList: QuickInputCheckboxList;
}

Expand All @@ -84,6 +87,8 @@ class SelectManyController<T extends IPickOpenEntry> implements InputController<
});
this.result.then(() => this.closed = true, () => this.closed = true);

ui.inputBox.value = '';
ui.inputBox.setPlaceholder(parameters.placeHolder || '');
ui.checkboxList.matchOnDescription = parameters.matchOnDescription;
ui.checkboxList.matchOnDetail = parameters.matchOnDetail;
ui.checkboxList.setElements([]);
Expand All @@ -104,10 +109,11 @@ class SelectManyController<T extends IPickOpenEntry> implements InputController<
}

class TextInputController implements InputController<string> {
public showUI = { inputBox: true };
public showUI = { inputBox: true, message: true };
public result: TPromise<string>;
public ready = TPromise.as(null);
public resolve: (ok?: true | Thenable<never>) => void;
private validationValue: string;
private disposables: IDisposable[] = [];

constructor(ui: QuickInputUI, parameters: TextInputParameters) {
Expand All @@ -117,10 +123,22 @@ class TextInputController implements InputController<string> {
this.result.then(() => this.dispose());

ui.inputBox.value = parameters.value || '';
ui.inputBox.setPlaceholder(parameters.placeHolder || '');
const defaultMessage = parameters.prompt
? localize('inputModeEntryDescription', "{0} (Press 'Enter' to confirm or 'Escape' to cancel)", parameters.prompt)
: localize('inputModeEntry', "Press 'Enter' to confirm your input or 'Escape' to cancel");
ui.message.textContent = defaultMessage;

if (parameters.validateInput) {
this.disposables.push(ui.inputBox.onDidChange(value => {
parameters.validateInput(value);
// TODO
this.validationValue = value;
parameters.validateInput(value)
.then(validationError => {
if (this.validationValue === value) {
ui.message.textContent = validationError || defaultMessage;
}
})
.then(null, onUnexpectedError);
}));
}
}
Expand Down Expand Up @@ -218,6 +236,8 @@ export class QuickInputService extends Component implements IQuickInputService {
}
}));

const message = dom.append(this.container, $('.quick-input-message'));

this.progressBar = new ProgressBar(this.container);
dom.addClass(this.progressBar.getContainer(), 'quick-input-progress');
this.toUnbind.push(attachProgressBarStyler(this.progressBar, this.themeService));
Expand Down Expand Up @@ -289,7 +309,7 @@ export class QuickInputService extends Component implements IQuickInputService {

this.toUnbind.push(this.quickOpenService.onShow(() => this.close()));

this.ui = { checkAll, inputBox, count, checkboxList };
this.ui = { checkAll, inputBox, count, message, checkboxList };
this.updateStyles();
}

Expand All @@ -315,6 +335,7 @@ export class QuickInputService extends Component implements IQuickInputService {
return this.show({
type: 'textInput',
value: options.value,
prompt: options.prompt,
placeHolder: options.placeHolder,
ignoreFocusLost: options.ignoreFocusLost,
validateInput: options.validateInput,
Expand All @@ -330,10 +351,9 @@ export class QuickInputService extends Component implements IQuickInputService {
this.controller.resolve();
}

this.ignoreFocusLost = parameters.ignoreFocusLost;
this.container.setAttribute('data-type', parameters.type);

this.ui.inputBox.value = '';
this.ui.inputBox.setPlaceholder(parameters.placeHolder || '');
this.ignoreFocusLost = parameters.ignoreFocusLost;

this.progressBar.stop();
this.ready = false;
Expand All @@ -343,6 +363,7 @@ export class QuickInputService extends Component implements IQuickInputService {
this.filterContainer.style.display = this.controller.showUI.inputBox ? null : 'none';
this.countContainer.style.display = this.controller.showUI.count ? null : 'none';
this.okContainer.style.display = this.controller.showUI.ok ? null : 'none';
this.ui.message.style.display = this.controller.showUI.message ? null : 'none';
this.ui.checkboxList.display(this.controller.showUI.checkboxList);

this.container.style.display = null;
Expand Down

0 comments on commit 2b4dfcc

Please sign in to comment.