Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
b017bc48
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b017bc48
编写于
6月 03, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more details in stack events (for #6670)
上级
86f52ce4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
50 deletion
+90
-50
src/vs/workbench/common/editor.ts
src/vs/workbench/common/editor.ts
+7
-19
src/vs/workbench/common/editor/editorStacksModel.ts
src/vs/workbench/common/editor/editorStacksModel.ts
+39
-27
src/vs/workbench/test/common/editor/editorStacksModel.test.ts
...vs/workbench/test/common/editor/editorStacksModel.test.ts
+44
-4
未找到文件。
src/vs/workbench/common/editor.ts
浏览文件 @
b017bc48
...
...
@@ -593,14 +593,15 @@ export function asFileEditorInput(obj: any, supportDiff?: boolean): IFileEditorI
return
i
instanceof
EditorInput
&&
types
.
areFunctions
(
i
.
setResource
,
i
.
setMime
,
i
.
setEncoding
,
i
.
getEncoding
,
i
.
getResource
,
i
.
getMime
)
?
i
:
null
;
}
export
interface
IStacksModelChangeEvent
{
group
:
IEditorGroup
;
editor
?:
IEditorInput
;
structural
?:
boolean
;
}
export
interface
IEditorStacksModel
{
onGroupOpened
:
Event
<
IEditorGroup
>
;
onGroupClosed
:
Event
<
IEditorGroup
>
;
onGroupActivated
:
Event
<
IEditorGroup
>
;
onGroupMoved
:
Event
<
IEditorGroup
>
;
onGroupRenamed
:
Event
<
IEditorGroup
>
;
onModelChanged
:
Event
<
IEditorGroup
>
;
onModelChanged
:
Event
<
IStacksModelChangeEvent
>
;
groups
:
IEditorGroup
[];
activeGroup
:
IEditorGroup
;
...
...
@@ -631,14 +632,6 @@ export interface IEditorGroup {
activeEditor
:
IEditorInput
;
previewEditor
:
IEditorInput
;
onEditorActivated
:
Event
<
IEditorInput
>
;
onEditorOpened
:
Event
<
IEditorInput
>
;
onEditorClosed
:
Event
<
IGroupEvent
>
;
onEditorMoved
:
Event
<
IEditorInput
>
;
onEditorPinned
:
Event
<
IEditorInput
>
;
onEditorUnpinned
:
Event
<
IEditorInput
>
;
onEditorChanged
:
Event
<
IEditorInput
>
;
getEditor
(
index
:
number
):
IEditorInput
;
indexOf
(
editor
:
IEditorInput
):
number
;
...
...
@@ -651,11 +644,6 @@ export interface IEditorGroup {
isPinned
(
editor
:
IEditorInput
):
boolean
;
}
export
interface
IGroupEvent
{
editor
:
IEditorInput
;
pinned
:
boolean
;
}
export
interface
IEditorIdentifier
{
group
:
IEditorGroup
;
editor
:
IEditorInput
;
...
...
src/vs/workbench/common/editor/editorStacksModel.ts
浏览文件 @
b017bc48
...
...
@@ -6,7 +6,7 @@
'
use strict
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
EditorInput
,
getUntitledOrFileResource
,
IEditorStacksModel
,
IEditorGroup
,
I
GroupEvent
,
IEditorIdentifier
,
GroupIdentifier
}
from
'
vs/workbench/common/editor
'
;
import
{
EditorInput
,
getUntitledOrFileResource
,
IEditorStacksModel
,
IEditorGroup
,
I
EditorIdentifier
,
GroupIdentifier
,
IStacksModelChangeEvent
}
from
'
vs/workbench/common/editor
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
IStorageService
,
StorageScope
}
from
'
vs/platform/storage/common/storage
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
...
...
@@ -21,7 +21,7 @@ import {DiffEditorInput} from 'vs/workbench/common/editor/diffEditorInput';
// TODO@Ben currently only files and untitled editors are tracked with their resources in the stacks model
// Once the resource is a base concept of all editor inputs, every resource should be tracked for any editor
export
interface
GroupEvent
extends
IGroupEvent
{
export
interface
GroupEvent
{
editor
:
EditorInput
;
pinned
:
boolean
;
}
...
...
@@ -78,7 +78,8 @@ export class EditorGroup implements IEditorGroup {
private
_onEditorMoved
:
Emitter
<
EditorInput
>
;
private
_onEditorPinned
:
Emitter
<
EditorInput
>
;
private
_onEditorUnpinned
:
Emitter
<
EditorInput
>
;
private
_onEditorChanged
:
Emitter
<
EditorInput
>
;
private
_onEditorStateChanged
:
Emitter
<
EditorInput
>
;
private
_onEditorsStructureChanged
:
Emitter
<
EditorInput
>
;
constructor
(
arg1
:
string
|
ISerializedEditorGroup
,
...
...
@@ -99,9 +100,10 @@ export class EditorGroup implements IEditorGroup {
this
.
_onEditorMoved
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorPinned
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorUnpinned
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorChanged
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorStateChanged
=
new
Emitter
<
EditorInput
>
();
this
.
_onEditorsStructureChanged
=
new
Emitter
<
EditorInput
>
();
this
.
toDispose
.
push
(
this
.
_onEditorActivated
,
this
.
_onEditorOpened
,
this
.
_onEditorClosed
,
this
.
_onEditorDisposed
,
this
.
_onEditorDirty
,
this
.
_onEditorMoved
,
this
.
_onEditorPinned
,
this
.
_onEditorUnpinned
,
this
.
_onEditorChanged
);
this
.
toDispose
.
push
(
this
.
_onEditorActivated
,
this
.
_onEditorOpened
,
this
.
_onEditorClosed
,
this
.
_onEditorDisposed
,
this
.
_onEditorDirty
,
this
.
_onEditorMoved
,
this
.
_onEditorPinned
,
this
.
_onEditorUnpinned
,
this
.
_onEditor
StateChanged
,
this
.
_onEditorsStructure
Changed
);
if
(
typeof
arg1
===
'
object
'
)
{
this
.
deserialize
(
arg1
);
...
...
@@ -158,8 +160,12 @@ export class EditorGroup implements IEditorGroup {
return
this
.
_onEditorUnpinned
.
event
;
}
public
get
onEditorChanged
():
Event
<
EditorInput
>
{
return
this
.
_onEditorChanged
.
event
;
public
get
onEditorStateChanged
():
Event
<
EditorInput
>
{
return
this
.
_onEditorStateChanged
.
event
;
}
public
get
onEditorsStructureChanged
():
Event
<
EditorInput
>
{
return
this
.
_onEditorsStructureChanged
.
event
;
}
public
getEditors
(
mru
?:
boolean
):
EditorInput
[]
{
...
...
@@ -242,7 +248,7 @@ export class EditorGroup implements IEditorGroup {
this
.
hookEditorListeners
(
editor
);
// Event
this
.
fireEvent
(
this
.
_onEditorOpened
,
editor
);
this
.
fireEvent
(
this
.
_onEditorOpened
,
editor
,
true
);
// Handle active
if
(
makeActive
)
{
...
...
@@ -282,7 +288,7 @@ export class EditorGroup implements IEditorGroup {
// Re-Emit dirty state changes
unbind
.
push
(
editor
.
onDidChangeDirty
(()
=>
{
this
.
_onEditorDirty
.
fire
(
editor
);
this
.
fireEvent
(
this
.
_onEditorDirty
,
editor
,
false
);
}));
// Clean up dispose listeners once the editor gets closed
...
...
@@ -324,7 +330,7 @@ export class EditorGroup implements IEditorGroup {
this
.
splice
(
index
,
true
);
// Event
this
.
fireEvent
(
this
.
_onEditorClosed
,
{
editor
,
pinned
});
this
.
fireEvent
(
this
.
_onEditorClosed
,
{
editor
,
pinned
}
,
true
);
}
public
closeEditors
(
except
:
EditorInput
,
direction
?:
Direction
):
void
{
...
...
@@ -371,7 +377,7 @@ export class EditorGroup implements IEditorGroup {
this
.
editors
.
splice
(
toIndex
,
0
,
editor
);
// Event
this
.
fireEvent
(
this
.
_onEditorMoved
,
editor
);
this
.
fireEvent
(
this
.
_onEditorMoved
,
editor
,
true
);
}
public
setActive
(
editor
:
EditorInput
):
void
{
...
...
@@ -390,7 +396,7 @@ export class EditorGroup implements IEditorGroup {
this
.
setMostRecentlyUsed
(
editor
);
// Event
this
.
fireEvent
(
this
.
_onEditorActivated
,
editor
);
this
.
fireEvent
(
this
.
_onEditorActivated
,
editor
,
false
);
}
public
pin
(
editor
:
EditorInput
):
void
{
...
...
@@ -407,7 +413,7 @@ export class EditorGroup implements IEditorGroup {
this
.
preview
=
null
;
// Event
this
.
fireEvent
(
this
.
_onEditorPinned
,
editor
);
this
.
fireEvent
(
this
.
_onEditorPinned
,
editor
,
false
);
}
public
unpin
(
editor
:
EditorInput
):
void
{
...
...
@@ -425,7 +431,7 @@ export class EditorGroup implements IEditorGroup {
this
.
preview
=
editor
;
// Event
this
.
fireEvent
(
this
.
_onEditorUnpinned
,
editor
);
this
.
fireEvent
(
this
.
_onEditorUnpinned
,
editor
,
false
);
// Close old preview editor if any
this
.
closeEditor
(
oldPreview
);
...
...
@@ -444,9 +450,14 @@ export class EditorGroup implements IEditorGroup {
return
!
this
.
matches
(
this
.
preview
,
editor
);
}
private
fireEvent
(
emitter
:
Emitter
<
EditorInput
|
IGroupEvent
>
,
arg2
:
EditorInput
|
GroupEvent
):
void
{
private
fireEvent
(
emitter
:
Emitter
<
EditorInput
|
GroupEvent
>
,
arg2
:
EditorInput
|
GroupEvent
,
isStructuralChange
:
boolean
):
void
{
emitter
.
fire
(
arg2
);
this
.
_onEditorChanged
.
fire
(
arg2
instanceof
EditorInput
?
arg2
:
arg2
.
editor
);
if
(
isStructuralChange
)
{
this
.
_onEditorsStructureChanged
.
fire
(
arg2
instanceof
EditorInput
?
arg2
:
arg2
.
editor
);
}
else
{
this
.
_onEditorStateChanged
.
fire
(
arg2
instanceof
EditorInput
?
arg2
:
arg2
.
editor
);
}
}
private
splice
(
index
:
number
,
del
:
boolean
,
editor
?:
EditorInput
):
void
{
...
...
@@ -616,9 +627,9 @@ export class EditorStacksModel implements IEditorStacksModel {
private
_onGroupMoved
:
Emitter
<
EditorGroup
>
;
private
_onGroupActivated
:
Emitter
<
EditorGroup
>
;
private
_onGroupRenamed
:
Emitter
<
EditorGroup
>
;
private
_onModelChanged
:
Emitter
<
EditorGroup
>
;
private
_onEditorDisposed
:
Emitter
<
EditorIdentifier
>
;
private
_onEditorDirty
:
Emitter
<
EditorIdentifier
>
;
private
_onModelChanged
:
Emitter
<
IStacksModelChangeEvent
>
;
constructor
(
@
IStorageService
private
storageService
:
IStorageService
,
...
...
@@ -638,7 +649,7 @@ export class EditorStacksModel implements IEditorStacksModel {
this
.
_onGroupActivated
=
new
Emitter
<
EditorGroup
>
();
this
.
_onGroupMoved
=
new
Emitter
<
EditorGroup
>
();
this
.
_onGroupRenamed
=
new
Emitter
<
EditorGroup
>
();
this
.
_onModelChanged
=
new
Emitter
<
EditorGroup
>
();
this
.
_onModelChanged
=
new
Emitter
<
IStacksModelChangeEvent
>
();
this
.
_onEditorDisposed
=
new
Emitter
<
EditorIdentifier
>
();
this
.
_onEditorDirty
=
new
Emitter
<
EditorIdentifier
>
();
...
...
@@ -671,7 +682,7 @@ export class EditorStacksModel implements IEditorStacksModel {
return
this
.
_onGroupRenamed
.
event
;
}
public
get
onModelChanged
():
Event
<
EditorGroup
>
{
public
get
onModelChanged
():
Event
<
IStacksModelChangeEvent
>
{
return
this
.
_onModelChanged
.
event
;
}
...
...
@@ -726,7 +737,7 @@ export class EditorStacksModel implements IEditorStacksModel {
}
// Event
this
.
fireEvent
(
this
.
_onGroupOpened
,
group
);
this
.
fireEvent
(
this
.
_onGroupOpened
,
group
,
true
);
// Activate if we are first or set to activate groups
if
(
!
this
.
_activeGroup
||
activate
)
{
...
...
@@ -741,7 +752,7 @@ export class EditorStacksModel implements IEditorStacksModel {
if
(
group
.
label
!==
label
)
{
group
.
label
=
label
;
this
.
fireEvent
(
this
.
_onGroupRenamed
,
group
);
this
.
fireEvent
(
this
.
_onGroupRenamed
,
group
,
false
);
}
}
...
...
@@ -783,7 +794,7 @@ export class EditorStacksModel implements IEditorStacksModel {
this
.
groupToIdentifier
[
group
.
id
]
=
void
0
;
// Event
this
.
fireEvent
(
this
.
_onGroupClosed
,
group
);
this
.
fireEvent
(
this
.
_onGroupClosed
,
group
,
true
);
}
public
closeGroups
(
except
?:
EditorGroup
):
void
{
...
...
@@ -807,7 +818,7 @@ export class EditorStacksModel implements IEditorStacksModel {
this
.
_activeGroup
=
group
;
this
.
fireEvent
(
this
.
_onGroupActivated
,
group
);
this
.
fireEvent
(
this
.
_onGroupActivated
,
group
,
false
);
}
public
moveGroup
(
group
:
EditorGroup
,
toIndex
:
number
):
void
{
...
...
@@ -823,7 +834,7 @@ export class EditorStacksModel implements IEditorStacksModel {
this
.
_groups
.
splice
(
toIndex
,
0
,
group
);
// Event
this
.
fireEvent
(
this
.
_onGroupMoved
,
group
);
this
.
fireEvent
(
this
.
_onGroupMoved
,
group
,
true
);
}
private
indexOf
(
group
:
EditorGroup
):
number
{
...
...
@@ -922,9 +933,9 @@ export class EditorStacksModel implements IEditorStacksModel {
};
}
private
fireEvent
(
emitter
:
Emitter
<
EditorGroup
>
,
group
:
EditorGroup
):
void
{
private
fireEvent
(
emitter
:
Emitter
<
EditorGroup
>
,
group
:
EditorGroup
,
isStructuralChange
:
boolean
):
void
{
emitter
.
fire
(
group
);
this
.
_onModelChanged
.
fire
(
group
);
this
.
_onModelChanged
.
fire
(
{
group
,
structural
:
isStructuralChange
}
);
}
private
ensureLoaded
():
void
{
...
...
@@ -1040,7 +1051,8 @@ export class EditorStacksModel implements IEditorStacksModel {
// Funnel editor changes in the group through our event aggregator
const
unbind
:
IDisposable
[]
=
[];
unbind
.
push
(
group
.
onEditorChanged
(
e
=>
this
.
_onModelChanged
.
fire
(
group
)));
unbind
.
push
(
group
.
onEditorsStructureChanged
(
editor
=>
this
.
_onModelChanged
.
fire
({
group
,
editor
,
structural
:
true
})));
unbind
.
push
(
group
.
onEditorStateChanged
(
editor
=>
this
.
_onModelChanged
.
fire
({
group
,
editor
})));
unbind
.
push
(
group
.
onEditorClosed
(
e
=>
this
.
onEditorClosed
(
e
)));
unbind
.
push
(
group
.
onEditorDisposed
(
editor
=>
this
.
_onEditorDisposed
.
fire
({
editor
,
group
})));
unbind
.
push
(
group
.
onEditorDirty
(
editor
=>
this
.
_onEditorDirty
.
fire
({
editor
,
group
})));
...
...
src/vs/workbench/test/common/editor/editorStacksModel.test.ts
浏览文件 @
b017bc48
...
...
@@ -7,7 +7,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
EditorStacksModel
,
EditorGroup
,
setOpenEditorDirection
}
from
'
vs/workbench/common/editor/editorStacksModel
'
;
import
{
EditorInput
,
IFileEditorInput
,
IEditorIdentifier
,
IEditorGroup
}
from
'
vs/workbench/common/editor
'
;
import
{
EditorInput
,
IFileEditorInput
,
IEditorIdentifier
,
IEditorGroup
,
IStacksModelChangeEvent
}
from
'
vs/workbench/common/editor
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
TestStorageService
,
TestLifecycleService
,
TestContextService
,
TestWorkspace
,
TestConfiguration
}
from
'
vs/workbench/test/common/servicesTestUtils
'
;
import
{
InstantiationService
}
from
'
vs/platform/instantiation/common/instantiationService
'
;
...
...
@@ -39,6 +39,7 @@ interface ModelEvents {
moved
:
IEditorGroup
[];
renamed
:
IEditorGroup
[];
disposed
:
IEditorIdentifier
[];
changed
:
IStacksModelChangeEvent
[];
}
interface
GroupEvents
{
...
...
@@ -57,7 +58,8 @@ function modelListener(model: EditorStacksModel): ModelEvents {
closed
:
[],
moved
:
[],
renamed
:
[],
disposed
:
[]
disposed
:
[],
changed
:
[]
};
model
.
onGroupOpened
(
g
=>
modelEvents
.
opened
.
push
(
g
));
...
...
@@ -66,11 +68,12 @@ function modelListener(model: EditorStacksModel): ModelEvents {
model
.
onGroupMoved
(
g
=>
modelEvents
.
moved
.
push
(
g
));
model
.
onGroupRenamed
(
g
=>
modelEvents
.
renamed
.
push
(
g
));
model
.
onEditorDisposed
(
e
=>
modelEvents
.
disposed
.
push
(
e
));
model
.
onModelChanged
(
e
=>
modelEvents
.
changed
.
push
(
e
));
return
modelEvents
;
}
function
groupListener
(
group
:
I
EditorGroup
):
GroupEvents
{
function
groupListener
(
group
:
EditorGroup
):
GroupEvents
{
const
groupEvents
=
{
opened
:
[],
closed
:
[],
...
...
@@ -312,7 +315,7 @@ suite('Editor Stacks Model', () => {
test
(
'
Groups - Event Aggregation
'
,
function
()
{
const
model
=
create
();
let
groupEvents
:
I
EditorGroup
[]
=
[];
let
groupEvents
:
I
StacksModelChangeEvent
[]
=
[];
let
count
=
groupEvents
.
length
;
model
.
onModelChanged
(
group
=>
{
groupEvents
.
push
(
group
);
...
...
@@ -1650,4 +1653,41 @@ suite('Editor Stacks Model', () => {
assert
.
equal
(
dirtyCounter
,
2
);
});
test
(
'
Groups - Model change events (structural vs state)
'
,
function
()
{
const
model
=
create
();
const
events
=
modelListener
(
model
);
const
group1
=
model
.
openGroup
(
'
first
'
);
assert
.
equal
(
events
.
changed
[
0
].
group
,
group1
);
assert
.
equal
(
events
.
changed
[
0
].
structural
,
true
);
// open group
assert
.
equal
(
events
.
changed
[
1
].
group
,
group1
);
assert
.
ok
(
!
events
.
changed
[
1
].
structural
);
// set active
const
input1
=
input
();
group1
.
openEditor
(
input1
,
{
pinned
:
true
,
active
:
true
});
assert
.
equal
(
events
.
changed
[
2
].
group
,
group1
);
assert
.
equal
(
events
.
changed
[
2
].
structural
,
true
);
// open editor
assert
.
equal
(
events
.
changed
[
2
].
editor
,
input1
);
assert
.
equal
(
events
.
changed
[
3
].
group
,
group1
);
assert
.
ok
(
!
events
.
changed
[
3
].
structural
);
// set active
assert
.
equal
(
events
.
changed
[
3
].
editor
,
input1
);
group1
.
unpin
(
input1
);
assert
.
equal
(
events
.
changed
[
4
].
group
,
group1
);
assert
.
ok
(
!
events
.
changed
[
4
].
structural
);
// unpin
assert
.
equal
(
events
.
changed
[
4
].
editor
,
input1
);
group1
.
closeAllEditors
();
assert
.
equal
(
events
.
changed
[
5
].
group
,
group1
);
assert
.
ok
(
events
.
changed
[
5
].
structural
);
// close
assert
.
equal
(
events
.
changed
[
5
].
editor
,
input1
);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录