提交 91db8b52 编写于 作者: B Benjamin Pasero

get rid of ICommandLineArguments

上级 68562163
......@@ -15,31 +15,26 @@ import * as types from 'vs/base/common/types';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { parseMainProcessArgv, ParsedArgs } from 'vs/platform/environment/node/argv';
export interface ICommandLineArguments extends ParsedArgs {
paths?: string[];
}
export const IEnvService = createDecorator<IEnvService>('mainEnvironmentService');
export interface IEnvService {
_serviceBrand: any;
cliArgs: ICommandLineArguments;
cliArgs: ParsedArgs;
}
export class EnvService implements IEnvService {
_serviceBrand: any;
private _cliArgs: ICommandLineArguments;
get cliArgs(): ICommandLineArguments { return this._cliArgs; }
private _cliArgs: ParsedArgs;
get cliArgs(): ParsedArgs { return this._cliArgs; }
constructor() {
const argv = parseMainProcessArgv(process.argv);
const paths = parsePathArguments(argv._, argv.goto);
this._cliArgs = Object.freeze({
_: [],
paths,
_: paths,
performance: argv.performance,
verbose: argv.verbose,
debugPluginHost: argv.debugPluginHost,
......
......@@ -5,7 +5,6 @@
'use strict';
import { ICommandLineArguments } from 'vs/code/electron-main/env';
import { IWindowsService } from 'vs/code/electron-main/windows';
import { VSCodeWindow } from 'vs/code/electron-main/window';
import { TPromise } from 'vs/base/common/winjs.base';
......@@ -13,14 +12,15 @@ import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { ILogService } from 'vs/code/electron-main/log';
import { IURLService } from 'vs/platform/url/common/url';
import { IProcessEnvironment } from 'vs/base/common/platform';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
export interface IStartArguments {
args: ICommandLineArguments;
args: ParsedArgs;
userEnv: IProcessEnvironment;
}
export interface ILaunchService {
start(args: ICommandLineArguments, userEnv: IProcessEnvironment): TPromise<void>;
start(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void>;
}
export interface ILaunchChannel extends IChannel {
......@@ -45,7 +45,7 @@ export class LaunchChannelClient implements ILaunchService {
constructor(private channel: ILaunchChannel) { }
start(args: ICommandLineArguments, userEnv: IProcessEnvironment): TPromise<void> {
start(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void> {
return this.channel.call('start', { args, userEnv });
}
}
......@@ -58,7 +58,7 @@ export class LaunchService implements ILaunchService {
@IURLService private urlService: IURLService
) {}
start(args: ICommandLineArguments, userEnv: IProcessEnvironment): TPromise<void> {
start(args: ParsedArgs, userEnv: IProcessEnvironment): TPromise<void> {
this.logService.log('Received data from other instance: ', args, userEnv);
const openUrlArg = args['open-url'] || [];
......@@ -73,9 +73,9 @@ export class LaunchService implements ILaunchService {
let usedWindows: VSCodeWindow[];
if (!!args.extensionDevelopmentPath) {
this.windowsService.openPluginDevelopmentHostWindow({ cli: args, userEnv });
} else if (args.paths.length === 0 && args['new-window']) {
} else if (args._.length === 0 && args['new-window']) {
usedWindows = this.windowsService.open({ cli: args, userEnv, forceNewWindow: true, forceEmpty: true });
} else if (args.paths.length === 0) {
} else if (args._.length === 0) {
usedWindows = [this.windowsService.focusLastActive(args)];
} else {
usedWindows = this.windowsService.open({
......
......@@ -253,9 +253,9 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
updateService.initialize();
// Open our first window
if (envService.cliArgs['new-window'] && envService.cliArgs.paths.length === 0) {
if (envService.cliArgs['new-window'] && envService.cliArgs._.length === 0) {
windowsService.open({ cli: envService.cliArgs, forceNewWindow: true, forceEmpty: true }); // new window if "-n" was used without paths
} else if (global.macOpenFiles && global.macOpenFiles.length && (!envService.cliArgs.paths || !envService.cliArgs.paths.length)) {
} else if (global.macOpenFiles && global.macOpenFiles.length && (!envService.cliArgs._ || !envService.cliArgs._.length)) {
windowsService.open({ cli: envService.cliArgs, pathsToOpen: global.macOpenFiles }); // mac: open-file event received on startup
} else {
windowsService.open({ cli: envService.cliArgs, forceNewWindow: envService.cliArgs['new-window'], diffMode: envService.cliArgs.diff }); // default: read paths from cli
......@@ -426,6 +426,7 @@ function getEnvironment(accessor: ServicesAccessor): TPromise<platform.IProcessE
function createPaths(environmentService: IEnvironmentService): TPromise<any> {
const paths = [environmentService.appSettingsHome, environmentService.userHome, environmentService.extensionsPath];
return TPromise.join(paths.map(p => mkdirp(p))) as TPromise<any>;
}
......
......@@ -69,11 +69,11 @@ export class VSCodeMenu {
});
// Listen to "open" & "close" event from window service
this.windowsService.onOpen((paths) => this.onOpen(paths));
this.windowsService.onOpen(paths => this.onOpen(paths));
this.windowsService.onClose(_ => this.onClose(this.windowsService.getWindowCount()));
// Resolve keybindings when any first workbench is loaded
this.windowsService.onReady((win) => this.resolveKeybindings(win));
this.windowsService.onReady(win => this.resolveKeybindings(win));
// Listen to resolved keybindings
ipc.on('vscode:keybindingsResolved', (event, rawKeybindings) => {
......@@ -86,7 +86,7 @@ export class VSCodeMenu {
// Fill hash map of resolved keybindings
let needsMenuUpdate = false;
keybindings.forEach((keybinding) => {
keybindings.forEach(keybinding => {
const accelerator = new Keybinding(keybinding.binding)._toElectronAccelerator();
if (accelerator) {
this.mapResolvedKeybindingToActionId[keybinding.id] = accelerator;
......@@ -328,7 +328,7 @@ export class VSCodeMenu {
!platform.isMacintosh ? closeWindow : null,
!platform.isMacintosh ? __separator__() : null,
!platform.isMacintosh ? exit : null
]).forEach((item) => fileMenu.append(item));
]).forEach(item => fileMenu.append(item));
}
private getPreferencesMenu(): Electron.MenuItem {
......@@ -434,8 +434,8 @@ export class VSCodeMenu {
let selectAll: Electron.MenuItem;
if (platform.isMacintosh) {
undo = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), 'undo', (devTools) => devTools.undo());
redo = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), 'redo', (devTools) => devTools.redo());
undo = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miUndo', comment: ['&& denotes a mnemonic'] }, "&&Undo"), 'undo', devTools => devTools.undo());
redo = this.createDevToolsAwareMenuItem(nls.localize({ key: 'miRedo', comment: ['&& denotes a mnemonic'] }, "&&Redo"), 'redo', devTools => devTools.redo());
cut = this.createRoleMenuItem(nls.localize({ key: 'miCut', comment: ['&& denotes a mnemonic'] }, "&&Cut"), 'editor.action.clipboardCutAction', 'cut');
copy = this.createRoleMenuItem(nls.localize({ key: 'miCopy', comment: ['&& denotes a mnemonic'] }, "C&&opy"), 'editor.action.clipboardCopyAction', 'copy');
paste = this.createRoleMenuItem(nls.localize({ key: 'miPaste', comment: ['&& denotes a mnemonic'] }, "&&Paste"), 'editor.action.clipboardPasteAction', 'paste');
......@@ -531,7 +531,7 @@ export class VSCodeMenu {
zoomIn,
zoomOut,
resetZoom
]).forEach((item) => viewMenu.append(item));
]).forEach(item => viewMenu.append(item));
}
private setGotoMenu(gotoMenu: Electron.Menu): void {
......@@ -673,7 +673,7 @@ export class VSCodeMenu {
(product.licenseUrl || product.privacyStatementUrl) ? __separator__() : null,
toggleDevToolsItem,
platform.isWindows && product.quality !== 'stable' ? showAccessibilityOptions : null
]).forEach((item) => helpMenu.append(item));
]).forEach(item => helpMenu.append(item));
if (!platform.isMacintosh) {
const updateMenuItems = this.getUpdateMenuItems();
......@@ -811,7 +811,7 @@ export class VSCodeMenu {
),
buttons: [nls.localize('okButton', "OK")],
noLink: true
}, (result) => null);
}, result => null);
this.reportMenuActionTelemetry('showAboutDialog');
}
......
......@@ -11,11 +11,10 @@ import * as objects from 'vs/base/common/objects';
import { IStorageService } from 'vs/code/electron-main/storage';
import { shell, screen, BrowserWindow } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ICommandLineArguments } from 'vs/code/electron-main/env';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs } from 'vs/platform/environment/node/argv';
import { parseArgs, ParsedArgs } from 'vs/platform/environment/node/argv';
import product from 'vs/platform/product';
export interface IWindowState {
......@@ -88,7 +87,7 @@ export interface IPath {
createFilePath?: boolean;
}
export interface IWindowConfiguration extends ICommandLineArguments {
export interface IWindowConfiguration extends ParsedArgs {
appRoot: string;
execPath: string;
......@@ -387,7 +386,7 @@ export class VSCodeWindow {
}
}
public reload(cli?: ICommandLineArguments): void {
public reload(cli?: ParsedArgs): void {
// Inherit current properties but overwrite some
const configuration: IWindowConfiguration = objects.mixin({}, this.currentConfig);
......
......@@ -18,7 +18,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IStorageService } from 'vs/code/electron-main/storage';
import { IPath, VSCodeWindow, ReadyState, IWindowConfiguration, IWindowState as ISingleWindowState, defaultWindowState, IWindowSettings } from 'vs/code/electron-main/window';
import { ipcMain as ipc, app, screen, crashReporter, BrowserWindow, dialog } from 'electron';
import { ICommandLineArguments, IEnvService, IParsedPath, parseLineAndColumnAware } from 'vs/code/electron-main/env';
import { IEnvService, IParsedPath, parseLineAndColumnAware } from 'vs/code/electron-main/env';
import { ILifecycleService } from 'vs/code/electron-main/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IUpdateService, IUpdate } from 'vs/code/electron-main/update-manager';
......@@ -27,6 +27,7 @@ import { IWindowEventService } from 'vs/code/common/windows';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import CommonEvent, { Emitter } from 'vs/base/common/event';
import product from 'vs/platform/product';
import { ParsedArgs } from 'vs/platform/environment/node/argv';
const EventTypes = {
OPEN: 'open',
......@@ -40,7 +41,7 @@ enum WindowError {
}
export interface IOpenConfiguration {
cli: ICommandLineArguments;
cli: ParsedArgs;
userEnv?: platform.IProcessEnvironment;
pathsToOpen?: string[];
preferNewWindow?: boolean;
......@@ -99,14 +100,14 @@ export interface IWindowsService {
// methods
ready(initialUserEnv: platform.IProcessEnvironment): void;
reload(win: VSCodeWindow, cli?: ICommandLineArguments): void;
reload(win: VSCodeWindow, cli?: ParsedArgs): void;
open(openConfig: IOpenConfiguration): VSCodeWindow[];
openPluginDevelopmentHostWindow(openConfig: IOpenConfiguration): void;
openFileFolderPicker(forceNewWindow?: boolean): void;
openFilePicker(forceNewWindow?: boolean): void;
openFolderPicker(forceNewWindow?: boolean): void;
openAccessibilityOptions(): void;
focusLastActive(cli: ICommandLineArguments): VSCodeWindow;
focusLastActive(cli: ParsedArgs): VSCodeWindow;
getLastActiveWindow(): VSCodeWindow;
findWindow(workspacePath: string, filePath?: string, extensionDevelopmentPath?: string): VSCodeWindow;
openNewWindow(): void;
......@@ -542,7 +543,7 @@ export class WindowsManager implements IWindowsService {
}
}
public reload(win: VSCodeWindow, cli?: ICommandLineArguments): void {
public reload(win: VSCodeWindow, cli?: ParsedArgs): void {
// Only reload when the window has not vetoed this
this.lifecycleService.unload(win).done(veto => {
......@@ -598,7 +599,7 @@ export class WindowsManager implements IWindowsService {
// Otherwise infer from command line arguments
else {
const ignoreFileNotFound = openConfig.cli.paths.length > 0; // we assume the user wants to create this file from command line
const ignoreFileNotFound = openConfig.cli._.length > 0; // we assume the user wants to create this file from command line
iPathsToOpen = this.cliToPaths(openConfig.cli, ignoreFileNotFound);
}
......@@ -824,26 +825,26 @@ export class WindowsManager implements IWindowsService {
}
// Fill in previously opened workspace unless an explicit path is provided and we are not unit testing
if (openConfig.cli.paths.length === 0 && !openConfig.cli.extensionTestsPath) {
if (openConfig.cli._.length === 0 && !openConfig.cli.extensionTestsPath) {
const workspaceToOpen = this.windowsState.lastPluginDevelopmentHostWindow && this.windowsState.lastPluginDevelopmentHostWindow.workspacePath;
if (workspaceToOpen) {
openConfig.cli.paths = [workspaceToOpen];
openConfig.cli._ = [workspaceToOpen];
}
}
// Make sure we are not asked to open a path that is already opened
if (openConfig.cli.paths.length > 0) {
res = WindowsManager.WINDOWS.filter(w => w.openedWorkspacePath && openConfig.cli.paths.indexOf(w.openedWorkspacePath) >= 0);
if (openConfig.cli._.length > 0) {
res = WindowsManager.WINDOWS.filter(w => w.openedWorkspacePath && openConfig.cli._.indexOf(w.openedWorkspacePath) >= 0);
if (res.length) {
openConfig.cli.paths = [];
openConfig.cli._ = [];
}
}
// Open it
this.open({ cli: openConfig.cli, forceNewWindow: true, forceEmpty: openConfig.cli.paths.length === 0 });
this.open({ cli: openConfig.cli, forceNewWindow: true, forceEmpty: openConfig.cli._.length === 0 });
}
private toConfiguration(userEnv: platform.IProcessEnvironment, cli: ICommandLineArguments, workspacePath?: string, filesToOpen?: IPath[], filesToCreate?: IPath[], filesToDiff?: IPath[]): IWindowConfiguration {
private toConfiguration(userEnv: platform.IProcessEnvironment, cli: ParsedArgs, workspacePath?: string, filesToOpen?: IPath[], filesToCreate?: IPath[], filesToDiff?: IPath[]): IWindowConfiguration {
const configuration: IWindowConfiguration = mixin({}, cli); // inherit all properties from CLI
configuration.appRoot = this.environmentService.appRoot;
configuration.execPath = process.execPath;
......@@ -888,12 +889,12 @@ export class WindowsManager implements IWindowsService {
return null;
}
private cliToPaths(cli: ICommandLineArguments, ignoreFileNotFound?: boolean): IPath[] {
private cliToPaths(cli: ParsedArgs, ignoreFileNotFound?: boolean): IPath[] {
// Check for pass in candidate or last opened path
let candidates: string[] = [];
if (cli.paths.length > 0) {
candidates = cli.paths;
if (cli._.length > 0) {
candidates = cli._;
}
// No path argument, check settings for what to do now
......@@ -1139,7 +1140,7 @@ export class WindowsManager implements IWindowsService {
});
}
public focusLastActive(cli: ICommandLineArguments): VSCodeWindow {
public focusLastActive(cli: ParsedArgs): VSCodeWindow {
const lastActive = this.getLastActiveWindow();
if (lastActive) {
lastActive.focus();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册