From e9e590997ea703ebc1eabc18935e75bbd0ccaae1 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 28 Feb 2022 13:55:02 +0100 Subject: [PATCH] web - tweak workspace label when temporary workspace is opened --- src/vs/platform/workspace/common/workspace.ts | 4 ++++ .../dialogs/browser/abstractFileDialogService.ts | 4 ++-- src/vs/workbench/services/label/common/labelService.ts | 9 +++++++-- .../browser/abstractWorkspaceEditingService.ts | 4 ++-- .../services/workspaces/common/workspaceTrust.ts | 6 +++--- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/workspace/common/workspace.ts b/src/vs/platform/workspace/common/workspace.ts index a0bd1b77d70..82c3edb83ea 100644 --- a/src/vs/platform/workspace/common/workspace.ts +++ b/src/vs/platform/workspace/common/workspace.ts @@ -432,6 +432,10 @@ export function isTemporaryWorkspace(arg1: IWorkspace | URI): boolean { return path?.scheme === Schemas.tmp; } +export function isSavedWorkspace(path: URI, environmentService: IEnvironmentService): boolean { + return !isUntitledWorkspace(path, environmentService) && !isTemporaryWorkspace(path); +} + export function hasWorkspaceFileExtension(path: string | URI) { const ext = (typeof path === 'string') ? extname(path) : resourceExtname(path); diff --git a/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts b/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts index 14ecbb3fcb7..8fba1ff2934 100644 --- a/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts +++ b/src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts @@ -6,7 +6,7 @@ import * as nls from 'vs/nls'; import { IWindowOpenable, isWorkspaceToOpen, isFileToOpen } from 'vs/platform/window/common/window'; import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, FileFilter, IFileDialogService, IDialogService, ConfirmResult, getFileNamesMessage } from 'vs/platform/dialogs/common/dialogs'; -import { isUntitledWorkspace, IWorkspaceContextService, WorkbenchState, WORKSPACE_EXTENSION } from 'vs/platform/workspace/common/workspace'; +import { isSavedWorkspace, IWorkspaceContextService, WorkbenchState, WORKSPACE_EXTENSION } from 'vs/platform/workspace/common/workspace'; import { IHistoryService } from 'vs/workbench/services/history/common/history'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { URI } from 'vs/base/common/uri'; @@ -94,7 +94,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService { // Check for current workspace config file first... if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) { const configuration = this.contextService.getWorkspace().configuration; - if (configuration && configuration.scheme === schemeFilter && !isUntitledWorkspace(configuration, this.environmentService)) { + if (configuration && configuration.scheme === schemeFilter && isSavedWorkspace(configuration, this.environmentService)) { defaultWorkspacePath = resources.dirname(configuration) || undefined; } } diff --git a/src/vs/workbench/services/label/common/labelService.ts b/src/vs/workbench/services/label/common/labelService.ts index 326daa5057a..65d814b0627 100644 --- a/src/vs/workbench/services/label/common/labelService.ts +++ b/src/vs/workbench/services/label/common/labelService.ts @@ -11,7 +11,7 @@ import { Emitter } from 'vs/base/common/event'; import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { Registry } from 'vs/platform/registry/common/platform'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { IWorkspaceContextService, IWorkspace, isWorkspace, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier, toWorkspaceIdentifier, WORKSPACE_EXTENSION, isUntitledWorkspace } from 'vs/platform/workspace/common/workspace'; +import { IWorkspaceContextService, IWorkspace, isWorkspace, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier, toWorkspaceIdentifier, WORKSPACE_EXTENSION, isUntitledWorkspace, isTemporaryWorkspace } from 'vs/platform/workspace/common/workspace'; import { basenameOrAuthority, basename, joinPath, dirname } from 'vs/base/common/resources'; import { tildify, getPathLabel } from 'vs/base/common/labels'; import { ILabelService, ResourceLabelFormatter, ResourceLabelFormatting, IFormatterChangeEvent } from 'vs/platform/label/common/label'; @@ -236,13 +236,18 @@ export class LabelService extends Disposable implements ILabelService { return localize('untitledWorkspace', "Untitled (Workspace)"); } + // Workspace: Temporary + if (isTemporaryWorkspace(workspaceUri)) { + return localize('temporaryWorkspace', "Workspace"); + } + // Workspace: Saved let filename = basename(workspaceUri); if (filename.endsWith(WORKSPACE_EXTENSION)) { filename = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1); } - let label; + let label: string; if (options?.verbose) { label = localize('workspaceNameVerbose', "{0} (Workspace)", this.getUriLabel(joinPath(dirname(workspaceUri), filename))); } else { diff --git a/src/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.ts b/src/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.ts index bd4868724fb..72f3a0b82ed 100644 --- a/src/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.ts +++ b/src/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.ts @@ -6,7 +6,7 @@ import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing'; import { URI } from 'vs/base/common/uri'; import { localize } from 'vs/nls'; -import { hasWorkspaceFileExtension, isUntitledWorkspace, IWorkspaceContextService, IWorkspaceIdentifier, WorkbenchState, WORKSPACE_EXTENSION, WORKSPACE_FILTER } from 'vs/platform/workspace/common/workspace'; +import { hasWorkspaceFileExtension, isSavedWorkspace, isUntitledWorkspace, IWorkspaceContextService, IWorkspaceIdentifier, WorkbenchState, WORKSPACE_EXTENSION, WORKSPACE_FILTER } from 'vs/platform/workspace/common/workspace'; import { IJSONEditingService, JSONEditingError, JSONEditingErrorCode } from 'vs/workbench/services/configuration/common/jsonEditing'; import { IWorkspaceFolderCreationData, IWorkspacesService, rewriteWorkspaceFileForNewLocation, IEnterWorkspaceResult, IStoredWorkspace } from 'vs/platform/workspaces/common/workspaces'; import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService'; @@ -86,7 +86,7 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi } case WorkbenchState.WORKSPACE: { const configPathURI = this.getCurrentWorkspaceIdentifier()?.configPath; - if (configPathURI && !isUntitledWorkspace(configPathURI, this.environmentService)) { + if (configPathURI && isSavedWorkspace(configPathURI, this.environmentService)) { return basename(configPathURI); } break; diff --git a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts index 66392db3353..38877625d85 100644 --- a/src/vs/workbench/services/workspaces/common/workspaceTrust.ts +++ b/src/vs/workbench/services/workspaces/common/workspaceTrust.ts @@ -15,7 +15,7 @@ import { IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/rem import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts'; import { isVirtualResource } from 'vs/platform/workspace/common/virtualWorkspace'; import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; -import { ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isUntitledWorkspace, IWorkspace, IWorkspaceContextService, IWorkspaceFolder, toWorkspaceIdentifier, WorkbenchState } from 'vs/platform/workspace/common/workspace'; +import { ISingleFolderWorkspaceIdentifier, isSavedWorkspace, isSingleFolderWorkspaceIdentifier, IWorkspace, IWorkspaceContextService, IWorkspaceFolder, toWorkspaceIdentifier, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { WorkspaceTrustRequestOptions, IWorkspaceTrustManagementService, IWorkspaceTrustInfo, IWorkspaceTrustUriInfo, IWorkspaceTrustRequestService, IWorkspaceTrustTransitionParticipant, WorkspaceTrustUriResponse, IWorkspaceTrustEnablementService } from 'vs/platform/workspace/common/workspaceTrust'; import { Memento, MementoObject } from 'vs/workbench/common/memento'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; @@ -268,7 +268,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork } let canonicalWorkspaceConfiguration = this.workspaceService.getWorkspace().configuration; - if (canonicalWorkspaceConfiguration && !isUntitledWorkspace(canonicalWorkspaceConfiguration, this.environmentService)) { + if (canonicalWorkspaceConfiguration && isSavedWorkspace(canonicalWorkspaceConfiguration, this.environmentService)) { canonicalWorkspaceConfiguration = await this.getCanonicalUri(canonicalWorkspaceConfiguration); } @@ -319,7 +319,7 @@ export class WorkspaceTrustManagementService extends Disposable implements IWork private getWorkspaceUris(): URI[] { const workspaceUris = this._canonicalWorkspace.folders.map(f => f.uri); const workspaceConfiguration = this._canonicalWorkspace.configuration; - if (workspaceConfiguration && !isUntitledWorkspace(workspaceConfiguration, this.environmentService)) { + if (workspaceConfiguration && isSavedWorkspace(workspaceConfiguration, this.environmentService)) { workspaceUris.push(workspaceConfiguration); }