quickInputBox.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import * as dom from '../../../browser/dom.js';
  6. import { StandardKeyboardEvent } from '../../../browser/keyboardEvent.js';
  7. import { StandardMouseEvent } from '../../../browser/mouseEvent.js';
  8. import { InputBox } from '../../../browser/ui/inputbox/inputBox.js';
  9. import { Disposable } from '../../../common/lifecycle.js';
  10. import Severity from '../../../common/severity.js';
  11. import './media/quickInput.css';
  12. const $ = dom.$;
  13. export class QuickInputBox extends Disposable {
  14. constructor(parent) {
  15. super();
  16. this.parent = parent;
  17. this.onKeyDown = (handler) => {
  18. return dom.addDisposableListener(this.inputBox.inputElement, dom.EventType.KEY_DOWN, (e) => {
  19. handler(new StandardKeyboardEvent(e));
  20. });
  21. };
  22. this.onMouseDown = (handler) => {
  23. return dom.addDisposableListener(this.inputBox.inputElement, dom.EventType.MOUSE_DOWN, (e) => {
  24. handler(new StandardMouseEvent(e));
  25. });
  26. };
  27. this.onDidChange = (handler) => {
  28. return this.inputBox.onDidChange(handler);
  29. };
  30. this.container = dom.append(this.parent, $('.quick-input-box'));
  31. this.inputBox = this._register(new InputBox(this.container, undefined));
  32. }
  33. get value() {
  34. return this.inputBox.value;
  35. }
  36. set value(value) {
  37. this.inputBox.value = value;
  38. }
  39. select(range = null) {
  40. this.inputBox.select(range);
  41. }
  42. isSelectionAtEnd() {
  43. return this.inputBox.isSelectionAtEnd();
  44. }
  45. get placeholder() {
  46. return this.inputBox.inputElement.getAttribute('placeholder') || '';
  47. }
  48. set placeholder(placeholder) {
  49. this.inputBox.setPlaceHolder(placeholder);
  50. }
  51. get ariaLabel() {
  52. return this.inputBox.getAriaLabel();
  53. }
  54. set ariaLabel(ariaLabel) {
  55. this.inputBox.setAriaLabel(ariaLabel);
  56. }
  57. get password() {
  58. return this.inputBox.inputElement.type === 'password';
  59. }
  60. set password(password) {
  61. this.inputBox.inputElement.type = password ? 'password' : 'text';
  62. }
  63. setAttribute(name, value) {
  64. this.inputBox.inputElement.setAttribute(name, value);
  65. }
  66. removeAttribute(name) {
  67. this.inputBox.inputElement.removeAttribute(name);
  68. }
  69. showDecoration(decoration) {
  70. if (decoration === Severity.Ignore) {
  71. this.inputBox.hideMessage();
  72. }
  73. else {
  74. this.inputBox.showMessage({ type: decoration === Severity.Info ? 1 /* INFO */ : decoration === Severity.Warning ? 2 /* WARNING */ : 3 /* ERROR */, content: '' });
  75. }
  76. }
  77. stylesForType(decoration) {
  78. return this.inputBox.stylesForType(decoration === Severity.Info ? 1 /* INFO */ : decoration === Severity.Warning ? 2 /* WARNING */ : 3 /* ERROR */);
  79. }
  80. setFocus() {
  81. this.inputBox.focus();
  82. }
  83. layout() {
  84. this.inputBox.layout();
  85. }
  86. style(styles) {
  87. this.inputBox.style(styles);
  88. }
  89. }