Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d295bff1
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d295bff1
编写于
4月 14, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add IOpenerService and use it with webview, #3676
上级
37f6bc48
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
135 addition
and
2 deletion
+135
-2
src/vs/platform/opener/common/opener.ts
src/vs/platform/opener/common/opener.ts
+25
-0
src/vs/platform/opener/electron-browser/opener.contribution.ts
...s/platform/opener/electron-browser/opener.contribution.ts
+12
-0
src/vs/platform/opener/electron-browser/openerService.ts
src/vs/platform/opener/electron-browser/openerService.ts
+65
-0
src/vs/workbench/electron-browser/shell.ts
src/vs/workbench/electron-browser/shell.ts
+3
-0
src/vs/workbench/parts/html/browser/htmlPreviewPart.ts
src/vs/workbench/parts/html/browser/htmlPreviewPart.ts
+13
-2
src/vs/workbench/parts/html/browser/webview.html
src/vs/workbench/parts/html/browser/webview.html
+17
-0
未找到文件。
src/vs/platform/opener/common/opener.ts
0 → 100644
浏览文件 @
d295bff1
/*---------------------------------------------------------------------------------------------
* 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
>
;
}
src/vs/platform/opener/electron-browser/opener.contribution.ts
0 → 100644
浏览文件 @
d295bff1
/*---------------------------------------------------------------------------------------------
* 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
);
src/vs/platform/opener/electron-browser/openerService.ts
0 → 100644
浏览文件 @
d295bff1
/*---------------------------------------------------------------------------------------------
* 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
}
}
src/vs/workbench/electron-browser/shell.ts
浏览文件 @
d295bff1
...
...
@@ -93,6 +93,9 @@ import {IExtensionsService} from 'vs/workbench/parts/extensions/common/extension
import
{
ExtensionsService
}
from
'
vs/workbench/parts/extensions/node/extensionsService
'
;
import
{
ReloadWindowAction
}
from
'
vs/workbench/electron-browser/actions
'
;
// self registering service
import
'
vs/platform/opener/electron-browser/opener.contribution
'
;
/**
* Services that we require for the Shell
*/
...
...
src/vs/workbench/parts/html/browser/htmlPreviewPart.ts
浏览文件 @
d295bff1
...
...
@@ -24,6 +24,7 @@ import {BaseTextEditorModel} from 'vs/workbench/common/editor/textEditorModel';
import
{
HtmlInput
}
from
'
vs/workbench/parts/html/common/htmlInput
'
;
import
{
IThemeService
}
from
'
vs/workbench/services/themes/common/themeService
'
;
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
IOpenerService
}
from
'
vs/platform/opener/common/opener
'
;
KeybindingsRegistry
.
registerCommandDesc
({
id
:
'
_webview.openDevTools
'
,
...
...
@@ -62,7 +63,7 @@ class ManagedWebview {
private
_ready
:
TPromise
<
this
>
;
private
_disposables
:
IDisposable
[];
constructor
(
private
_parent
:
HTMLElement
,
private
_layoutParent
:
HTMLElement
,
private
_styleElement
)
{
constructor
(
private
_parent
:
HTMLElement
,
private
_layoutParent
:
HTMLElement
,
private
_styleElement
,
onDidClickLink
:(
uri
:
URI
)
=>
any
)
{
this
.
_webview
=
<
Webview
>
document
.
createElement
(
'
webview
'
);
this
.
_webview
.
style
.
zIndex
=
'
1
'
;
this
.
_webview
.
style
.
position
=
'
absolute
'
;
...
...
@@ -88,6 +89,12 @@ class ManagedWebview {
}),
addDisposableListener
(
this
.
_webview
,
'
crashed
'
,
function
()
{
console
.
error
(
'
embedded page crashed
'
);
}),
addDisposableListener
(
this
.
_webview
,
'
ipc-message
'
,
(
event
)
=>
{
if
(
event
.
channel
===
'
did-click-link
'
)
{
let
[
uri
]
=
event
.
args
;
onDidClickLink
(
URI
.
parse
(
uri
));
}
})
];
...
...
@@ -190,6 +197,7 @@ export class HtmlPreviewPart extends BaseEditor {
private
_editorService
:
IWorkbenchEditorService
;
private
_themeService
:
IThemeService
;
private
_openerService
:
IOpenerService
;
private
_webview
:
ManagedWebview
;
private
_container
:
HTMLDivElement
;
...
...
@@ -203,12 +211,14 @@ export class HtmlPreviewPart extends BaseEditor {
@
ITelemetryService
telemetryService
:
ITelemetryService
,
@
IWorkbenchEditorService
editorService
:
IWorkbenchEditorService
,
@
IThemeService
themeService
:
IThemeService
,
@
IOpenerService
openerService
:
IOpenerService
,
@
IWorkspaceContextService
contextService
:
IWorkspaceContextService
)
{
super
(
HtmlPreviewPart
.
ID
,
telemetryService
);
this
.
_editorService
=
editorService
;
this
.
_themeService
=
themeService
;
this
.
_openerService
=
openerService
;
this
.
_baseUrl
=
contextService
.
toResource
(
'
/
'
);
}
...
...
@@ -232,7 +242,8 @@ export class HtmlPreviewPart extends BaseEditor {
if
(
!
this
.
_webview
)
{
this
.
_webview
=
new
ManagedWebview
(
document
.
getElementById
(
'
workbench.main.container
'
),
this
.
_container
,
document
.
querySelector
(
'
.monaco-editor-background
'
));
document
.
querySelector
(
'
.monaco-editor-background
'
),
uri
=>
this
.
_openerService
.
open
(
uri
));
this
.
_webview
.
baseUrl
=
this
.
_baseUrl
&&
this
.
_baseUrl
.
toString
();
}
...
...
src/vs/workbench/parts/html/browser/webview.html
浏览文件 @
d295bff1
...
...
@@ -66,6 +66,17 @@
newDocument
.
head
.
appendChild
(
defaultStyles
);
}
// script to bubble out link-clicks
const
defaultScripts
=
newDocument
.
createElement
(
'
script
'
);
defaultScripts
.
innerHTML
=
`
document.body.addEventListener('click', function (event) {
if(event.target.tagName === 'A' && event.target.href) {
window.parent.postMessage({ command: 'did-click-link', data: event.target.href }, 'file://');
event.preventDefault();
}
});`
newDocument
.
body
.
appendChild
(
defaultScripts
);
// write new content onto iframe
target
.
contentDocument
.
open
(
'
text/html
'
,
'
replace
'
);
target
.
contentDocument
.
write
(
newDocument
.
documentElement
.
innerHTML
);
...
...
@@ -73,6 +84,12 @@
});
// forward messages from the embedded iframe
window
.
onmessage
=
function
(
message
)
{
const
{
command
,
data
}
=
message
.
data
;
ipcRenderer
.
sendToHost
(
command
,
data
);
};
// signal ready, needs a short timeout for an
// unknown reason
setTimeout
(
function
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录