Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010 (#7415)

* Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010

* add missing files
This commit is contained in:
Anthony Dresser
2019-09-27 23:30:36 -07:00
committed by GitHub
parent d0fb6de390
commit bca7c8e6bd
123 changed files with 1704 additions and 1330 deletions

View File

@@ -15,6 +15,32 @@ import { IFileService } from 'vs/platform/files/common/files';
import { ILabelService } from 'vs/platform/label/common/label';
import { trackFocus } from 'vs/base/browser/dom';
import { Disposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
/**
* A workspace to open in the workbench can either be:
* - a workspace file with 0-N folders (via `workspaceUri`)
* - a single folder (via `folderUri`)
* - empty (via `undefined`)
*/
export type IWorkspace = { workspaceUri: URI } | { folderUri: URI } | undefined;
export interface IWorkspaceProvider {
/**
* The initial workspace to open.
*/
readonly workspace: IWorkspace;
/**
* Asks to open a workspace in the current or a new window.
*
* @param workspace the workspace to open.
* @param options wether to open inside the current window or a new window.
*/
open(workspace: IWorkspace, options?: { reuse?: boolean }): Promise<void>;
}
export class BrowserHostService extends Disposable implements IHostService {
@@ -27,15 +53,27 @@ export class BrowserHostService extends Disposable implements IHostService {
//#endregion
private workspaceProvider: IWorkspaceProvider;
constructor(
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
@IEditorService private readonly editorService: IEditorService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IFileService private readonly fileService: IFileService,
@ILabelService private readonly labelService: ILabelService
@ILabelService private readonly labelService: ILabelService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService
) {
super();
if (environmentService.options && environmentService.options.workspaceProvider) {
this.workspaceProvider = environmentService.options.workspaceProvider;
} else {
this.workspaceProvider = new class implements IWorkspaceProvider {
readonly workspace = undefined;
async open() { }
};
}
this.registerListeners();
}
@@ -54,33 +92,21 @@ export class BrowserHostService extends Disposable implements IHostService {
readonly windowCount = Promise.resolve(1);
async openInWindow(toOpen: IWindowOpenable[], options?: IOpenInWindowOptions): Promise<void> {
// TODO@Ben delegate to embedder
const { openFolderInNewWindow } = this.shouldOpenNewWindow(options);
for (let i = 0; i < toOpen.length; i++) {
const openable = toOpen[i];
openable.label = openable.label || this.getRecentLabel(openable);
// Folder
if (isFolderToOpen(openable)) {
const newAddress = `${document.location.origin}${document.location.pathname}?folder=${openable.folderUri.path}`;
if (openFolderInNewWindow) {
window.open(newAddress);
} else {
window.location.href = newAddress;
}
this.workspaceProvider.open({ folderUri: openable.folderUri }, { reuse: this.shouldReuse(options) });
}
// Workspace
else if (isWorkspaceToOpen(openable)) {
const newAddress = `${document.location.origin}${document.location.pathname}?workspace=${openable.workspaceUri.path}`;
if (openFolderInNewWindow) {
window.open(newAddress);
} else {
window.location.href = newAddress;
}
this.workspaceProvider.open({ workspaceUri: openable.workspaceUri }, { reuse: this.shouldReuse(options) });
}
// File
// File: open via editor service in current window
else if (isFileToOpen(openable)) {
const inputs: IResourceEditor[] = await pathsToEditors([openable], this.fileService);
this.editorService.openEditors(inputs);
@@ -100,7 +126,7 @@ export class BrowserHostService extends Disposable implements IHostService {
return this.labelService.getUriLabel(openable.fileUri);
}
private shouldOpenNewWindow(options: IOpenInWindowOptions = {}): { openFolderInNewWindow: boolean } {
private shouldReuse(options: IOpenInWindowOptions = {}): boolean {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
const openFolderInNewWindowConfig = (windowConfig && windowConfig.openFoldersInNewWindow) || 'default' /* default */;
@@ -109,17 +135,11 @@ export class BrowserHostService extends Disposable implements IHostService {
openFolderInNewWindow = (openFolderInNewWindowConfig === 'on');
}
return { openFolderInNewWindow };
return !openFolderInNewWindow;
}
async openEmptyWindow(options?: IOpenEmptyWindowOptions): Promise<void> {
// TODO@Ben delegate to embedder
const targetHref = `${document.location.origin}${document.location.pathname}?ew=true`;
if (options && options.reuse) {
window.location.href = targetHref;
} else {
window.open(targetHref);
}
this.workspaceProvider.open(undefined, { reuse: options && options.reuse });
}
async toggleFullScreen(): Promise<void> {