Path: blob/main/src/vs/editor/contrib/hover/browser/contentHoverStatusBar.ts
5221 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import * as dom from '../../../../base/browser/dom.js';5import { HoverAction } from '../../../../base/browser/ui/hover/hoverWidget.js';6import { Disposable } from '../../../../base/common/lifecycle.js';7import { IEditorHoverAction, IEditorHoverStatusBar } from './hoverTypes.js';8import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';9import { IHoverService } from '../../../../platform/hover/browser/hover.js';10import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js';1112const $ = dom.$;1314export class EditorHoverStatusBar extends Disposable implements IEditorHoverStatusBar {1516public readonly hoverElement: HTMLElement;17public readonly actions: HoverAction[] = [];1819private readonly actionsElement: HTMLElement;20private _hasContent: boolean = false;2122public get hasContent() {23return this._hasContent;24}2526constructor(27@IKeybindingService private readonly _keybindingService: IKeybindingService,28@IHoverService private readonly _hoverService: IHoverService,29) {30super();31this.hoverElement = $('div.hover-row.status-bar');32this.hoverElement.tabIndex = 0;33this.actionsElement = dom.append(this.hoverElement, $('div.actions'));34}3536public addAction(37actionOptions: {38label: string;39iconClass?: string; run: (target: HTMLElement) => void;40commandId: string;41}): IEditorHoverAction {4243const keybinding = this._keybindingService.lookupKeybinding(actionOptions.commandId);44const keybindingLabel = keybinding ? keybinding.getLabel() : null;45this._hasContent = true;46const action = this._register(HoverAction.render(this.actionsElement, actionOptions, keybindingLabel));47this._register(this._hoverService.setupManagedHover(getDefaultHoverDelegate('element'), action.actionContainer, action.actionRenderedLabel));48this.actions.push(action);49return action;50}5152public append(element: HTMLElement): HTMLElement {53const result = dom.append(this.actionsElement, element);54this._hasContent = true;55return result;56}57}585960