Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support opening files through URL handling (fixes #4883) #15320

Merged
merged 1 commit into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/platform/windows/common/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IWindowsService {
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
openFilePicker(windowId: number, forceNewWindow?: boolean, path?: string): TPromise<void>;
openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
openFileForURI(filePath: String): TPromise<void>;
reloadWindow(windowId: number): TPromise<void>;
openDevTools(windowId: number): TPromise<void>;
toggleDevTools(windowId: number): TPromise<void>;
Expand Down
6 changes: 6 additions & 0 deletions src/vs/platform/windows/common/windowsIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IWindowsChannel extends IChannel {
call(command: 'event:onWindowOpen'): TPromise<number>;
call(command: 'event:onWindowFocus'): TPromise<number>;
call(command: 'openFileFolderPicker', arg: [number, boolean]): TPromise<void>;
call(command: 'openFileForURI', arg: string): TPromise<void>;
call(command: 'openFilePicker', arg: [number, boolean, string]): TPromise<void>;
call(command: 'openFolderPicker', arg: [number, boolean]): TPromise<void>;
call(command: 'reloadWindow', arg: number): TPromise<void>;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -99,6 +101,10 @@ export class WindowsChannelClient implements IWindowsService {
private _onWindowFocus: Event<number> = eventFromCall<number>(this.channel, 'event:onWindowFocus');
get onWindowFocus(): Event<number> { return this._onWindowFocus; }

openFileForURI(filePath: string): TPromise<void> {
return this.channel.call('openFileForURI', filePath);
}

openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
return this.channel.call('openFileFolderPicker', [windowId, forceNewWindow]);
}
Expand Down
24 changes: 21 additions & 3 deletions src/vs/platform/windows/electron-main/windowsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<void> {
this.windowsMainService.openFileFolderPicker(forceNewWindow);
return TPromise.as(null);
}

openFileForURI(filePath: string): TPromise<void> {
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<void> {
this.windowsMainService.openFilePicker(forceNewWindow, path);
return TPromise.as(null);
Expand Down