-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add IOpenerService and use it with webview, #3676
- Loading branch information
Showing
6 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 URI from 'vs/base/common/uri'; | ||
import {TPromise} from 'vs/base/common/winjs.base'; | ||
import {createDecorator} from 'vs/platform/instantiation/common/instantiation'; | ||
|
||
export const IOpenerService = createDecorator<IOpenerService>('openerService'); | ||
|
||
|
||
export interface IOpenerService { | ||
|
||
serviceId: any; | ||
|
||
/** | ||
* Opens a resource, like a webadress, a document uri, or executes command. | ||
* | ||
* @param resource A resource | ||
* @return A promise that resolves when the opening is done. | ||
*/ | ||
open(resource: URI): TPromise<any>; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/vs/platform/opener/electron-browser/opener.contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 {registerSingleton} from 'vs/platform/instantiation/common/extensions'; | ||
import {OpenerService} from 'vs/platform/opener/electron-browser/openerService'; | ||
import {IOpenerService} from 'vs/platform/opener/common/opener'; | ||
|
||
registerSingleton(IOpenerService, OpenerService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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 URI from 'vs/base/common/uri'; | ||
import {Schemas} from 'vs/base/common/network'; | ||
import {TPromise} from 'vs/base/common/winjs.base'; | ||
import {IEditorService} from 'vs/platform/editor/common/editor'; | ||
import {IKeybindingService} from 'vs/platform/keybinding/common/keybindingService'; | ||
import {IOpenerService} from '../common/opener'; | ||
|
||
export class OpenerService implements IOpenerService { | ||
|
||
serviceId: any; | ||
|
||
constructor( | ||
@IEditorService private _editorService: IEditorService, | ||
@IKeybindingService private _keybindingService: IKeybindingService | ||
) { | ||
// | ||
} | ||
|
||
open(resource: URI): TPromise<any> { | ||
|
||
const {scheme, path, query, fragment} = resource; | ||
let promise: TPromise<any>; | ||
if (scheme === Schemas.http || scheme === Schemas.https) { | ||
// open http | ||
window.open(resource.toString(true)); | ||
|
||
} else if (scheme === 'command' && this._keybindingService.hasCommand(path)) { | ||
// execute as command | ||
let args: any; | ||
try { | ||
args = JSON.parse(query); | ||
} catch (e) { | ||
// | ||
} | ||
promise = this._keybindingService.executeCommand(path, Array.isArray(args) ? args : [args]); | ||
|
||
} else { | ||
promise = this._editorService.resolveEditorModel({ resource }).then(model => { | ||
if (!model) { | ||
return; | ||
} | ||
// support file:///some/file.js#L73 | ||
let selection: { | ||
startLineNumber: number; | ||
startColumn: number; | ||
}; | ||
if (/^L\d+$/.test(fragment)) { | ||
selection = { | ||
startLineNumber: parseInt(fragment.substr(1)), | ||
startColumn: 1 | ||
}; | ||
} | ||
return this._editorService.openEditor({ resource, options: { selection } }); | ||
}); | ||
} | ||
|
||
return TPromise.as(promise).then(undefined, err => { }); // !ignores all errors | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters