diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index ebf203412f67c..cf69be0bc52f2 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -21,6 +21,7 @@ export interface IWindowsService { openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise; openFilePicker(windowId: number, forceNewWindow?: boolean, path?: string): TPromise; openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise; + openFileForURI(filePath: String): TPromise; reloadWindow(windowId: number): TPromise; openDevTools(windowId: number): TPromise; toggleDevTools(windowId: number): TPromise; diff --git a/src/vs/platform/windows/common/windowsIpc.ts b/src/vs/platform/windows/common/windowsIpc.ts index 55e70ee622a78..b1ea792f5460d 100644 --- a/src/vs/platform/windows/common/windowsIpc.ts +++ b/src/vs/platform/windows/common/windowsIpc.ts @@ -14,6 +14,7 @@ export interface IWindowsChannel extends IChannel { call(command: 'event:onWindowOpen'): TPromise; call(command: 'event:onWindowFocus'): TPromise; call(command: 'openFileFolderPicker', arg: [number, boolean]): TPromise; + call(command: 'openFileForURI', arg: string): TPromise; call(command: 'openFilePicker', arg: [number, boolean, string]): TPromise; call(command: 'openFolderPicker', arg: [number, boolean]): TPromise; call(command: 'reloadWindow', arg: number): TPromise; @@ -57,6 +58,7 @@ export class WindowsChannel implements IWindowsChannel { case 'event:onWindowOpen': return eventToCall(this.onWindowOpen); case 'event:onWindowFocus': return eventToCall(this.onWindowFocus); case 'openFileFolderPicker': return this.service.openFileFolderPicker(arg[0], arg[1]); + case 'openFileForURI': return this.service.openFileForURI(arg); case 'openFilePicker': return this.service.openFilePicker(arg[0], arg[1], arg[2]); case 'openFolderPicker': return this.service.openFolderPicker(arg[0], arg[1]); case 'reloadWindow': return this.service.reloadWindow(arg); @@ -99,6 +101,10 @@ export class WindowsChannelClient implements IWindowsService { private _onWindowFocus: Event = eventFromCall(this.channel, 'event:onWindowFocus'); get onWindowFocus(): Event { return this._onWindowFocus; } + openFileForURI(filePath: string): TPromise { + return this.channel.call('openFileForURI', filePath); + } + openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise { return this.channel.call('openFileFolderPicker', [windowId, forceNewWindow]); } diff --git a/src/vs/platform/windows/electron-main/windowsService.ts b/src/vs/platform/windows/electron-main/windowsService.ts index 9416f75458fc6..9020e0423e3d7 100644 --- a/src/vs/platform/windows/electron-main/windowsService.ts +++ b/src/vs/platform/windows/electron-main/windowsService.ts @@ -9,8 +9,9 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IWindowsService } from 'vs/platform/windows/common/windows'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { shell, crashReporter, app } from 'electron'; -import Event from 'vs/base/common/event'; +import Event, { chain } from 'vs/base/common/event'; import { fromEventEmitter } from 'vs/base/node/event'; +import { IURLService } from 'vs/platform/url/common/url'; // TODO@Joao: remove this dependency, move all implementation to this class import { IWindowsMainService } from 'vs/code/electron-main/windows'; @@ -24,14 +25,31 @@ export class WindowsService implements IWindowsService { constructor( @IWindowsMainService private windowsMainService: IWindowsMainService, - @IEnvironmentService private environmentService: IEnvironmentService - ) { } + @IEnvironmentService private environmentService: IEnvironmentService, + @IURLService private urlService: IURLService + ) { + chain(urlService.onOpenURL) + .filter(uri => uri.authority === 'file') + .on(uri => this.openFileForURI(uri.path), this); + } openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise { this.windowsMainService.openFileFolderPicker(forceNewWindow); return TPromise.as(null); } + openFileForURI(filePath: string): TPromise { + if (!filePath || !filePath.length) { + return TPromise.as(null); + } + + var envServiceArgs = this.environmentService.args; + envServiceArgs.goto = true; + + this.windowsMainService.open({ cli: envServiceArgs, pathsToOpen: [filePath] }); + return TPromise.as(null); + } + openFilePicker(windowId: number, forceNewWindow?: boolean, path?: string): TPromise { this.windowsMainService.openFilePicker(forceNewWindow, path); return TPromise.as(null);