Skip to content

Commit

Permalink
Support relaunch hover action
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Apr 22, 2021
1 parent 2130042 commit 5460fcf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal
import { localize } from 'vs/nls';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { Codicon } from 'vs/base/common/codicons';
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover';

export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo {
readonly requiresAction = true;
Expand Down Expand Up @@ -59,7 +60,7 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo {
return Codicon.warning;
}

getActions(): { label: string, iconClass?: string, run: () => void, commandId: string }[] {
getActions(): IHoverAction[] {
return [{
label: localize('relaunchTerminalLabel', "Relaunch terminal"),
run: () => this._terminalService.getInstanceFromId(this._terminalId)?.relaunch(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
id: TerminalStatus.RelaunchNeeded,
severity: Severity.Warning,
icon: Codicon.warning,
tooltip: info.getInfo()
tooltip: info.getInfo(),
hoverActions: info.getActions ? info.getActions() : undefined
});
}
if (disposable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import Severity from 'vs/base/common/severity';
import { IHoverAction } from 'vs/workbench/services/hover/browser/hover';

/**
* The set of _internal_ terminal statuses, other components building on the terminal should put
Expand Down Expand Up @@ -35,6 +36,10 @@ export interface ITerminalStatus {
* What to show for this status in the terminal's hover.
*/
tooltip?: string | undefined;
/**
* Actions to expose on hover.
*/
hoverActions?: IHoverAction[];
}

export interface ITerminalStatusList {
Expand Down
26 changes: 19 additions & 7 deletions src/vs/workbench/contrib/terminal/browser/terminalTabsWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
import { TerminalDecorationsProvider } from 'vs/workbench/contrib/terminal/browser/terminalDecorationsProvider';
import { DEFAULT_LABELS_CONTAINER, IResourceLabel, ResourceLabels } from 'vs/workbench/browser/labels';
import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations';
import { IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { IHoverAction, IHoverService } from 'vs/workbench/services/hover/browser/hover';
import Severity from 'vs/base/common/severity';
import { DisposableStore } from 'vs/base/common/lifecycle';

Expand Down Expand Up @@ -141,14 +141,19 @@ class TerminalTabsRenderer implements ITreeRenderer<ITerminalInstance, never, IT
(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement).classList.add('force-no-twistie');

const element = DOM.append(container, $('.terminal-tabs-entry'));

const context: { hoverActions?: IHoverAction[] } = {};
const label = this._labels.create(element, {
supportHighlights: true,
supportDescriptionHighlights: true,
supportIcons: true,
hoverDelegate: {
delay: this._configurationService.getValue<number>('workbench.hover.delay'),
showHover: e => this._hoverService.showHover(e)
showHover: options => {
return this._hoverService.showHover({
...options,
actions: context.hoverActions
});
}
}
});

Expand All @@ -164,7 +169,8 @@ class TerminalTabsRenderer implements ITreeRenderer<ITerminalInstance, never, IT
return {
element,
label,
actionBar
actionBar,
context
};
}

Expand Down Expand Up @@ -197,9 +203,12 @@ class TerminalTabsRenderer implements ITreeRenderer<ITerminalInstance, never, IT

let title = instance.title;
const statuses = instance.statusList.statuses;
if (statuses.length) {
title += `\n\n---\n\n`;
title += statuses.map(e => `${e.tooltip || e.id}`);
template.context.hoverActions = [];
for (const status of statuses) {
title += `\n\n---\n\n${status.tooltip || status.id}`;
if (status.hoverActions) {
template.context.hoverActions.push(...status.hoverActions);
}
}

let label: string;
Expand Down Expand Up @@ -265,5 +274,8 @@ interface ITerminalTabEntryTemplate {
element: HTMLElement;
label: IResourceLabel;
actionBar: ActionBar;
context: {
hoverActions?: IHoverAction[];
};
elementDispoables?: DisposableStore;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,10 @@ export interface IEnvironmentVariableInfo {
readonly requiresAction: boolean;
getInfo(): string;
getIcon(): ThemeIcon;
getActions?(): { label: string, iconClass?: string, run: () => void, commandId: string }[];
getActions?(): {
label: string;
commandId: string;
iconClass?: string;
run(target: HTMLElement): void;
}[];
}

0 comments on commit 5460fcf

Please sign in to comment.