diff --git a/samples/sqlservices/src/controllers/mainController.ts b/samples/sqlservices/src/controllers/mainController.ts index f836ffa032..fd6073f67c 100644 --- a/samples/sqlservices/src/controllers/mainController.ts +++ b/samples/sqlservices/src/controllers/mainController.ts @@ -82,7 +82,8 @@ export default class MainController implements vscode.Disposable { tab1.registerContent(async (view) => { let inputBox = view.modelBuilder.inputBox() .withProperties({ - //width: 300 + multiline: true, + height: 100 }).component(); let inputBoxWrapper = view.modelBuilder.loadingComponent().withItem(inputBox).component(); inputBoxWrapper.loading = false; diff --git a/src/sql/base/browser/ui/inputBox/inputBox.ts b/src/sql/base/browser/ui/inputBox/inputBox.ts index e13df70934..eb10b5117d 100644 --- a/src/sql/base/browser/ui/inputBox/inputBox.ts +++ b/src/sql/base/browser/ui/inputBox/inputBox.ts @@ -67,6 +67,14 @@ export class InputBox extends vsInputBox { this.applyStyles(); } + public set rows(value: number) { + this.inputElement.setAttribute('rows', value.toString()); + } + + public set columns(value: number) { + this.inputElement.setAttribute('cols', value.toString()); + } + public disable(): void { super.disable(); this.inputBackground = this.disabledInputBackground; @@ -75,6 +83,10 @@ export class InputBox extends vsInputBox { this.applyStyles(); } + public setHeight(value: string) { + this.inputElement.style.height = value; + } + public isEnabled(): boolean { return !this.inputElement.hasAttribute('disabled'); } diff --git a/src/sql/parts/modelComponents/inputbox.component.ts b/src/sql/parts/modelComponents/inputbox.component.ts index a881731edd..f4ef757316 100644 --- a/src/sql/parts/modelComponents/inputbox.component.ts +++ b/src/sql/parts/modelComponents/inputbox.component.ts @@ -20,19 +20,23 @@ import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/work import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { Event, Emitter } from 'vs/base/common/event'; import * as nls from 'vs/nls'; +import { TextAreaInput } from 'vs/editor/browser/controller/textAreaInput'; @Component({ selector: 'modelview-inputBox', template: ` -
+ + ` }) export default class InputBoxComponent extends ComponentBase implements IComponent, OnDestroy, AfterViewInit { @Input() descriptor: IComponentDescriptor; @Input() modelStore: IModelStore; private _input: InputBox; + private _textAreaInput: InputBox; @ViewChild('input', { read: ElementRef }) private _inputContainer: ElementRef; + @ViewChild('textarea', { read: ElementRef }) private _textareaContainer: ElementRef; constructor( @Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef, @Inject(IWorkbenchThemeService) private themeService: IWorkbenchThemeService, @@ -43,47 +47,71 @@ export default class InputBoxComponent extends ComponentBase implements ICompone ngOnInit(): void { this.baseInit(); - } ngAfterViewInit(): void { - if (this._inputContainer) { - let inputOptions: IInputOptions = { - placeholder: '', - ariaLabel: '', - validationOptions: { - validation: () => { - if (this.valid) { - return undefined; - } else { - return { - content: this._input.inputElement.validationMessage || nls.localize('invalidValueError', 'Invalid value'), - type: MessageType.ERROR - }; - } + let inputOptions: IInputOptions = { + placeholder: '', + ariaLabel: '', + validationOptions: { + validation: () => { + if (this.valid) { + return undefined; + } else { + return { + content: this.inputElement.inputElement.validationMessage || nls.localize('invalidValueError', 'Invalid value'), + type: MessageType.ERROR + }; } - }, - useDefaultValidation: true - }; - + } + }, + useDefaultValidation: true + }; + if (this._inputContainer) { this._input = new InputBox(this._inputContainer.nativeElement, this.contextViewService, inputOptions); - this._validations.push(() => !this._input.inputElement.validationMessage); + this.registerInput(this._input, () => !this.multiline); - this._register(this._input); - this._register(attachInputBoxStyler(this._input, this.themeService)); - this._register(this._input.onDidChange(e => { - this.value = this._input.value; - this._onEventEmitter.fire({ - eventType: ComponentEventType.onDidChange, - args: e - }); + } + if (this._textareaContainer) { + let textAreaInputOptions = Object.assign({}, inputOptions, { flexibleHeight: true }); + this._textAreaInput = new InputBox(this._textareaContainer.nativeElement, this.contextViewService, textAreaInputOptions); + this.registerInput(this._textAreaInput, () => this.multiline); + } + } + + private get inputElement(): InputBox { + return this.multiline ? this._textAreaInput : this._input; + } + + private registerInput(input: InputBox, checkOption: () => boolean): void { + if (input) { + this._validations.push(() => !input.inputElement.validationMessage); + + this._register(input); + this._register(attachInputBoxStyler(input, this.themeService)); + this._register(input.onDidChange(e => { + if (checkOption()) { + this.value = input.value; + this._onEventEmitter.fire({ + eventType: ComponentEventType.onDidChange, + args: e + }); + } })); } } + public getInputBoxDisplay(): string { + return !this.multiline ? '' : 'none'; + } + + public getTextAreaDisplay(): string { + return this.multiline ? '' : 'none'; + } + public validate(): Thenable