Merge from vscode e0762af258c0b20320ed03f3871a41967acc4421 (#7404)

* Merge from vscode e0762af258c0b20320ed03f3871a41967acc4421

* readd svgs
This commit is contained in:
Anthony Dresser
2019-09-27 11:13:19 -07:00
committed by GitHub
parent 6385443a4c
commit 07109617b5
348 changed files with 4219 additions and 4307 deletions

View File

@@ -3,21 +3,116 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { IResourceEditor, IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWindowSettings, IWindowOpenable, IOpenInWindowOptions, isFolderToOpen, isWorkspaceToOpen, isFileToOpen, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
import { pathsToEditors } from 'vs/workbench/common/editor';
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';
export class BrowserHostService implements IHostService {
export class BrowserHostService extends Disposable implements IHostService {
_serviceBrand: undefined;
constructor(@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService) { }
//#region Events
get onDidChangeFocus(): Event<boolean> { return this._onDidChangeFocus; }
private _onDidChangeFocus: Event<boolean>;
//#endregion
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
) {
super();
this.registerListeners();
}
private registerListeners(): void {
// Track Focus on Window
const focusTracker = this._register(trackFocus(window));
this._onDidChangeFocus = Event.any(
Event.map(focusTracker.onDidFocus, () => this.hasFocus),
Event.map(focusTracker.onDidBlur, () => this.hasFocus)
);
}
//#region Window
readonly windowCount = Promise.resolve(1);
async openEmptyWindow(options?: { reuse?: boolean, remoteAuthority?: string }): Promise<void> {
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;
}
}
// 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;
}
}
// File
else if (isFileToOpen(openable)) {
const inputs: IResourceEditor[] = await pathsToEditors([openable], this.fileService);
this.editorService.openEditors(inputs);
}
}
}
private getRecentLabel(openable: IWindowOpenable): string {
if (isFolderToOpen(openable)) {
return this.labelService.getWorkspaceLabel(openable.folderUri, { verbose: true });
}
if (isWorkspaceToOpen(openable)) {
return this.labelService.getWorkspaceLabel({ id: '', configPath: openable.workspaceUri }, { verbose: true });
}
return this.labelService.getUriLabel(openable.fileUri);
}
private shouldOpenNewWindow(options: IOpenInWindowOptions = {}): { openFolderInNewWindow: boolean } {
const windowConfig = this.configurationService.getValue<IWindowSettings>('window');
const openFolderInNewWindowConfig = (windowConfig && windowConfig.openFoldersInNewWindow) || 'default' /* default */;
let openFolderInNewWindow = !!options.forceNewWindow && !options.forceReuseWindow;
if (!options.forceNewWindow && !options.forceReuseWindow && (openFolderInNewWindowConfig === 'on' || openFolderInNewWindowConfig === 'off')) {
openFolderInNewWindow = (openFolderInNewWindowConfig === 'on');
}
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) {
@@ -61,6 +156,14 @@ export class BrowserHostService implements IHostService {
}
}
get hasFocus(): boolean {
return document.hasFocus();
}
async focus(): Promise<void> {
window.focus();
}
//#endregion
async restart(): Promise<void> {