Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4527146d
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,发现更多精彩内容 >>
提交
4527146d
编写于
5月 10, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more shuffling
上级
c5b9234d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
143 addition
and
151 deletion
+143
-151
src/vs/workbench/browser/parts/editor/editorPart.ts
src/vs/workbench/browser/parts/editor/editorPart.ts
+143
-151
未找到文件。
src/vs/workbench/browser/parts/editor/editorPart.ts
浏览文件 @
4527146d
...
...
@@ -227,195 +227,152 @@ export class EditorPart extends Part implements IEditorPart {
});
}
private
doShowEditor
(
editorD
escriptor
:
EditorDescriptor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
widthRatios
:
number
[],
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
private
doShowEditor
(
d
escriptor
:
EditorDescriptor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
widthRatios
:
number
[],
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
// Return early if the currently visible editor can handle the input
if
(
this
.
visibleEditors
[
position
]
&&
editorD
escriptor
.
describes
(
this
.
visibleEditors
[
position
]))
{
return
this
.
mapEditorCreationPromiseToEditor
[
position
][
editorD
escriptor
.
getId
()]
||
TPromise
.
as
(
this
.
visibleEditors
[
position
]);
if
(
this
.
visibleEditors
[
position
]
&&
d
escriptor
.
describes
(
this
.
visibleEditors
[
position
]))
{
return
this
.
mapEditorCreationPromiseToEditor
[
position
][
d
escriptor
.
getId
()]
||
TPromise
.
as
(
this
.
visibleEditors
[
position
]);
}
let
activeEditorHidePromise
:
TPromise
<
BaseEditor
>
;
if
(
this
.
visibleEditors
[
position
])
{
activeEditorHidePromise
=
this
.
hideEditor
(
this
.
visibleEditors
[
position
],
position
,
false
);
// Editor can not handle Input (Close this Editor)
}
else
{
activeEditorHidePromise
=
TPromise
.
as
(
null
);
// Editor needs to be created first
}
return
activeEditorHidePromise
.
then
(()
=>
{
let
timerEvent
=
timer
.
start
(
timer
.
Topic
.
WORKBENCH
,
strings
.
format
(
'
Creating Editor: {0}
'
,
editorDescriptor
.
getName
()));
// We need the container for this editor now
let
editorContainer
=
this
.
mapEditorToEditorContainers
[
position
][
editorDescriptor
.
getId
()];
let
newlyCreatedEditorContainerBuilder
:
Builder
;
if
(
!
editorContainer
)
{
// Build Container off-DOM
editorContainer
=
$
().
div
({
'
class
'
:
'
editor-container
'
,
id
:
editorDescriptor
.
getId
()
},
(
div
)
=>
{
newlyCreatedEditorContainerBuilder
=
div
;
});
// Remember editor container
this
.
mapEditorToEditorContainers
[
position
][
editorDescriptor
.
getId
()]
=
editorContainer
;
}
// Create or get editor from cache
let
editor
=
this
.
instantiatedEditors
[
position
].
filter
(
e
=>
editorDescriptor
.
describes
(
e
))[
0
]
||
null
;
let
loadOrGetEditorPromise
:
TPromise
<
BaseEditor
>
;
if
(
editor
===
null
)
{
// Check if loading is pending from another openEditor
let
pendingEditorLoad
=
this
.
mapEditorLoadingPromiseToEditor
[
position
][
editorDescriptor
.
getId
()];
if
(
pendingEditorLoad
)
{
loadOrGetEditorPromise
=
pendingEditorLoad
;
}
// Otherwise load
else
{
let
loaded
=
false
;
let
progressService
=
new
WorkbenchProgressService
(
this
.
eventService
,
this
.
sideBySideControl
.
getProgressBar
(
position
),
editorDescriptor
.
getId
(),
true
);
let
editorInstantiationService
=
this
.
instantiationService
.
createChild
(
new
ServiceCollection
([
IProgressService
,
progressService
]));
loadOrGetEditorPromise
=
editorInstantiationService
.
createInstance
(
editorDescriptor
).
then
((
editor
:
BaseEditor
)
=>
{
loaded
=
true
;
this
.
instantiatedEditors
[
position
].
push
(
editor
);
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
editorDescriptor
.
getId
()];
// 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
editor
;
},
(
error
)
=>
{
loaded
=
true
;
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
editorDescriptor
.
getId
()];
// Create Editor
let
timerEvent
=
timer
.
start
(
timer
.
Topic
.
WORKBENCH
,
strings
.
format
(
'
Creating Editor: {0}
'
,
descriptor
.
getName
()));
return
this
.
doCreateEditor
(
descriptor
,
position
,
monitor
).
then
(
editor
=>
{
return
TPromise
.
wrapError
(
error
);
});
if
(
!
loaded
)
{
this
.
mapEditorLoadingPromiseToEditor
[
position
][
editorDescriptor
.
getId
()]
=
loadOrGetEditorPromise
;
}
}
}
else
{
loadOrGetEditorPromise
=
TPromise
.
as
(
editor
);
}
return
loadOrGetEditorPromise
.
then
((
editor
)
=>
{
// Make sure that the user meanwhile did not open another editor
if
(
monitor
.
token
!==
this
.
editorOpenToken
[
position
])
{
// Make sure that the user meanwhile did not open another editor or something went wrong
if
(
!
editor
||
!
this
.
visibleEditors
[
position
]
||
editor
.
getId
()
!==
this
.
visibleEditors
[
position
].
getId
())
{
timerEvent
.
stop
();
// Stop loading promise if any
monitor
.
cancel
();
return
null
;
}
//
Remember Editor at position
this
.
visibleEditors
[
position
]
=
editor
;
//
Show in side by side control
this
.
sideBySideControl
.
show
(
editor
,
this
.
mapEditorToEditorContainers
[
position
][
descriptor
.
getId
()],
position
,
options
&&
options
.
preserveFocus
,
widthRatios
)
;
//
Register as Emitter to Workbench Bus
this
.
visibleEditorListeners
[
position
].
push
(
this
.
eventService
.
addEmitter
(
this
.
visibleEditors
[
position
],
this
.
visibleEditors
[
position
].
getId
()));
//
Indicate to editor that it is now visible
return
editor
.
setVisible
(
true
,
position
).
then
(()
=>
{
let
createEditorPromise
:
TPromise
<
any
>
;
if
(
newlyCreatedEditorContainerBuilder
)
{
// Editor created for the first time
// Make sure the editor is layed out
this
.
sideBySideControl
.
layout
(
position
);
// create editor
let
created
=
false
;
createEditorPromise
=
editor
.
create
(
newlyCreatedEditorContainerBuilder
).
then
(()
=>
{
created
=
true
;
delete
this
.
mapEditorCreationPromiseToEditor
[
position
][
editorDescriptor
.
getId
()];
},
(
error
)
=>
{
created
=
true
;
delete
this
.
mapEditorCreationPromiseToEditor
[
position
][
editorDescriptor
.
getId
()];
// Emit Editor-Opened Event
this
.
emit
(
WorkbenchEventType
.
EDITOR_OPENED
,
new
EditorEvent
(
editor
,
editor
.
getId
(),
input
,
options
,
position
));
return
TPromise
.
wrapError
(
error
);
});
timerEvent
.
stop
();
if
(
!
created
)
{
this
.
mapEditorCreationPromiseToEditor
[
position
][
editorDescriptor
.
getId
()]
=
createEditorPromise
;
}
}
return
editor
;
});
},
(
e
:
any
)
=>
this
.
messageService
.
show
(
Severity
.
Error
,
types
.
isString
(
e
)
?
new
Error
(
e
)
:
e
));
});
}
// Editor already exists but is hidden or pending to create
else
{
private
doCreateEditor
(
descriptor
:
EditorDescriptor
,
position
:
Position
,
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
// Check if create is pending from another openEditor
let
pendingEditorCreate
=
this
.
mapEditorCreationPromiseToEditor
[
position
][
editorDescriptor
.
getId
()];
if
(
pendingEditorCreate
)
{
createEditorPromise
=
pendingEditorCreate
;
}
else
{
createEditorPromise
=
TPromise
.
as
(
null
);
}
}
// We need the container for this editor now
let
editorContainer
=
this
.
mapEditorToEditorContainers
[
position
][
descriptor
.
getId
()];
let
newlyCreatedEditorContainerBuilder
:
Builder
;
if
(
!
editorContainer
)
{
// Fill Content and Actions
return
createEditorPromise
.
then
(()
=>
{
// Build Container off-DOM
editorContainer
=
$
().
div
({
'
class
'
:
'
editor-container
'
,
id
:
descriptor
.
getId
()
},
(
div
)
=>
{
newlyCreatedEditorContainerBuilder
=
div
;
});
// Make sure that the user meanwhile did not open another edito
r
if
(
!
this
.
visibleEditors
[
position
]
||
editor
.
getId
()
!==
this
.
visibleEditors
[
position
].
getId
())
{
timerEvent
.
stop
();
// Remember editor containe
r
this
.
mapEditorToEditorContainers
[
position
][
descriptor
.
getId
()]
=
editorContainer
;
}
// Stop loading promise if any
monitor
.
cancel
();
// Create or get editor from cache
let
instantiatedEditor
=
this
.
instantiatedEditors
[
position
].
filter
(
e
=>
descriptor
.
describes
(
e
))[
0
];
let
loadOrGetEditorPromise
:
TPromise
<
BaseEditor
>
;
if
(
!
instantiatedEditor
)
{
return
null
;
}
// Check if loading is pending from another openEditor
let
pendingEditorLoad
=
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
if
(
pendingEditorLoad
)
{
loadOrGetEditorPromise
=
pendingEditorLoad
;
}
// Show in side by side control
this
.
sideBySideControl
.
show
(
editor
,
editorContainer
,
position
,
options
&&
options
.
preserveFocus
,
widthRatios
);
// 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
]));
// Indicate to editor that it is now visible
return
editor
.
setVisible
(
true
,
position
).
then
(()
=>
{
loadOrGetEditorPromise
=
editorInstantiationService
.
createInstance
(
descriptor
).
then
((
editor
:
BaseEditor
)
=>
{
loaded
=
true
;
this
.
instantiatedEditors
[
position
].
push
(
editor
);
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
// Make sure the editor is layed out
this
.
sideBySideControl
.
layout
(
position
);
return
editor
;
},
(
error
)
=>
{
loaded
=
true
;
delete
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()];
// Emit Editor-Opened Event
this
.
emit
(
WorkbenchEventType
.
EDITOR_OPENED
,
new
EditorEvent
(
editor
,
editor
.
getId
(),
input
,
options
,
position
)
);
return
TPromise
.
wrapError
(
error
);
}
);
timerEvent
.
stop
();
if
(
!
loaded
)
{
this
.
mapEditorLoadingPromiseToEditor
[
position
][
descriptor
.
getId
()]
=
loadOrGetEditorPromise
;
}
}
}
else
{
loadOrGetEditorPromise
=
TPromise
.
as
(
instantiatedEditor
);
}
return
editor
;
});
},
(
e
:
any
)
=>
this
.
messageService
.
show
(
Severity
.
Error
,
types
.
isString
(
e
)
?
new
Error
(
e
)
:
e
));
});
});
}
return
loadOrGetEditorPromise
.
then
((
editor
)
=>
{
private
doCloseEditor
(
input
:
EditorInput
,
position
:
Position
):
TPromise
<
BaseEditor
>
{
if
(
this
.
visibleEditors
[
position
])
{
// Make sure that the user meanwhile did not open another editor
if
(
monitor
.
token
!==
this
.
editorOpenToken
[
position
])
{
monitor
.
cancel
();
// Reset counter
this
.
editorSetInputErrorCounter
[
position
]
=
0
;
return
null
;
}
//
Emit Input-Changing Event
this
.
emit
(
WorkbenchEventType
.
EDITOR_INPUT_CHANGING
,
new
EditorEvent
(
null
,
null
,
null
,
null
,
position
))
;
//
Remember Editor at position
this
.
visibleEditors
[
position
]
=
editor
;
//
Hide Editor
return
this
.
hideEditor
(
this
.
visibleEditors
[
position
],
position
,
true
).
then
(()
=>
{
//
Register as Emitter to Workbench Bus
this
.
visibleEditorListeners
[
position
].
push
(
this
.
eventService
.
addEmitter
(
this
.
visibleEditors
[
position
],
this
.
visibleEditors
[
position
].
getId
()));
// Emit Input-Changed Event
this
.
emit
(
WorkbenchEventType
.
EDITOR_INPUT_CHANGED
,
new
EditorEvent
(
null
,
null
,
null
,
null
,
position
));
let
createEditorPromise
:
TPromise
<
any
>
;
if
(
newlyCreatedEditorContainerBuilder
)
{
// Editor created for the first time
let
created
=
false
;
createEditorPromise
=
editor
.
create
(
newlyCreatedEditorContainerBuilder
).
then
(()
=>
{
created
=
true
;
delete
this
.
mapEditorCreationPromiseToEditor
[
position
][
descriptor
.
getId
()];
},
(
error
)
=>
{
created
=
true
;
delete
this
.
mapEditorCreationPromiseToEditor
[
position
][
descriptor
.
getId
()];
// Focus next editor if there is still an active one left
let
currentActiveEditor
=
this
.
sideBySideControl
.
getActiveEditor
();
if
(
currentActiveEditor
)
{
return
this
.
openEditor
(
currentActiveEditor
.
input
,
null
,
currentActiveEditor
.
position
).
then
(()
=>
{
// Explicitly trigger the focus changed handler because the side by side control will not trigger it unless
// the user is actively changing focus with the mouse from left to right.
this
.
onEditorFocusChanged
();
return
TPromise
.
wrapError
(
error
);
});
return
currentActiveEditor
;
})
;
if
(
!
created
)
{
this
.
mapEditorCreationPromiseToEditor
[
position
][
descriptor
.
getId
()]
=
createEditorPromise
;
}
}
return
TPromise
.
as
<
BaseEditor
>
(
null
);
});
}
// Editor already exists but is hidden or pending to create
else
{
return
TPromise
.
as
<
BaseEditor
>
(
null
);
// Check if create is pending from another openEditor
let
pendingEditorCreate
=
this
.
mapEditorCreationPromiseToEditor
[
position
][
descriptor
.
getId
()];
if
(
pendingEditorCreate
)
{
createEditorPromise
=
pendingEditorCreate
;
}
else
{
createEditorPromise
=
TPromise
.
as
(
null
);
}
}
return
createEditorPromise
.
then
(()
=>
editor
);
});
}
private
doSetInput
(
editor
:
BaseEditor
,
input
:
EditorInput
,
options
:
EditorOptions
,
position
:
Position
,
monitor
:
ProgressMonitor
):
TPromise
<
BaseEditor
>
{
...
...
@@ -531,7 +488,42 @@ export class EditorPart extends Part implements IEditorPart {
});
}
private
hideEditor
(
editor
:
BaseEditor
,
position
:
Position
,
layoutAndRochade
:
boolean
):
TPromise
<
BaseEditor
>
{
private
doCloseEditor
(
input
:
EditorInput
,
position
:
Position
):
TPromise
<
BaseEditor
>
{
if
(
this
.
visibleEditors
[
position
])
{
// Reset counter
this
.
editorSetInputErrorCounter
[
position
]
=
0
;
// Emit Input-Changing Event
this
.
emit
(
WorkbenchEventType
.
EDITOR_INPUT_CHANGING
,
new
EditorEvent
(
null
,
null
,
null
,
null
,
position
));
// Hide Editor
return
this
.
doHideEditor
(
this
.
visibleEditors
[
position
],
position
,
true
).
then
(()
=>
{
// Emit Input-Changed Event
this
.
emit
(
WorkbenchEventType
.
EDITOR_INPUT_CHANGED
,
new
EditorEvent
(
null
,
null
,
null
,
null
,
position
));
// Focus next editor if there is still an active one left
let
currentActiveEditor
=
this
.
sideBySideControl
.
getActiveEditor
();
if
(
currentActiveEditor
)
{
return
this
.
openEditor
(
currentActiveEditor
.
input
,
null
,
currentActiveEditor
.
position
).
then
(()
=>
{
// Explicitly trigger the focus changed handler because the side by side control will not trigger it unless
// the user is actively changing focus with the mouse from left to right.
this
.
onEditorFocusChanged
();
return
currentActiveEditor
;
});
}
return
TPromise
.
as
<
BaseEditor
>
(
null
);
});
}
return
TPromise
.
as
<
BaseEditor
>
(
null
);
}
private
doHideEditor
(
editor
:
BaseEditor
,
position
:
Position
,
layoutAndRochade
:
boolean
):
TPromise
<
BaseEditor
>
{
let
editorContainer
=
this
.
mapEditorToEditorContainers
[
position
][
editor
.
getId
()];
// Hide in side by side control
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录