Path: blob/main/src/vs/workbench/contrib/files/browser/views/emptyView.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as nls from '../../../../../nls.js';6import { IViewletViewOptions } from '../../../../browser/parts/views/viewsViewlet.js';7import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';8import { IThemeService } from '../../../../../platform/theme/common/themeService.js';9import { IKeybindingService } from '../../../../../platform/keybinding/common/keybinding.js';10import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.js';11import { isTemporaryWorkspace, IWorkspaceContextService, WorkbenchState } from '../../../../../platform/workspace/common/workspace.js';12import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';13import { ViewPane } from '../../../../browser/parts/views/viewPane.js';14import { ResourcesDropHandler } from '../../../../browser/dnd.js';15import { listDropOverBackground } from '../../../../../platform/theme/common/colorRegistry.js';16import { ILabelService } from '../../../../../platform/label/common/label.js';17import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';18import { IViewDescriptorService } from '../../../../common/views.js';19import { IOpenerService } from '../../../../../platform/opener/common/opener.js';20import { isWeb } from '../../../../../base/common/platform.js';21import { DragAndDropObserver, getWindow } from '../../../../../base/browser/dom.js';22import { ILocalizedString } from '../../../../../platform/action/common/action.js';23import { IHoverService } from '../../../../../platform/hover/browser/hover.js';2425export class EmptyView extends ViewPane {2627static readonly ID: string = 'workbench.explorer.emptyView';28static readonly NAME: ILocalizedString = nls.localize2('noWorkspace', "No Folder Opened");29private _disposed: boolean = false;3031constructor(32options: IViewletViewOptions,33@IThemeService themeService: IThemeService,34@IViewDescriptorService viewDescriptorService: IViewDescriptorService,35@IInstantiationService instantiationService: IInstantiationService,36@IKeybindingService keybindingService: IKeybindingService,37@IContextMenuService contextMenuService: IContextMenuService,38@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,39@IConfigurationService configurationService: IConfigurationService,40@ILabelService private labelService: ILabelService,41@IContextKeyService contextKeyService: IContextKeyService,42@IOpenerService openerService: IOpenerService,43@IHoverService hoverService: IHoverService,44) {45super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);4647this._register(this.contextService.onDidChangeWorkbenchState(() => this.refreshTitle()));48this._register(this.labelService.onDidChangeFormatters(() => this.refreshTitle()));49}5051override shouldShowWelcome(): boolean {52return true;53}5455protected override renderBody(container: HTMLElement): void {56super.renderBody(container);5758this._register(new DragAndDropObserver(container, {59onDrop: e => {60container.style.backgroundColor = '';61const dropHandler = this.instantiationService.createInstance(ResourcesDropHandler, { allowWorkspaceOpen: !isWeb || isTemporaryWorkspace(this.contextService.getWorkspace()) });62dropHandler.handleDrop(e, getWindow(container));63},64onDragEnter: () => {65const color = this.themeService.getColorTheme().getColor(listDropOverBackground);66container.style.backgroundColor = color ? color.toString() : '';67},68onDragEnd: () => {69container.style.backgroundColor = '';70},71onDragLeave: () => {72container.style.backgroundColor = '';73},74onDragOver: e => {75if (e.dataTransfer) {76e.dataTransfer.dropEffect = 'copy';77}78}79}));8081this.refreshTitle();82}8384private refreshTitle(): void {85if (this._disposed) {86return;87}8889if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) {90this.updateTitle(EmptyView.NAME.value);91} else {92this.updateTitle(this.title);93}94}9596override dispose(): void {97this._disposed = true;98super.dispose();99}100}101102103