提交 1b4942a7 编写于 作者: B Benjamin Pasero

get rid of workbench IOptions

上级 307e1df1
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IResourceInput } from 'vs/platform/editor/common/editor';
export interface IOptions {
/**
* Instructs the workbench to open the provided files right after startup.
*/
filesToOpen?: IResourceInput[];
/**
* Instructs the workbench to create and open the provided files right after startup.
*/
filesToCreate?: IResourceInput[];
/**
* Instructs the workbench to open a diff of the provided files right after startup.
*/
filesToDiff?: IResourceInput[];
}
\ No newline at end of file
......@@ -8,7 +8,6 @@
import nls = require('vs/nls');
import { TPromise } from 'vs/base/common/winjs.base';
import { WorkbenchShell } from 'vs/workbench/electron-browser/shell';
import { IOptions } from 'vs/workbench/common/options';
import * as browser from 'vs/base/browser/browser';
import { domContentLoaded } from 'vs/base/browser/dom';
import errors = require('vs/base/common/errors');
......@@ -17,7 +16,6 @@ import platform = require('vs/base/common/platform');
import paths = require('vs/base/common/paths');
import uri from 'vs/base/common/uri';
import strings = require('vs/base/common/strings');
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { EmptyWorkspaceServiceImpl, WorkspaceServiceImpl, WorkspaceService } from 'vs/workbench/services/configuration/node/configuration';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
......@@ -29,7 +27,7 @@ import gracefulFs = require('graceful-fs');
import { IInitData } from 'vs/workbench/services/timer/common/timerService';
import { TimerService } from 'vs/workbench/services/timer/node/timerService';
import { KeyboardMapperFactory } from "vs/workbench/services/keybinding/electron-browser/keybindingService";
import { IWindowConfiguration, IPath, IWindowsService } from 'vs/platform/windows/common/windows';
import { IWindowConfiguration, IWindowsService } from 'vs/platform/windows/common/windows';
import { WindowsChannelClient } from 'vs/platform/windows/common/windowsIpc';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
......@@ -68,46 +66,11 @@ export function startup(configuration: IWindowConfiguration): TPromise<void> {
// Setup Intl
comparer.setFileNameComparer(new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }));
// Shell Options
const filesToOpen = configuration.filesToOpen && configuration.filesToOpen.length ? toInputs(configuration.filesToOpen) : null;
const filesToCreate = configuration.filesToCreate && configuration.filesToCreate.length ? toInputs(configuration.filesToCreate) : null;
const filesToDiff = configuration.filesToDiff && configuration.filesToDiff.length ? toInputs(configuration.filesToDiff) : null;
const shellOptions: IOptions = {
filesToOpen,
filesToCreate,
filesToDiff
};
// Open workbench
return openWorkbench(configuration, shellOptions);
}
function toInputs(paths: IPath[], isUntitledFile?: boolean): IResourceInput[] {
return paths.map(p => {
const input = <IResourceInput>{};
if (isUntitledFile) {
input.resource = uri.from({ scheme: 'untitled', path: p.filePath });
} else {
input.resource = uri.file(p.filePath);
}
input.options = {
pinned: true // opening on startup is always pinned and not preview
};
if (p.lineNumber) {
input.options.selection = {
startLineNumber: p.lineNumber,
startColumn: p.columnNumber
};
}
return input;
});
return openWorkbench(configuration);
}
function openWorkbench(configuration: IWindowConfiguration, options: IOptions): TPromise<void> {
function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
const mainProcessClient = new ElectronIPCClient(String(`window${currentWindowId}`));
const mainServices = createMainProcessServices(mainProcessClient);
......@@ -132,7 +95,7 @@ function openWorkbench(configuration: IWindowConfiguration, options: IOptions):
environmentService,
timerService,
storageService
}, mainServices, configuration, options);
}, mainServices, configuration);
shell.open();
// Inform user about loading issues from the loader
......
......@@ -51,7 +51,6 @@ import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
import { EditorWorkerServiceImpl } from 'vs/editor/common/services/editorWorkerServiceImpl';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { MainProcessExtensionService } from 'vs/workbench/api/electron-browser/mainThreadExtensionService';
import { IOptions } from 'vs/workbench/common/options';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
......@@ -137,20 +136,18 @@ export class WorkbenchShell {
private contentsContainer: Builder;
private configuration: IWindowConfiguration;
private options: IOptions;
private workbench: Workbench;
constructor(container: HTMLElement, services: ICoreServices, mainProcessServices: ServiceCollection, configuration: IWindowConfiguration, options: IOptions) {
constructor(container: HTMLElement, coreServices: ICoreServices, mainProcessServices: ServiceCollection, configuration: IWindowConfiguration) {
this.container = container;
this.configuration = configuration;
this.options = options;
this.contextService = services.contextService;
this.configurationService = services.configurationService;
this.environmentService = services.environmentService;
this.timerService = services.timerService;
this.storageService = services.storageService;
this.contextService = coreServices.contextService;
this.configurationService = coreServices.configurationService;
this.environmentService = coreServices.environmentService;
this.timerService = coreServices.timerService;
this.storageService = coreServices.storageService;
this.mainProcessServices = mainProcessServices;
......@@ -170,7 +167,7 @@ export class WorkbenchShell {
const [instantiationService, serviceCollection] = this.initServiceCollection(parent.getHTMLElement());
// Workbench
this.workbench = instantiationService.createInstance(Workbench, parent.getHTMLElement(), workbenchContainer.getHTMLElement(), this.configuration, this.options, serviceCollection);
this.workbench = instantiationService.createInstance(Workbench, parent.getHTMLElement(), workbenchContainer.getHTMLElement(), this.configuration, serviceCollection);
this.workbench.startup({
onWorkbenchStarted: (info: IWorkbenchStartedInfo) => {
......@@ -204,14 +201,14 @@ export class WorkbenchShell {
private onWorkbenchStarted(info: IWorkbenchStartedInfo): void {
// Telemetry: workspace info
const { filesToOpen, filesToCreate, filesToDiff } = this.options;
const { filesToOpen, filesToCreate, filesToDiff } = this.configuration;
this.telemetryService.publicLog('workspaceLoad', {
userAgent: navigator.userAgent,
windowSize: { innerHeight: window.innerHeight, innerWidth: window.innerWidth, outerHeight: window.outerHeight, outerWidth: window.outerWidth },
emptyWorkbench: !this.contextService.hasWorkspace(),
'workbench.filesToOpen': filesToOpen && filesToOpen.length || undefined,
'workbench.filesToCreate': filesToCreate && filesToCreate.length || undefined,
'workbench.filesToDiff': filesToDiff && filesToDiff.length || undefined,
'workbench.filesToOpen': filesToOpen && filesToOpen.length || void 0,
'workbench.filesToCreate': filesToCreate && filesToCreate.length || void 0,
'workbench.filesToDiff': filesToDiff && filesToDiff.length || void 0,
customKeybindingsCount: info.customKeybindingsCount,
theme: this.themeService.getColorTheme().id,
language: platform.language,
......@@ -232,7 +229,7 @@ export class WorkbenchShell {
// Telemetry: workspace tags
const workspaceStats: WorkspaceStats = <WorkspaceStats>this.workbench.getInstantiationService().createInstance(WorkspaceStats);
workspaceStats.reportWorkspaceTags(this.options);
workspaceStats.reportWorkspaceTags(this.configuration);
workspaceStats.reportCloudStats();
if ((platform.isLinux || platform.isMacintosh) && process.getuid() === 0) {
......
......@@ -24,8 +24,7 @@ import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { Registry } from 'vs/platform/registry/common/platform';
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
import { IOptions } from 'vs/workbench/common/options';
import { Position as EditorPosition, IResourceDiffInput, IUntitledResourceInput, IEditor } from 'vs/platform/editor/common/editor';
import { Position as EditorPosition, IResourceDiffInput, IUntitledResourceInput, IEditor, IResourceInput } from 'vs/platform/editor/common/editor';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
import { HistoryService } from 'vs/workbench/services/history/browser/history';
......@@ -85,7 +84,7 @@ import { TextModelResolverService } from 'vs/workbench/services/textmodelResolve
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { ILifecycleService, ShutdownReason } from 'vs/platform/lifecycle/common/lifecycle';
import { IWindowService, IWindowConfiguration as IWindowSettings, IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { IWindowService, IWindowConfiguration as IWindowSettings, IWindowConfiguration, IPath } from 'vs/platform/windows/common/windows';
import { IMessageService } from 'vs/platform/message/common/message';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IMenuService, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
......@@ -100,6 +99,7 @@ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRe
import { getQuickNavigateHandler, inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickopen';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import { WorkspaceEditingService } from 'vs/workbench/services/workspace/node/workspaceEditingService';
import URI from "vs/base/common/uri";
export const MessagesVisibleContext = new RawContextKey<boolean>('globalMessageVisible', false);
export const EditorsVisibleContext = new RawContextKey<boolean>('editorIsOpen', false);
......@@ -107,7 +107,6 @@ export const InZenModeContext = new RawContextKey<boolean>('inZenMode', false);
export const NoEditorsVisibleContext: ContextKeyExpr = EditorsVisibleContext.toNegated();
interface WorkbenchParams {
options: IOptions;
configuration: IWindowConfiguration;
serviceCollection: ServiceCollection;
}
......@@ -216,7 +215,6 @@ export class Workbench implements IPartService {
parent: HTMLElement,
container: HTMLElement,
configuration: IWindowConfiguration,
options: IOptions,
serviceCollection: ServiceCollection,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
......@@ -232,15 +230,14 @@ export class Workbench implements IPartService {
this.container = container;
this.workbenchParams = {
options,
configuration,
serviceCollection
};
this.hasFilesToCreateOpenOrDiff =
(options.filesToCreate && options.filesToCreate.length > 0) ||
(options.filesToOpen && options.filesToOpen.length > 0) ||
(options.filesToDiff && options.filesToDiff.length > 0);
(configuration.filesToCreate && configuration.filesToCreate.length > 0) ||
(configuration.filesToOpen && configuration.filesToOpen.length > 0) ||
(configuration.filesToDiff && configuration.filesToDiff.length > 0);
this.toDispose = [];
this.toShutdown = [];
......@@ -437,10 +434,9 @@ export class Workbench implements IPartService {
// Files to open, diff or create
if (this.hasFilesToCreateOpenOrDiff) {
const wbopt = this.workbenchParams.options;
const filesToCreate = wbopt.filesToCreate || [];
const filesToOpen = wbopt.filesToOpen || [];
const filesToDiff = wbopt.filesToDiff;
const filesToCreate = this.toInputs(this.workbenchParams.configuration.filesToCreate);
const filesToOpen = this.toInputs(this.workbenchParams.configuration.filesToOpen);
const filesToDiff = this.toInputs(this.workbenchParams.configuration.filesToDiff);
// Files to diff is exclusive
if (filesToDiff && filesToDiff.length === 2) {
......@@ -482,6 +478,30 @@ export class Workbench implements IPartService {
return TPromise.as([]);
}
private toInputs(paths?: IPath[]): IResourceInput[] {
if (!paths || !paths.length) {
return [];
}
return paths.map(p => {
const input = <IResourceInput>{};
input.resource = URI.file(p.filePath);
input.options = {
pinned: true // opening on startup is always pinned and not preview
};
if (p.lineNumber) {
input.options.selection = {
startLineNumber: p.lineNumber,
startColumn: p.columnNumber
};
}
return input;
});
}
private openUntitledFile() {
const startupEditor = this.configurationService.lookup('workbench.startupEditor');
......
......@@ -13,7 +13,7 @@ import { IFileService, IFileStat } from 'vs/platform/files/common/files';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IOptions } from 'vs/workbench/common/options';
import { IWindowConfiguration } from "vs/platform/windows/common/windows";
const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/;
const SshUrlMatcher = /^([^@:]+@)?([^:]+):(.+)$/;
......@@ -144,10 +144,10 @@ export class WorkspaceStats {
return arr.some(v => v.search(regEx) > -1) || undefined;
}
private getWorkspaceTags(workbenchOptions: IOptions): TPromise<Tags> {
private getWorkspaceTags(configuration: IWindowConfiguration): TPromise<Tags> {
const tags: Tags = Object.create(null);
const { filesToOpen, filesToCreate, filesToDiff } = workbenchOptions;
const { filesToOpen, filesToCreate, filesToDiff } = configuration;
tags['workbench.filesToOpen'] = filesToOpen && filesToOpen.length || undefined;
tags['workbench.filesToCreate'] = filesToCreate && filesToCreate.length || undefined;
tags['workbench.filesToDiff'] = filesToDiff && filesToDiff.length || undefined;
......@@ -156,7 +156,7 @@ export class WorkspaceStats {
tags['workspace.roots'] = workspace ? workspace.roots.length : 0;
tags['workspace.empty'] = !workspace;
const folders = workspace ? workspace.roots : this.environmentService.appQuality !== 'stable' && this.findFolders(workbenchOptions);
const folders = workspace ? workspace.roots : this.environmentService.appQuality !== 'stable' && this.findFolders(configuration);
if (folders && folders.length && this.fileService) {
return this.fileService.resolveFiles(folders.map(resource => ({ resource }))).then(results => {
const names = (<IFileStat[]>[]).concat(...results.map(result => result.success ? (result.stat.children || []) : [])).map(c => c.name);
......@@ -229,18 +229,18 @@ export class WorkspaceStats {
}
}
private findFolders(options: IOptions): URI[] {
const folder = this.findFolder(options);
private findFolders(configuration: IWindowConfiguration): URI[] {
const folder = this.findFolder(configuration);
return folder && [folder];
}
private findFolder({ filesToOpen, filesToCreate, filesToDiff }: IOptions): URI {
private findFolder({ filesToOpen, filesToCreate, filesToDiff }: IWindowConfiguration): URI {
if (filesToOpen && filesToOpen.length) {
return this.parentURI(filesToOpen[0].resource);
return this.parentURI(URI.file(filesToOpen[0].filePath));
} else if (filesToCreate && filesToCreate.length) {
return this.parentURI(filesToCreate[0].resource);
return this.parentURI(URI.file(filesToCreate[0].filePath));
} else if (filesToDiff && filesToDiff.length) {
return this.parentURI(filesToDiff[0].resource);
return this.parentURI(URI.file(filesToDiff[0].filePath));
}
return undefined;
}
......@@ -251,8 +251,8 @@ export class WorkspaceStats {
return i !== -1 ? uri.with({ path: path.substr(0, i) }) : undefined;
}
public reportWorkspaceTags(workbenchOptions: IOptions): void {
this.getWorkspaceTags(workbenchOptions).then((tags) => {
public reportWorkspaceTags(configuration: IWindowConfiguration): void {
this.getWorkspaceTags(configuration).then((tags) => {
this.telemetryService.publicLog('workspce.tags', tags);
}, error => onUnexpectedError(error));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册