quickInput.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. import { CancellationToken } from '../../../base/common/cancellation.js';
  15. import { QuickInputController } from '../../../base/parts/quickinput/browser/quickInput.js';
  16. import { IAccessibilityService } from '../../accessibility/common/accessibility.js';
  17. import { IContextKeyService, RawContextKey } from '../../contextkey/common/contextkey.js';
  18. import { IInstantiationService } from '../../instantiation/common/instantiation.js';
  19. import { ILayoutService } from '../../layout/browser/layoutService.js';
  20. import { WorkbenchList } from '../../list/browser/listService.js';
  21. import { QuickAccessController } from './quickAccess.js';
  22. import { activeContrastBorder, badgeBackground, badgeForeground, buttonBackground, buttonForeground, buttonHoverBackground, contrastBorder, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, keybindingLabelBackground, keybindingLabelBorder, keybindingLabelBottomBorder, keybindingLabelForeground, pickerGroupBorder, pickerGroupForeground, progressBarBackground, quickInputBackground, quickInputForeground, quickInputListFocusBackground, quickInputListFocusForeground, quickInputListFocusIconForeground, quickInputTitleBackground, widgetShadow } from '../../theme/common/colorRegistry.js';
  23. import { computeStyles } from '../../theme/common/styler.js';
  24. import { IThemeService, Themable } from '../../theme/common/themeService.js';
  25. let QuickInputService = class QuickInputService extends Themable {
  26. constructor(instantiationService, contextKeyService, themeService, accessibilityService, layoutService) {
  27. super(themeService);
  28. this.instantiationService = instantiationService;
  29. this.contextKeyService = contextKeyService;
  30. this.accessibilityService = accessibilityService;
  31. this.layoutService = layoutService;
  32. this.contexts = new Map();
  33. }
  34. get controller() {
  35. if (!this._controller) {
  36. this._controller = this._register(this.createController());
  37. }
  38. return this._controller;
  39. }
  40. get quickAccess() {
  41. if (!this._quickAccess) {
  42. this._quickAccess = this._register(this.instantiationService.createInstance(QuickAccessController));
  43. }
  44. return this._quickAccess;
  45. }
  46. createController(host = this.layoutService, options) {
  47. var _a, _b;
  48. const defaultOptions = {
  49. idPrefix: 'quickInput_',
  50. container: host.container,
  51. ignoreFocusOut: () => false,
  52. isScreenReaderOptimized: () => this.accessibilityService.isScreenReaderOptimized(),
  53. backKeybindingLabel: () => undefined,
  54. setContextKey: (id) => this.setContextKey(id),
  55. returnFocus: () => host.focus(),
  56. createList: (user, container, delegate, renderers, options) => this.instantiationService.createInstance(WorkbenchList, user, container, delegate, renderers, options),
  57. styles: this.computeStyles()
  58. };
  59. const controller = this._register(new QuickInputController(Object.assign(Object.assign({}, defaultOptions), options)));
  60. controller.layout(host.dimension, (_b = (_a = host.offset) === null || _a === void 0 ? void 0 : _a.top) !== null && _b !== void 0 ? _b : 0);
  61. // Layout changes
  62. this._register(host.onDidLayout(dimension => { var _a, _b; return controller.layout(dimension, (_b = (_a = host.offset) === null || _a === void 0 ? void 0 : _a.top) !== null && _b !== void 0 ? _b : 0); }));
  63. // Context keys
  64. this._register(controller.onShow(() => this.resetContextKeys()));
  65. this._register(controller.onHide(() => this.resetContextKeys()));
  66. return controller;
  67. }
  68. setContextKey(id) {
  69. let key;
  70. if (id) {
  71. key = this.contexts.get(id);
  72. if (!key) {
  73. key = new RawContextKey(id, false)
  74. .bindTo(this.contextKeyService);
  75. this.contexts.set(id, key);
  76. }
  77. }
  78. if (key && key.get()) {
  79. return; // already active context
  80. }
  81. this.resetContextKeys();
  82. if (key) {
  83. key.set(true);
  84. }
  85. }
  86. resetContextKeys() {
  87. this.contexts.forEach(context => {
  88. if (context.get()) {
  89. context.reset();
  90. }
  91. });
  92. }
  93. pick(picks, options = {}, token = CancellationToken.None) {
  94. return this.controller.pick(picks, options, token);
  95. }
  96. createQuickPick() {
  97. return this.controller.createQuickPick();
  98. }
  99. updateStyles() {
  100. this.controller.applyStyles(this.computeStyles());
  101. }
  102. computeStyles() {
  103. return {
  104. widget: Object.assign({}, computeStyles(this.theme, {
  105. quickInputBackground,
  106. quickInputForeground,
  107. quickInputTitleBackground,
  108. contrastBorder,
  109. widgetShadow
  110. })),
  111. inputBox: computeStyles(this.theme, {
  112. inputForeground,
  113. inputBackground,
  114. inputBorder,
  115. inputValidationInfoBackground,
  116. inputValidationInfoForeground,
  117. inputValidationInfoBorder,
  118. inputValidationWarningBackground,
  119. inputValidationWarningForeground,
  120. inputValidationWarningBorder,
  121. inputValidationErrorBackground,
  122. inputValidationErrorForeground,
  123. inputValidationErrorBorder
  124. }),
  125. countBadge: computeStyles(this.theme, {
  126. badgeBackground,
  127. badgeForeground,
  128. badgeBorder: contrastBorder
  129. }),
  130. button: computeStyles(this.theme, {
  131. buttonForeground,
  132. buttonBackground,
  133. buttonHoverBackground,
  134. buttonBorder: contrastBorder
  135. }),
  136. progressBar: computeStyles(this.theme, {
  137. progressBarBackground
  138. }),
  139. keybindingLabel: computeStyles(this.theme, {
  140. keybindingLabelBackground,
  141. keybindingLabelForeground,
  142. keybindingLabelBorder,
  143. keybindingLabelBottomBorder,
  144. keybindingLabelShadow: widgetShadow
  145. }),
  146. list: computeStyles(this.theme, {
  147. listBackground: quickInputBackground,
  148. // Look like focused when inactive.
  149. listInactiveFocusForeground: quickInputListFocusForeground,
  150. listInactiveSelectionIconForeground: quickInputListFocusIconForeground,
  151. listInactiveFocusBackground: quickInputListFocusBackground,
  152. listFocusOutline: activeContrastBorder,
  153. listInactiveFocusOutline: activeContrastBorder,
  154. pickerGroupBorder,
  155. pickerGroupForeground
  156. })
  157. };
  158. }
  159. };
  160. QuickInputService = __decorate([
  161. __param(0, IInstantiationService),
  162. __param(1, IContextKeyService),
  163. __param(2, IThemeService),
  164. __param(3, IAccessibilityService),
  165. __param(4, ILayoutService)
  166. ], QuickInputService);
  167. export { QuickInputService };