virtualWorkspace context key to detect virtual workspaces. Fixes #121165
This commit is contained in:
parent
38f2172759
commit
49796d31cb
3 changed files with 41 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
import { Schemas } from 'vs/base/common/network';
|
import { Schemas } from 'vs/base/common/network';
|
||||||
|
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
|
||||||
|
|
||||||
export function getRemoteAuthority(uri: URI): string | undefined {
|
export function getRemoteAuthority(uri: URI): string | undefined {
|
||||||
return uri.scheme === Schemas.vscodeRemote ? uri.authority : undefined;
|
return uri.scheme === Schemas.vscodeRemote ? uri.authority : undefined;
|
||||||
|
@ -24,3 +25,25 @@ export function getRemoteName(authority: string | undefined): string | undefined
|
||||||
}
|
}
|
||||||
return authority.substr(0, pos);
|
return authority.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isVirtualResource(resource: URI) {
|
||||||
|
return resource.scheme !== Schemas.file && resource.scheme !== Schemas.vscodeRemote;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVirtualWorkspaceLocation(workspace: IWorkspace): URI | undefined {
|
||||||
|
const configFile = workspace.configuration;
|
||||||
|
if (configFile && isVirtualResource(configFile)) {
|
||||||
|
return configFile;
|
||||||
|
}
|
||||||
|
if (workspace.folders.length) {
|
||||||
|
const firstFolder = workspace.folders[0].uri;
|
||||||
|
if (isVirtualResource(firstFolder)) {
|
||||||
|
return firstFolder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVirtualWorkspaceScheme(workspace: IWorkspace): string | undefined {
|
||||||
|
return getVirtualWorkspaceLocation(workspace)?.scheme;
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { SideBarVisibleContext } from 'vs/workbench/common/viewlet';
|
||||||
import { IWorkbenchLayoutService, Parts, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
|
import { IWorkbenchLayoutService, Parts, positionToString } from 'vs/workbench/services/layout/browser/layoutService';
|
||||||
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
|
||||||
import { PanelMaximizedContext, PanelPositionContext, PanelVisibleContext } from 'vs/workbench/common/panel';
|
import { PanelMaximizedContext, PanelPositionContext, PanelVisibleContext } from 'vs/workbench/common/panel';
|
||||||
import { getRemoteName } from 'vs/platform/remote/common/remoteHosts';
|
import { getRemoteName, getVirtualWorkspaceScheme } from 'vs/platform/remote/common/remoteHosts';
|
||||||
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
|
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService';
|
||||||
import { isNative } from 'vs/base/common/platform';
|
import { isNative } from 'vs/base/common/platform';
|
||||||
|
|
||||||
|
@ -27,9 +27,10 @@ export const WorkbenchStateContext = new RawContextKey<string>('workbenchState',
|
||||||
export const WorkspaceFolderCountContext = new RawContextKey<number>('workspaceFolderCount', 0, localize('workspaceFolderCount', "The number of root folders in the workspace"));
|
export const WorkspaceFolderCountContext = new RawContextKey<number>('workspaceFolderCount', 0, localize('workspaceFolderCount', "The number of root folders in the workspace"));
|
||||||
export const EmptyWorkspaceSupportContext = new RawContextKey<boolean>('emptyWorkspaceSupport', true, true);
|
export const EmptyWorkspaceSupportContext = new RawContextKey<boolean>('emptyWorkspaceSupport', true, true);
|
||||||
|
|
||||||
export const DirtyWorkingCopiesContext = new RawContextKey<boolean>('dirtyWorkingCopies', false, localize('dirtyWorkingCopies', "Wether there are any dirty working copies"));
|
export const DirtyWorkingCopiesContext = new RawContextKey<boolean>('dirtyWorkingCopies', false, localize('dirtyWorkingCopies', "Whether there are any dirty working copies"));
|
||||||
|
|
||||||
export const RemoteNameContext = new RawContextKey<string>('remoteName', '', localize('remoteName', "The name of the remote the window is connected to or an empty string if not connected to any remote"));
|
export const RemoteNameContext = new RawContextKey<string>('remoteName', '', localize('remoteName', "The name of the remote the window is connected to or an empty string if not connected to any remote"));
|
||||||
|
export const VirtualWorkspaceContext = new RawContextKey<string>('virtualWorkspace', '', localize('virtualWorkspace', "The scheme of the current workspace if is from a virtual file system or an empty string."));
|
||||||
|
|
||||||
export const IsFullscreenContext = new RawContextKey<boolean>('isFullscreen', false, localize('isFullscreen', "Whether the window is in fullscreen mode"));
|
export const IsFullscreenContext = new RawContextKey<boolean>('isFullscreen', false, localize('isFullscreen', "Whether the window is in fullscreen mode"));
|
||||||
|
|
||||||
|
@ -68,6 +69,8 @@ export class WorkbenchContextKeysHandler extends Disposable {
|
||||||
private panelVisibleContext: IContextKey<boolean>;
|
private panelVisibleContext: IContextKey<boolean>;
|
||||||
private panelMaximizedContext: IContextKey<boolean>;
|
private panelMaximizedContext: IContextKey<boolean>;
|
||||||
|
|
||||||
|
private vitualWorkspaceContext: IContextKey<string>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IContextKeyService private readonly contextKeyService: IContextKeyService,
|
@IContextKeyService private readonly contextKeyService: IContextKeyService,
|
||||||
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
|
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
|
||||||
|
@ -91,6 +94,9 @@ export class WorkbenchContextKeysHandler extends Disposable {
|
||||||
|
|
||||||
RemoteNameContext.bindTo(this.contextKeyService).set(getRemoteName(this.environmentService.remoteAuthority) || '');
|
RemoteNameContext.bindTo(this.contextKeyService).set(getRemoteName(this.environmentService.remoteAuthority) || '');
|
||||||
|
|
||||||
|
this.vitualWorkspaceContext = VirtualWorkspaceContext.bindTo(this.contextKeyService);
|
||||||
|
this.updateVirtualWorkspaceContextKey();
|
||||||
|
|
||||||
// Capabilities
|
// Capabilities
|
||||||
HasWebFileSystemAccess.bindTo(this.contextKeyService).set(WebFileSystemAccess.supported(window));
|
HasWebFileSystemAccess.bindTo(this.contextKeyService).set(WebFileSystemAccess.supported(window));
|
||||||
|
|
||||||
|
@ -173,7 +179,10 @@ export class WorkbenchContextKeysHandler extends Disposable {
|
||||||
this._register(addDisposableListener(window, EventType.FOCUS_IN, () => this.updateInputContextKeys(), true));
|
this._register(addDisposableListener(window, EventType.FOCUS_IN, () => this.updateInputContextKeys(), true));
|
||||||
|
|
||||||
this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateWorkbenchStateContextKey()));
|
this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateWorkbenchStateContextKey()));
|
||||||
this._register(this.contextService.onDidChangeWorkspaceFolders(() => this.updateWorkspaceFolderCountContextKey()));
|
this._register(this.contextService.onDidChangeWorkspaceFolders(() => {
|
||||||
|
this.updateWorkspaceFolderCountContextKey();
|
||||||
|
this.updateVirtualWorkspaceContextKey();
|
||||||
|
}));
|
||||||
|
|
||||||
this._register(this.configurationService.onDidChangeConfiguration(e => {
|
this._register(this.configurationService.onDidChangeConfiguration(e => {
|
||||||
if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
|
if (e.affectsConfiguration('workbench.editor.openSideBySideDirection')) {
|
||||||
|
@ -285,4 +294,8 @@ export class WorkbenchContextKeysHandler extends Disposable {
|
||||||
private updateSideBarContextKeys(): void {
|
private updateSideBarContextKeys(): void {
|
||||||
this.sideBarVisibleContext.set(this.layoutService.isVisible(Parts.SIDEBAR_PART));
|
this.sideBarVisibleContext.set(this.layoutService.isVisible(Parts.SIDEBAR_PART));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateVirtualWorkspaceContextKey(): void {
|
||||||
|
this.vitualWorkspaceContext.set(getVirtualWorkspaceScheme(this.contextService.getWorkspace()) || '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { isWeb } from 'vs/base/common/platform';
|
||||||
import { once } from 'vs/base/common/functional';
|
import { once } from 'vs/base/common/functional';
|
||||||
import { truncate } from 'vs/base/common/strings';
|
import { truncate } from 'vs/base/common/strings';
|
||||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||||
|
import { getVirtualWorkspaceLocation } from 'vs/platform/remote/common/remoteHosts';
|
||||||
|
|
||||||
export class RemoteStatusIndicator extends Disposable implements IWorkbenchContribution {
|
export class RemoteStatusIndicator extends Disposable implements IWorkbenchContribution {
|
||||||
|
|
||||||
|
@ -247,11 +248,10 @@ export class RemoteStatusIndicator extends Disposable implements IWorkbenchContr
|
||||||
|
|
||||||
private getWorkspaceLabel() {
|
private getWorkspaceLabel() {
|
||||||
const workspace = this.workspaceContextService.getWorkspace();
|
const workspace = this.workspaceContextService.getWorkspace();
|
||||||
const workspaceLocation = workspace.configuration || (workspace.folders.length === 1 ? workspace.folders[0].uri : undefined);
|
const workspaceLocation = getVirtualWorkspaceLocation(workspace);
|
||||||
if (workspaceLocation) {
|
if (workspaceLocation) {
|
||||||
return this.labelService.getHostLabel(workspaceLocation.scheme, workspaceLocation.authority);
|
return this.labelService.getHostLabel(workspaceLocation.scheme, workspaceLocation.authority);
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue