Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b1c59a14
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,发现更多精彩内容 >>
提交
b1c59a14
编写于
5月 11, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extract doInstantiateEditor
上级
d387c41b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
52 addition
and
46 deletion
+52
-46
src/vs/workbench/browser/parts/editor/editorPart.ts
src/vs/workbench/browser/parts/editor/editorPart.ts
+52
-46
未找到文件。
src/vs/workbench/browser/parts/editor/editorPart.ts
浏览文件 @
b1c59a14
...
@@ -71,6 +71,7 @@ class ProgressMonitor {
...
@@ -71,6 +71,7 @@ class ProgressMonitor {
* - need to listen to any input dispose that is opened in a stack not just the visible one to close a non active editor
* - need to listen to any input dispose that is opened in a stack not just the visible one to close a non active editor
* -> maybe just hook up a listener to the model.close event and let the model listen on dispose? this would also nicely
* -> maybe just hook up a listener to the model.close event and let the model listen on dispose? this would also nicely
* -> cover the unpin() case
* -> cover the unpin() case
* - need API to close an editor with specific input, passing in null does not really work...
*/
*/
/**
/**
...
@@ -151,7 +152,7 @@ export class EditorPart extends Part implements IEditorPart {
...
@@ -151,7 +152,7 @@ export class EditorPart extends Part implements IEditorPart {
// Emit early open event to allow for veto
// Emit early open event to allow for veto
if
(
input
)
{
if
(
input
)
{
let
event
=
new
EditorEvent
(
this
.
visibleEditors
[
position
],
this
.
visibleEditors
[
position
]
&&
this
.
visibleEditors
[
position
].
getId
()
,
input
,
options
,
position
);
let
event
=
new
EditorEvent
(
null
,
null
,
input
,
options
,
position
);
this
.
emit
(
WorkbenchEventType
.
EDITOR_INPUT_OPENING
,
event
);
this
.
emit
(
WorkbenchEventType
.
EDITOR_INPUT_OPENING
,
event
);
if
(
event
.
isPrevented
())
{
if
(
event
.
isPrevented
())
{
return
TPromise
.
as
<
BaseEditor
>
(
null
);
return
TPromise
.
as
<
BaseEditor
>
(
null
);
...
@@ -179,8 +180,8 @@ export class EditorPart extends Part implements IEditorPart {
...
@@ -179,8 +180,8 @@ export class EditorPart extends Part implements IEditorPart {
private
doOpenEditor
(
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
widthRatios
:
number
[]):
TPromise
<
BaseEditor
>
{
private
doOpenEditor
(
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
widthRatios
:
number
[]):
TPromise
<
BaseEditor
>
{
// We need an editor descriptor for the input
// We need an editor descriptor for the input
let
editorDescriptor
=
(
<
IEditorRegistry
>
Registry
.
as
(
EditorExtensions
.
Editors
)
).
getEditor
(
input
);
let
descriptor
=
Registry
.
as
<
IEditorRegistry
>
(
EditorExtensions
.
Editors
).
getEditor
(
input
);
if
(
!
editorD
escriptor
)
{
if
(
!
d
escriptor
)
{
return
TPromise
.
wrapError
(
new
Error
(
strings
.
format
(
'
Can not find a registered editor for the input {0}
'
,
input
)));
return
TPromise
.
wrapError
(
new
Error
(
strings
.
format
(
'
Can not find a registered editor for the input {0}
'
,
input
)));
}
}
...
@@ -217,7 +218,7 @@ export class EditorPart extends Part implements IEditorPart {
...
@@ -217,7 +218,7 @@ export class EditorPart extends Part implements IEditorPart {
}));
}));
// Show editor
// Show editor
return
this
.
doShowEditor
(
editorD
escriptor
,
input
,
options
,
position
,
widthRatios
,
monitor
).
then
(
editor
=>
{
return
this
.
doShowEditor
(
d
escriptor
,
input
,
options
,
position
,
widthRatios
,
monitor
).
then
(
editor
=>
{
if
(
!
editor
)
{
if
(
!
editor
)
{
return
TPromise
.
as
<
BaseEditor
>
(
null
);
// canceled or other error
return
TPromise
.
as
<
BaseEditor
>
(
null
);
// canceled or other error
}
}
...
@@ -228,14 +229,15 @@ export class EditorPart extends Part implements IEditorPart {
...
@@ -228,14 +229,15 @@ export class EditorPart extends Part implements IEditorPart {
}
}
private
doShowEditor
(
descriptor
:
EditorDescriptor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
widthRatios
:
number
[],
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
private
doShowEditor
(
descriptor
:
EditorDescriptor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
widthRatios
:
number
[],
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
const
editorAtPosition
=
this
.
visibleEditors
[
position
];
// Return early if the currently visible editor can handle the input
// Return early if the currently visible editor can handle the input
if
(
this
.
visibleEditors
[
position
]
&&
descriptor
.
describes
(
this
.
visibleEditors
[
position
]
))
{
if
(
editorAtPosition
&&
descriptor
.
describes
(
editorAtPosition
))
{
return
this
.
mapEditorCreationPromiseToEditor
[
position
][
descriptor
.
getId
()]
||
TPromise
.
as
(
this
.
visibleEditors
[
position
]
);
return
this
.
mapEditorCreationPromiseToEditor
[
position
][
descriptor
.
getId
()]
||
TPromise
.
as
(
editorAtPosition
);
}
}
// If we have an active editor, hide it first
// If we have an active editor, hide it first
return
(
this
.
visibleEditors
[
position
]
?
this
.
doHideEditor
(
this
.
visibleEditors
[
position
]
,
position
,
false
)
:
TPromise
.
as
(
null
)).
then
(()
=>
{
return
(
editorAtPosition
?
this
.
doHideEditor
(
editorAtPosition
,
position
,
false
)
:
TPromise
.
as
(
null
)).
then
(()
=>
{
// Create Editor
// Create Editor
let
timerEvent
=
timer
.
start
(
timer
.
Topic
.
WORKBENCH
,
strings
.
format
(
'
Creating Editor: {0}
'
,
descriptor
.
getName
()));
let
timerEvent
=
timer
.
start
(
timer
.
Topic
.
WORKBENCH
,
strings
.
format
(
'
Creating Editor: {0}
'
,
descriptor
.
getName
()));
...
@@ -288,45 +290,8 @@ export class EditorPart extends Part implements IEditorPart {
...
@@ -288,45 +290,8 @@ export class EditorPart extends Part implements IEditorPart {
this
.
mapEditorToEditorContainers
[
position
][
descriptor
.
getId
()]
=
editorContainer
;
this
.
mapEditorToEditorContainers
[
position
][
descriptor
.
getId
()]
=
editorContainer
;
}
}
// Create or get editor from cache
// Instantiate editor
let
instantiatedEditor
=
this
.
instantiatedEditors
[
position
].
filter
(
e
=>
descriptor
.
describes
(
e
))[
0
];
return
this
.
doInstantiateEditor
(
descriptor
,
position
).
then
(
editor
=>
{
let
loadOrGetEditorPromise
:
TPromise
<
BaseEditor
>
;
if
(
!
instantiatedEditor
)
{
// Check if loading is pending from another openEditor
let
pendingEditorLoad
=
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
if
(
pendingEditorLoad
)
{
loadOrGetEditorPromise
=
pendingEditorLoad
;
}
// Otherwise load
else
{
let
loaded
=
false
;
let
progressService
=
new
WorkbenchProgressService
(
this
.
eventService
,
this
.
sideBySideControl
.
getProgressBar
(
position
),
descriptor
.
getId
(),
true
);
let
editorInstantiationService
=
this
.
instantiationService
.
createChild
(
new
ServiceCollection
([
IProgressService
,
progressService
]));
loadOrGetEditorPromise
=
editorInstantiationService
.
createInstance
(
descriptor
).
then
((
editor
:
BaseEditor
)
=>
{
loaded
=
true
;
this
.
instantiatedEditors
[
position
].
push
(
editor
);
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
return
editor
;
},
(
error
)
=>
{
loaded
=
true
;
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
return
TPromise
.
wrapError
(
error
);
});
if
(
!
loaded
)
{
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()]
=
loadOrGetEditorPromise
;
}
}
}
else
{
loadOrGetEditorPromise
=
TPromise
.
as
(
instantiatedEditor
);
}
return
loadOrGetEditorPromise
.
then
((
editor
)
=>
{
// Make sure that the user meanwhile did not open another editor
// Make sure that the user meanwhile did not open another editor
if
(
monitor
.
token
!==
this
.
editorOpenToken
[
position
])
{
if
(
monitor
.
token
!==
this
.
editorOpenToken
[
position
])
{
...
@@ -375,6 +340,47 @@ export class EditorPart extends Part implements IEditorPart {
...
@@ -375,6 +340,47 @@ export class EditorPart extends Part implements IEditorPart {
});
});
}
}
private
doInstantiateEditor
(
descriptor
:
EditorDescriptor
,
position
:
Position
):
TPromise
<
BaseEditor
>
{
let
instantiatedEditor
=
this
.
instantiatedEditors
[
position
].
filter
(
e
=>
descriptor
.
describes
(
e
))[
0
];
let
loadEditorPromise
:
TPromise
<
BaseEditor
>
;
if
(
!
instantiatedEditor
)
{
// Check if loading is pending from another openEditor call
let
pendingEditorLoad
=
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
if
(
pendingEditorLoad
)
{
loadEditorPromise
=
pendingEditorLoad
;
}
// Otherwise load
else
{
let
loaded
=
false
;
let
progressService
=
new
WorkbenchProgressService
(
this
.
eventService
,
this
.
sideBySideControl
.
getProgressBar
(
position
),
descriptor
.
getId
(),
true
);
let
editorInstantiationService
=
this
.
instantiationService
.
createChild
(
new
ServiceCollection
([
IProgressService
,
progressService
]));
loadEditorPromise
=
editorInstantiationService
.
createInstance
(
descriptor
).
then
((
editor
:
BaseEditor
)
=>
{
loaded
=
true
;
this
.
instantiatedEditors
[
position
].
push
(
editor
);
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
return
editor
;
},
(
error
)
=>
{
loaded
=
true
;
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
return
TPromise
.
wrapError
(
error
);
});
if
(
!
loaded
)
{
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()]
=
loadEditorPromise
;
}
}
}
else
{
loadEditorPromise
=
TPromise
.
as
(
instantiatedEditor
);
}
return
loadEditorPromise
;
}
private
doSetInput
(
editor
:
BaseEditor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
private
doSetInput
(
editor
:
BaseEditor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
// Emit Input-/Options-Changed Event as appropiate
// Emit Input-/Options-Changed Event as appropiate
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录