Skip to content

Commit

Permalink
add icon manager
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Jun 15, 2021
1 parent e97953a commit 537b1f0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ export interface ITerminalService {
setEditable(instance: ITerminalInstance, data: IEditableData | null): Promise<void>;
instanceIsSplit(instance: ITerminalInstance): boolean;
safeDisposeTerminal(instance: ITerminalInstance): Promise<void>;

getPlatformKey(): Promise<string>;
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ export class TerminalEditor extends EditorPane {
if (!this._editorInput?.terminalInstance) {
return;
}

if (!this._isAttached) {
this._editorInput.terminalInstance.attachToElement(this._parentElement!);
this._isAttached = true;
}
this._editorInput.terminalInstance.setVisible(visible);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as dom from 'vs/base/browser/dom';
import { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TerminalIcon, TerminalSettingPrefix } from 'vs/platform/terminal/common/terminal';
import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ILifecycleService, LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';

export class TerminalEditorIconManager implements IDisposable {

private readonly _icons = new Map<string, TerminalIcon>();

private _styleElement: HTMLStyleElement | undefined;

constructor(
@ILifecycleService private readonly _lifecycleService: ILifecycleService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@ITerminalService terminalService: ITerminalService
) {
_configurationService.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(TerminalSettingPrefix.DefaultProfile + terminalService.getPlatformKey()) ||
e.affectsConfiguration(TerminalSettingPrefix.Profiles + terminalService.getPlatformKey())) {
this._updateStyleSheet();
}
});
}

dispose() {
this._styleElement?.remove();
this._styleElement = undefined;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
private get styleElement(): HTMLStyleElement {
if (!this._styleElement) {
this._styleElement = dom.createStyleSheet();
this._styleElement.className = 'terminal-icons';
}
return this._styleElement;
}

public setIcons(
webviewId: string,
iconPath?: TerminalIcon
) {
if (iconPath) {
this._icons.set(webviewId, iconPath);
} else {
this._icons.delete(webviewId);
}

this._updateStyleSheet();
}

private async _updateStyleSheet() {
await this._lifecycleService.when(LifecyclePhase.Starting);

const cssRules: string[] = [];
if (this._configurationService.getValue('workbench.iconTheme') !== null) {
for (const [key, value] of this._icons) {
const webviewSelector = `.show-file-icons .terminal-${key}-name-file-icon::before`;
try {
if (typeof value === 'object' && 'light' in value && 'dark' in value) {
cssRules.push(
`.monaco-workbench.vs ${webviewSelector} { content: ""; background-image: ${dom.asCSSUrl(value.light)}; }`,
`.monaco-workbench.vs-dark ${webviewSelector}, .monaco-workbench.hc-black ${webviewSelector} { content: ""; background-image: ${dom.asCSSUrl(value.dark)}; }`
);
} else if (URI.isUri(value)) {

} else {

}
} catch {
// noop
}
}
}
this.styleElement.textContent = cssRules.join('\n');
}
}
10 changes: 5 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export class TerminalService implements ITerminalService {
lifecycleService.onWillShutdown(e => this._onWillShutdown(e));

this._configurationService.onDidChangeConfiguration(async e => {
if (e.affectsConfiguration(TerminalSettingPrefix.DefaultProfile + this._getPlatformKey()) ||
e.affectsConfiguration(TerminalSettingPrefix.Profiles + this._getPlatformKey()) ||
if (e.affectsConfiguration(TerminalSettingPrefix.DefaultProfile + this.getPlatformKey()) ||
e.affectsConfiguration(TerminalSettingPrefix.Profiles + this.getPlatformKey()) ||
e.affectsConfiguration(TerminalSettingId.UseWslProfiles)) {
this._refreshAvailableProfiles();
}
Expand Down Expand Up @@ -380,7 +380,7 @@ export class TerminalService implements ITerminalService {
if (!this._primaryOffProcessTerminalService) {
return this._availableProfiles || [];
}
const platform = await this._getPlatformKey();
const platform = await this.getPlatformKey();
return this._primaryOffProcessTerminalService?.getProfiles(this._configurationService.getValue(`${TerminalSettingPrefix.Profiles}${platform}`), this._configurationService.getValue(`${TerminalSettingPrefix.DefaultProfile}${platform}`), includeDetectedProfiles);
}

Expand Down Expand Up @@ -911,7 +911,7 @@ export class TerminalService implements ITerminalService {



private async _getPlatformKey(): Promise<string> {
async getPlatformKey(): Promise<string> {
const env = await this._remoteAgentService.getEnvironment();
if (env) {
return env.os === OperatingSystem.Windows ? 'windows' : (env.os === OperatingSystem.Macintosh ? 'osx' : 'linux');
Expand All @@ -922,7 +922,7 @@ export class TerminalService implements ITerminalService {
async showProfileQuickPick(type: 'setDefault' | 'createInstance', cwd?: string | URI): Promise<ITerminalInstance | undefined> {
let keyMods: IKeyMods | undefined;
const profiles = await this._detectProfiles(true);
const platformKey = await this._getPlatformKey();
const platformKey = await this.getPlatformKey();

const options: IPickOptions<IProfileQuickPickItem> = {
placeHolder: type === 'createInstance' ? nls.localize('terminal.integrated.selectProfileToCreate', "Select the terminal profile to create") : nls.localize('terminal.integrated.chooseDefaultProfile', "Select your default terminal profile"),
Expand Down

0 comments on commit 537b1f0

Please sign in to comment.