4446b1eea58c28b01f374c1882731c93532a7d9539d17517e6b931c3ac6a08fc29f7308f0f66f1411a2a788fea0494cb372aed291fcb1934523696b89a6d25 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. const defaultOptions = {
  48. idPrefix: 'quickInput_',
  49. container: host.container,
  50. ignoreFocusOut: () => false,
  51. isScreenReaderOptimized: () => this.accessibilityService.isScreenReaderOptimized(),
  52. backKeybindingLabel: () => undefined,
  53. setContextKey: (id) => this.setContextKey(id),
  54. returnFocus: () => host.focus(),
  55. createList: (user, container, delegate, renderers, options) => this.instantiationService.createInstance(WorkbenchList, user, container, delegate, renderers, options),
  56. styles: this.computeStyles()
  57. };
  58. const controller = this._register(new QuickInputController(Object.assign(Object.assign({}, defaultOptions), options)));
  59. controller.layout(host.dimension, host.offset.quickPickTop);
  60. // Layout changes
  61. this._register(host.onDidLayout(dimension => controller.layout(dimension, host.offset.quickPickTop)));
  62. // Context keys
  63. this._register(controller.onShow(() => this.resetContextKeys()));
  64. this._register(controller.onHide(() => this.resetContextKeys()));
  65. return controller;
  66. }
  67. setContextKey(id) {
  68. let key;
  69. if (id) {
  70. key = this.contexts.get(id);
  71. if (!key) {
  72. key = new RawContextKey(id, false)
  73. .bindTo(this.contextKeyService);
  74. this.contexts.set(id, key);
  75. }
  76. }
  77. if (key && key.get()) {
  78. return; // already active context
  79. }
  80. this.resetContextKeys();
  81. key === null || key === void 0 ? void 0 : key.set(true);
  82. }
  83. resetContextKeys() {
  84. this.contexts.forEach(context => {
  85. if (context.get()) {
  86. context.reset();
  87. }
  88. });
  89. }
  90. pick(picks, options = {}, token = CancellationToken.None) {
  91. return this.controller.pick(picks, options, token);
  92. }
  93. createQuickPick() {
  94. return this.controller.createQuickPick();
  95. }
  96. updateStyles() {
  97. this.controller.applyStyles(this.computeStyles());
  98. }
  99. computeStyles() {
  100. return {
  101. widget: Object.assign({}, computeStyles(this.theme, {
  102. quickInputBackground,
  103. quickInputForeground,
  104. quickInputTitleBackground,
  105. contrastBorder,
  106. widgetShadow
  107. })),
  108. inputBox: computeStyles(this.theme, {
  109. inputForeground,
  110. inputBackground,
  111. inputBorder,
  112. inputValidationInfoBackground,
  113. inputValidationInfoForeground,
  114. inputValidationInfoBorder,
  115. inputValidationWarningBackground,
  116. inputValidationWarningForeground,
  117. inputValidationWarningBorder,
  118. inputValidationErrorBackground,
  119. inputValidationErrorForeground,
  120. inputValidationErrorBorder
  121. }),
  122. countBadge: computeStyles(this.theme, {
  123. badgeBackground,
  124. badgeForeground,
  125. badgeBorder: contrastBorder
  126. }),
  127. button: computeStyles(this.theme, {
  128. buttonForeground,
  129. buttonBackground,
  130. buttonHoverBackground,
  131. buttonBorder: contrastBorder
  132. }),
  133. progressBar: computeStyles(this.theme, {
  134. progressBarBackground
  135. }),
  136. keybindingLabel: computeStyles(this.theme, {
  137. keybindingLabelBackground,
  138. keybindingLabelForeground,
  139. keybindingLabelBorder,
  140. keybindingLabelBottomBorder,
  141. keybindingLabelShadow: widgetShadow
  142. }),
  143. list: computeStyles(this.theme, {
  144. listBackground: quickInputBackground,
  145. // Look like focused when inactive.
  146. listInactiveFocusForeground: quickInputListFocusForeground,
  147. listInactiveSelectionIconForeground: quickInputListFocusIconForeground,
  148. listInactiveFocusBackground: quickInputListFocusBackground,
  149. listFocusOutline: activeContrastBorder,
  150. listInactiveFocusOutline: activeContrastBorder,
  151. pickerGroupBorder,
  152. pickerGroupForeground
  153. })
  154. };
  155. }
  156. };
  157. QuickInputService = __decorate([
  158. __param(0, IInstantiationService),
  159. __param(1, IContextKeyService),
  160. __param(2, IThemeService),
  161. __param(3, IAccessibilityService),
  162. __param(4, ILayoutService)
  163. ], QuickInputService);
  164. export { QuickInputService };