-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e97953a
commit 537b1f0
Showing
4 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/vs/workbench/contrib/terminal/browser/terminalEditorIconManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters