Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/hover/browser/contentHoverStatusBar.ts
5221 views
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 * as dom from '../../../../base/browser/dom.js';
6
import { HoverAction } from '../../../../base/browser/ui/hover/hoverWidget.js';
7
import { Disposable } from '../../../../base/common/lifecycle.js';
8
import { IEditorHoverAction, IEditorHoverStatusBar } from './hoverTypes.js';
9
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
10
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
11
import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js';
12
13
const $ = dom.$;
14
15
export class EditorHoverStatusBar extends Disposable implements IEditorHoverStatusBar {
16
17
public readonly hoverElement: HTMLElement;
18
public readonly actions: HoverAction[] = [];
19
20
private readonly actionsElement: HTMLElement;
21
private _hasContent: boolean = false;
22
23
public get hasContent() {
24
return this._hasContent;
25
}
26
27
constructor(
28
@IKeybindingService private readonly _keybindingService: IKeybindingService,
29
@IHoverService private readonly _hoverService: IHoverService,
30
) {
31
super();
32
this.hoverElement = $('div.hover-row.status-bar');
33
this.hoverElement.tabIndex = 0;
34
this.actionsElement = dom.append(this.hoverElement, $('div.actions'));
35
}
36
37
public addAction(
38
actionOptions: {
39
label: string;
40
iconClass?: string; run: (target: HTMLElement) => void;
41
commandId: string;
42
}): IEditorHoverAction {
43
44
const keybinding = this._keybindingService.lookupKeybinding(actionOptions.commandId);
45
const keybindingLabel = keybinding ? keybinding.getLabel() : null;
46
this._hasContent = true;
47
const action = this._register(HoverAction.render(this.actionsElement, actionOptions, keybindingLabel));
48
this._register(this._hoverService.setupManagedHover(getDefaultHoverDelegate('element'), action.actionContainer, action.actionRenderedLabel));
49
this.actions.push(action);
50
return action;
51
}
52
53
public append(element: HTMLElement): HTMLElement {
54
const result = dom.append(this.actionsElement, element);
55
this._hasContent = true;
56
return result;
57
}
58
}
59
60