901ec03baef2347f9492b1c37aa0a2dc95f7d6b7174ab4d21091c1a284f5e873ae16957023216d7813557d0480b342abfac3621eecf3d566ba758bf2790b12 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 './overlayWidgets.css';
  6. import { createFastDomNode } from '../../../../base/browser/fastDomNode.js';
  7. import { PartFingerprints, ViewPart } from '../../view/viewPart.js';
  8. export class ViewOverlayWidgets extends ViewPart {
  9. constructor(context) {
  10. super(context);
  11. const options = this._context.configuration.options;
  12. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  13. this._widgets = {};
  14. this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth;
  15. this._minimapWidth = layoutInfo.minimap.minimapWidth;
  16. this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight;
  17. this._editorHeight = layoutInfo.height;
  18. this._editorWidth = layoutInfo.width;
  19. this._domNode = createFastDomNode(document.createElement('div'));
  20. PartFingerprints.write(this._domNode, 4 /* PartFingerprint.OverlayWidgets */);
  21. this._domNode.setClassName('overlayWidgets');
  22. }
  23. dispose() {
  24. super.dispose();
  25. this._widgets = {};
  26. }
  27. getDomNode() {
  28. return this._domNode;
  29. }
  30. // ---- begin view event handlers
  31. onConfigurationChanged(e) {
  32. const options = this._context.configuration.options;
  33. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  34. this._verticalScrollbarWidth = layoutInfo.verticalScrollbarWidth;
  35. this._minimapWidth = layoutInfo.minimap.minimapWidth;
  36. this._horizontalScrollbarHeight = layoutInfo.horizontalScrollbarHeight;
  37. this._editorHeight = layoutInfo.height;
  38. this._editorWidth = layoutInfo.width;
  39. return true;
  40. }
  41. // ---- end view event handlers
  42. addWidget(widget) {
  43. const domNode = createFastDomNode(widget.getDomNode());
  44. this._widgets[widget.getId()] = {
  45. widget: widget,
  46. preference: null,
  47. domNode: domNode
  48. };
  49. // This is sync because a widget wants to be in the dom
  50. domNode.setPosition('absolute');
  51. domNode.setAttribute('widgetId', widget.getId());
  52. this._domNode.appendChild(domNode);
  53. this.setShouldRender();
  54. }
  55. setWidgetPosition(widget, preference) {
  56. const widgetData = this._widgets[widget.getId()];
  57. if (widgetData.preference === preference) {
  58. return false;
  59. }
  60. widgetData.preference = preference;
  61. this.setShouldRender();
  62. return true;
  63. }
  64. removeWidget(widget) {
  65. const widgetId = widget.getId();
  66. if (this._widgets.hasOwnProperty(widgetId)) {
  67. const widgetData = this._widgets[widgetId];
  68. const domNode = widgetData.domNode.domNode;
  69. delete this._widgets[widgetId];
  70. domNode.parentNode.removeChild(domNode);
  71. this.setShouldRender();
  72. }
  73. }
  74. _renderWidget(widgetData) {
  75. const domNode = widgetData.domNode;
  76. if (widgetData.preference === null) {
  77. domNode.setTop('');
  78. return;
  79. }
  80. if (widgetData.preference === 0 /* OverlayWidgetPositionPreference.TOP_RIGHT_CORNER */) {
  81. domNode.setTop(0);
  82. domNode.setRight((2 * this._verticalScrollbarWidth) + this._minimapWidth);
  83. }
  84. else if (widgetData.preference === 1 /* OverlayWidgetPositionPreference.BOTTOM_RIGHT_CORNER */) {
  85. const widgetHeight = domNode.domNode.clientHeight;
  86. domNode.setTop((this._editorHeight - widgetHeight - 2 * this._horizontalScrollbarHeight));
  87. domNode.setRight((2 * this._verticalScrollbarWidth) + this._minimapWidth);
  88. }
  89. else if (widgetData.preference === 2 /* OverlayWidgetPositionPreference.TOP_CENTER */) {
  90. domNode.setTop(0);
  91. domNode.domNode.style.right = '50%';
  92. }
  93. }
  94. prepareRender(ctx) {
  95. // Nothing to read
  96. }
  97. render(ctx) {
  98. this._domNode.setWidth(this._editorWidth);
  99. const keys = Object.keys(this._widgets);
  100. for (let i = 0, len = keys.length; i < len; i++) {
  101. const widgetId = keys[i];
  102. this._renderWidget(this._widgets[widgetId]);
  103. }
  104. }
  105. }