84be6e0d6a589a12920a5f2a48e1e0cda81866c141d74324be151957259dbf8011949c699e47658615b5188699bb117d351c94f3fdc54695a9afd7354c5880 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 { ContextView } from '../../../base/browser/ui/contextview/contextview.js';
  15. import { Disposable, toDisposable } from '../../../base/common/lifecycle.js';
  16. import { ILayoutService } from '../../layout/browser/layoutService.js';
  17. let ContextViewService = class ContextViewService extends Disposable {
  18. constructor(layoutService) {
  19. super();
  20. this.layoutService = layoutService;
  21. this.currentViewDisposable = Disposable.None;
  22. this.container = layoutService.hasContainer ? layoutService.container : null;
  23. this.contextView = this._register(new ContextView(this.container, 1 /* ContextViewDOMPosition.ABSOLUTE */));
  24. this.layout();
  25. this._register(layoutService.onDidLayout(() => this.layout()));
  26. }
  27. // ContextView
  28. setContainer(container, domPosition) {
  29. this.contextView.setContainer(container, domPosition || 1 /* ContextViewDOMPosition.ABSOLUTE */);
  30. }
  31. showContextView(delegate, container, shadowRoot) {
  32. if (container) {
  33. if (container !== this.container || this.shadowRoot !== shadowRoot) {
  34. this.container = container;
  35. this.setContainer(container, shadowRoot ? 3 /* ContextViewDOMPosition.FIXED_SHADOW */ : 2 /* ContextViewDOMPosition.FIXED */);
  36. }
  37. }
  38. else {
  39. if (this.layoutService.hasContainer && this.container !== this.layoutService.container) {
  40. this.container = this.layoutService.container;
  41. this.setContainer(this.container, 1 /* ContextViewDOMPosition.ABSOLUTE */);
  42. }
  43. }
  44. this.shadowRoot = shadowRoot;
  45. this.contextView.show(delegate);
  46. const disposable = toDisposable(() => {
  47. if (this.currentViewDisposable === disposable) {
  48. this.hideContextView();
  49. }
  50. });
  51. this.currentViewDisposable = disposable;
  52. return disposable;
  53. }
  54. getContextViewElement() {
  55. return this.contextView.getViewElement();
  56. }
  57. layout() {
  58. this.contextView.layout();
  59. }
  60. hideContextView(data) {
  61. this.contextView.hide(data);
  62. }
  63. };
  64. ContextViewService = __decorate([
  65. __param(0, ILayoutService)
  66. ], ContextViewService);
  67. export { ContextViewService };