From bd0324f40607552612138303519298abc2ea7f6f Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 27 Oct 2017 12:51:08 +0200 Subject: [PATCH] ExplorerDecoariontsProvider fixes #35075 --- src/vs/platform/theme/common/colorRegistry.ts | 1 + .../views/explorerDecorationsProvider.ts | 45 +++++++++++++++++++ .../parts/files/browser/views/explorerView.ts | 7 ++- .../files/browser/views/explorerViewer.ts | 4 -- .../parts/files/common/explorerModel.ts | 2 +- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/vs/workbench/parts/files/browser/views/explorerDecorationsProvider.ts diff --git a/src/vs/platform/theme/common/colorRegistry.ts b/src/vs/platform/theme/common/colorRegistry.ts index 5c324011656..a30413c4706 100644 --- a/src/vs/platform/theme/common/colorRegistry.ts +++ b/src/vs/platform/theme/common/colorRegistry.ts @@ -196,6 +196,7 @@ export const listHoverBackground = registerColor('list.hoverBackground', { dark: export const listHoverForeground = registerColor('list.hoverForeground', { dark: null, light: null, hc: null }, nls.localize('listHoverForeground', "List/Tree foreground when hovering over items using the mouse.")); export const listDropBackground = registerColor('list.dropBackground', { dark: listFocusBackground, light: listFocusBackground, hc: null }, nls.localize('listDropBackground', "List/Tree drag and drop background when moving items around using the mouse.")); export const listHighlightForeground = registerColor('list.highlightForeground', { dark: '#0097fb', light: '#007acc', hc: focusBorder }, nls.localize('highlight', 'List/Tree foreground color of the match highlights when searching inside the list/tree.')); +export const listInvalidItemForeground = registerColor('list.invalidItemForeground', { dark: '#B89500', light: '#B89500', hc: '#B89500' }, nls.localize('invalidItemForeground', 'List/Tree foreground color for invalid items, for example an unresolved root in explorer.')); export const pickerGroupForeground = registerColor('pickerGroup.foreground', { dark: Color.fromHex('#0097FB').transparent(0.6), light: Color.fromHex('#007ACC').transparent(0.6), hc: Color.white }, nls.localize('pickerGroupForeground', "Quick picker color for grouping labels.")); export const pickerGroupBorder = registerColor('pickerGroup.border', { dark: '#3F3F46', light: '#CCCEDB', hc: Color.white }, nls.localize('pickerGroupBorder', "Quick picker color for grouping borders.")); diff --git a/src/vs/workbench/parts/files/browser/views/explorerDecorationsProvider.ts b/src/vs/workbench/parts/files/browser/views/explorerDecorationsProvider.ts new file mode 100644 index 00000000000..54295a7d1d7 --- /dev/null +++ b/src/vs/workbench/parts/files/browser/views/explorerDecorationsProvider.ts @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import URI from 'vs/base/common/uri'; +import Event, { Emitter } from 'vs/base/common/event'; +import { localize } from 'vs/nls'; +import { Model } from 'vs/workbench/parts/files/common/explorerModel'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IDecorationsProvider, IDecorationData } from 'vs/workbench/services/decorations/browser/decorations'; +import { listInvalidItemForeground } from 'vs/platform/theme/common/colorRegistry'; + +export class ExplorerDecorationsProvider implements IDecorationsProvider { + readonly label: string = localize('label', "Explorer"); + private _onDidChange = new Emitter(); + + constructor( + private model: Model, + @IWorkspaceContextService contextService: IWorkspaceContextService + ) { + contextService.onDidChangeWorkspaceFolders(e => { + this._onDidChange.fire(e.changed.map(wf => wf.uri)); + }); + } + + get onDidChange(): Event { + return this._onDidChange.event; + } + + provideDecorations(resource: URI): IDecorationData { + const fileStat = this.model.roots.filter(r => r.resource.toString() === resource.toString()).pop(); + if (fileStat && fileStat.nonexistentRoot) { + return { + tooltip: localize('canNotResolve', "Can not resolve folder"), + letter: '!', + color: listInvalidItemForeground, + }; + } + + return undefined; + } +} diff --git a/src/vs/workbench/parts/files/browser/views/explorerView.ts b/src/vs/workbench/parts/files/browser/views/explorerView.ts index 949ae1400fc..596b7f1a931 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerView.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerView.ts @@ -32,6 +32,7 @@ import { FileStat, Model } from 'vs/workbench/parts/files/common/explorerModel'; import { IListService } from 'vs/platform/list/browser/listService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IPartService } from 'vs/workbench/services/part/common/partService'; +import { ExplorerDecorationsProvider } from 'vs/workbench/parts/files/browser/views/explorerDecorationsProvider'; import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; @@ -45,6 +46,7 @@ import { IWorkbenchThemeService, IFileIconTheme } from 'vs/workbench/services/th import { isLinux } from 'vs/base/common/platform'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { attachListStyler } from 'vs/platform/theme/common/styler'; +import { IDecorationsService } from 'vs/workbench/services/decorations/browser/decorations'; export interface IExplorerViewOptions extends IViewletViewOptions { viewletState: FileViewletState; @@ -98,7 +100,8 @@ export class ExplorerView extends ViewsViewletPanel { @IContextKeyService contextKeyService: IContextKeyService, @IConfigurationService private configurationService: IConfigurationService, @IWorkbenchThemeService private themeService: IWorkbenchThemeService, - @IEnvironmentService private environmentService: IEnvironmentService + @IEnvironmentService private environmentService: IEnvironmentService, + @IDecorationsService decorationService: IDecorationsService ) { super({ ...(options as IViewOptions), ariaHeaderLabel: nls.localize('explorerSection', "Files Explorer Section") }, keybindingService, contextMenuService); @@ -120,6 +123,8 @@ export class ExplorerView extends ViewsViewletPanel { (root: URI) => this.getFileEventsExcludes(root), (event: IConfigurationChangeEvent) => event.affectsConfiguration(FILES_EXCLUDE_CONFIG) ); + + decorationService.registerDecorationsProvider(new ExplorerDecorationsProvider(this.model, contextService)); } private getFileEventsExcludes(root?: URI): glob.IExpression { diff --git a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts index 0b4eae344f6..69bb85dbb2a 100644 --- a/src/vs/workbench/parts/files/browser/views/explorerViewer.ts +++ b/src/vs/workbench/parts/files/browser/views/explorerViewer.ts @@ -313,12 +313,8 @@ export class FileRenderer implements IRenderer { if (!editableData) { templateData.label.element.style.display = 'flex'; const extraClasses = ['explorer-item']; - if (stat.nonexistentRoot) { - extraClasses.push('nonexistent-root'); - } templateData.label.setFile(stat.resource, { hidePath: true, - title: stat.nonexistentRoot ? nls.localize('canNotResolve', "Can not resolve folder {0}", stat.resource.toString()) : undefined, fileKind: stat.isRoot ? FileKind.ROOT_FOLDER : stat.isDirectory ? FileKind.FOLDER : FileKind.FILE, extraClasses, fileDecorations: this.configurationService.getConfiguration().explorer.decorations diff --git a/src/vs/workbench/parts/files/common/explorerModel.ts b/src/vs/workbench/parts/files/common/explorerModel.ts index 33f96015590..3d011a1c2a1 100644 --- a/src/vs/workbench/parts/files/common/explorerModel.ts +++ b/src/vs/workbench/parts/files/common/explorerModel.ts @@ -116,7 +116,7 @@ export class FileStat implements IFileStat { } public get nonexistentRoot(): boolean { - return this.isRoot && !this.isDirectoryResolved; + return this.isRoot && !this.isDirectoryResolved && this.isDirectory; } public getId(): string { -- GitLab