Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
55354382
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,发现更多精彩内容 >>
提交
55354382
编写于
9月 11, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement getTitle/getDescription for untitled editors
上级
3d6f59a3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
68 deletion
+123
-68
src/vs/workbench/browser/parts/editor/tabsTitleControl.ts
src/vs/workbench/browser/parts/editor/tabsTitleControl.ts
+64
-54
src/vs/workbench/common/editor/untitledEditorInput.ts
src/vs/workbench/common/editor/untitledEditorInput.ts
+50
-2
src/vs/workbench/parts/files/common/editors/fileEditorInput.ts
...s/workbench/parts/files/common/editors/fileEditorInput.ts
+9
-12
未找到文件。
src/vs/workbench/browser/parts/editor/tabsTitleControl.ts
浏览文件 @
55354382
...
...
@@ -51,6 +51,8 @@ interface IEditorInputLabel {
title
?:
string
;
}
type
AugmentedLabel
=
IEditorInputLabel
&
{
editor
:
IEditorInput
};
export
class
TabsTitleControl
extends
TitleControl
{
private
titleContainer
:
HTMLElement
;
private
tabsContainer
:
HTMLElement
;
...
...
@@ -342,7 +344,6 @@ export class TabsTitleControl extends TitleControl {
const
{
verbosity
,
shortenDuplicates
}
=
this
.
getSubtitleConfigFlags
(
tabSubtitleStyle
);
// Build labels and descriptions for each editor
type
AugmentedLabel
=
IEditorInputLabel
&
{
editor
:
IEditorInput
};
const
labels
=
editors
.
map
(
editor
=>
({
editor
,
name
:
editor
.
getName
(),
...
...
@@ -350,72 +351,81 @@ export class TabsTitleControl extends TitleControl {
title
:
editor
.
getTitle
(
Verbosity
.
LONG
)
}));
// Shorten labels as needed
if
(
shortenDuplicates
)
{
// gather duplicate titles, while filtering out invalid descriptions
const
mapTitleToDuplicates
=
new
Map
<
string
,
AugmentedLabel
[]
>
();
for
(
const
label
of
labels
)
{
if
(
typeof
label
.
description
===
'
string
'
&&
label
.
description
)
{
getOrSet
(
mapTitleToDuplicates
,
label
.
name
,
[]).
push
(
label
);
}
else
{
label
.
description
=
''
;
}
this
.
shortenTabLabels
(
labels
);
}
return
labels
;
}
private
shortenTabLabels
(
labels
:
AugmentedLabel
[]):
void
{
// Gather duplicate titles, while filtering out invalid descriptions
const
mapTitleToDuplicates
=
new
Map
<
string
,
AugmentedLabel
[]
>
();
for
(
const
label
of
labels
)
{
if
(
typeof
label
.
description
===
'
string
'
&&
label
.
description
)
{
getOrSet
(
mapTitleToDuplicates
,
label
.
name
,
[]).
push
(
label
);
}
else
{
label
.
description
=
''
;
}
}
// identify duplicate titles and shorten descriptions
mapTitleToDuplicates
.
forEach
(
duplicateTitles
=>
{
// remove description if the title isn't duplicated
if
(
duplicateTitles
.
length
===
1
)
{
duplicateTitles
[
0
].
description
=
''
;
return
;
}
// Identify duplicate titles and shorten descriptions
mapTitleToDuplicates
.
forEach
(
duplicateTitles
=>
{
// identify duplicate descriptions
const
mapDescriptionToDuplicates
=
new
Map
<
string
,
AugmentedLabel
[]
>
();
for
(
const
label
of
duplicateTitles
)
{
getOrSet
(
mapDescriptionToDuplicates
,
label
.
description
,
[]).
push
(
label
);
// Remove description if the title isn't duplicated
if
(
duplicateTitles
.
length
===
1
)
{
duplicateTitles
[
0
].
description
=
''
;
return
;
}
// Identify duplicate descriptions
const
mapDescriptionToDuplicates
=
new
Map
<
string
,
AugmentedLabel
[]
>
();
for
(
const
label
of
duplicateTitles
)
{
getOrSet
(
mapDescriptionToDuplicates
,
label
.
description
,
[]).
push
(
label
);
}
// For editors with duplicate descriptions, check whether any long descriptions differ
let
useLongDescriptions
=
false
;
mapDescriptionToDuplicates
.
forEach
((
duplicateDescriptions
,
name
)
=>
{
if
(
!
useLongDescriptions
&&
duplicateDescriptions
.
length
>
1
)
{
const
[
first
,
...
rest
]
=
duplicateDescriptions
.
map
(({
editor
})
=>
editor
.
getDescription
(
Verbosity
.
LONG
));
useLongDescriptions
=
rest
.
some
(
description
=>
description
!==
first
);
}
});
// for editors with duplicate descriptions, check whether any long descriptions differ
let
useLongDescriptions
=
false
;
mapDescriptionToDuplicates
.
forEach
((
duplicateDescriptions
,
name
)
=>
{
if
(
!
useLongDescriptions
&&
duplicateDescriptions
.
length
>
1
)
{
const
[
first
,
...
rest
]
=
duplicateDescriptions
.
map
(({
editor
})
=>
editor
.
getDescription
(
Verbosity
.
LONG
));
useLongDescriptions
=
rest
.
some
(
description
=>
description
!==
first
);
}
// If so, replace all descriptions with long descriptions
if
(
useLongDescriptions
)
{
mapDescriptionToDuplicates
.
clear
();
duplicateTitles
.
forEach
(
label
=>
{
label
.
description
=
label
.
editor
.
getDescription
(
Verbosity
.
LONG
);
getOrSet
(
mapDescriptionToDuplicates
,
label
.
description
,
[]).
push
(
label
);
});
}
// if so, replace all descriptions with long descriptions
if
(
useLongDescriptions
)
{
mapDescriptionToDuplicates
.
clear
();
duplicateTitles
.
forEach
(
label
=>
{
label
.
description
=
label
.
editor
.
getDescription
(
Verbosity
.
LONG
);
getOrSet
(
mapDescriptionToDuplicates
,
label
.
description
,
[]).
push
(
label
);
});
// Obtain final set of descriptions
const
descriptions
:
string
[]
=
[];
mapDescriptionToDuplicates
.
forEach
((
_
,
description
)
=>
descriptions
.
push
(
description
));
// Remove description if all descriptions are identical
if
(
descriptions
.
length
===
1
)
{
for
(
const
label
of
mapDescriptionToDuplicates
.
get
(
descriptions
[
0
]))
{
label
.
description
=
''
;
}
// obtain final set of descriptions
const
descriptions
:
string
[]
=
[];
mapDescriptionToDuplicates
.
forEach
((
_
,
description
)
=>
descriptions
.
push
(
description
));
return
;
}
// remove description if all descriptions are identical
if
(
descriptions
.
length
===
1
)
{
for
(
const
label
of
mapDescriptionToDuplicates
.
get
(
descriptions
[
0
]))
{
label
.
description
=
''
;
}
return
;
// Shorten descriptions
const
shortenedDescriptions
=
shorten
(
descriptions
);
descriptions
.
forEach
((
description
,
i
)
=>
{
for
(
const
label
of
mapDescriptionToDuplicates
.
get
(
description
))
{
label
.
description
=
shortenedDescriptions
[
i
];
}
// shorten descriptions
const
shortenedDescriptions
=
shorten
(
descriptions
);
descriptions
.
forEach
((
description
,
i
)
=>
{
for
(
const
label
of
mapDescriptionToDuplicates
.
get
(
description
))
{
label
.
description
=
shortenedDescriptions
[
i
];
}
});
});
}
return
labels
;
});
}
private
getSubtitleConfigFlags
(
value
:
string
)
{
...
...
src/vs/workbench/common/editor/untitledEditorInput.ts
浏览文件 @
55354382
...
...
@@ -19,6 +19,7 @@ import Event, { Emitter } from 'vs/base/common/event';
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
telemetryURIDescriptor
}
from
'
vs/platform/telemetry/common/telemetryUtils
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
Verbosity
}
from
'
vs/platform/editor/common/editor
'
;
/**
* An editor input to be used for untitled text buffers.
...
...
@@ -36,6 +37,14 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
private
toUnbind
:
IDisposable
[];
private
shortDescription
:
string
;
private
mediumDescription
:
string
;
private
longDescription
:
string
;
private
shortTitle
:
string
;
private
mediumTitle
:
string
;
private
longTitle
:
string
;
constructor
(
private
resource
:
URI
,
hasAssociatedFilePath
:
boolean
,
...
...
@@ -88,8 +97,47 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
return
this
.
hasAssociatedFilePath
?
paths
.
basename
(
this
.
resource
.
fsPath
)
:
this
.
resource
.
fsPath
;
}
public
getDescription
():
string
{
return
this
.
hasAssociatedFilePath
?
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
this
.
contextService
,
this
.
environmentService
)
:
null
;
public
getDescription
(
verbosity
:
Verbosity
=
Verbosity
.
MEDIUM
):
string
{
if
(
!
this
.
hasAssociatedFilePath
)
{
return
null
;
}
let
description
:
string
;
switch
(
verbosity
)
{
case
Verbosity
.
SHORT
:
description
=
this
.
shortDescription
?
this
.
shortDescription
:
(
this
.
shortDescription
=
paths
.
basename
(
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
void
0
,
this
.
environmentService
)));
break
;
case
Verbosity
.
LONG
:
description
=
this
.
longDescription
?
this
.
longDescription
:
(
this
.
longDescription
=
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
void
0
,
this
.
environmentService
));
break
;
case
Verbosity
.
MEDIUM
:
default
:
description
=
this
.
mediumDescription
?
this
.
mediumDescription
:
(
this
.
mediumDescription
=
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
this
.
contextService
,
this
.
environmentService
));
break
;
}
return
description
;
}
public
getTitle
(
verbosity
:
Verbosity
):
string
{
if
(
!
this
.
hasAssociatedFilePath
)
{
return
this
.
getName
();
}
let
title
:
string
;
switch
(
verbosity
)
{
case
Verbosity
.
SHORT
:
title
=
this
.
shortTitle
?
this
.
shortTitle
:
(
this
.
shortTitle
=
this
.
getName
());
break
;
case
Verbosity
.
MEDIUM
:
title
=
this
.
mediumTitle
?
this
.
mediumTitle
:
(
this
.
mediumTitle
=
labels
.
getPathLabel
(
this
.
resource
,
this
.
contextService
,
this
.
environmentService
));
break
;
case
Verbosity
.
LONG
:
title
=
this
.
longTitle
?
this
.
longTitle
:
(
this
.
longTitle
=
labels
.
getPathLabel
(
this
.
resource
,
void
0
,
this
.
environmentService
));
break
;
}
return
title
;
}
public
isDirty
():
boolean
{
...
...
src/vs/workbench/parts/files/common/editors/fileEditorInput.ts
浏览文件 @
55354382
...
...
@@ -131,24 +131,21 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
}
public
getDescription
(
verbosity
:
Verbosity
=
Verbosity
.
MEDIUM
):
string
{
let
description
:
string
;
switch
(
verbosity
)
{
case
Verbosity
.
SHORT
:
if
(
!
this
.
shortDescription
)
{
this
.
shortDescription
=
paths
.
basename
(
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
void
0
,
this
.
environmentService
));
}
return
this
.
shortDescription
;
description
=
this
.
shortDescription
?
this
.
shortDescription
:
(
this
.
shortDescription
=
paths
.
basename
(
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
void
0
,
this
.
environmentService
)));
break
;
case
Verbosity
.
LONG
:
if
(
!
this
.
longDescription
)
{
this
.
longDescription
=
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
void
0
,
this
.
environmentService
);
}
return
this
.
longDescription
;
description
=
this
.
longDescription
?
this
.
longDescription
:
(
this
.
longDescription
=
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
void
0
,
this
.
environmentService
));
break
;
case
Verbosity
.
MEDIUM
:
default
:
if
(
!
this
.
mediumDescription
)
{
this
.
mediumDescription
=
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
this
.
contextService
,
this
.
environmentService
);
}
return
this
.
mediumDescription
;
description
=
this
.
mediumDescription
?
this
.
mediumDescription
:
(
this
.
mediumDescription
=
labels
.
getPathLabel
(
paths
.
dirname
(
this
.
resource
.
fsPath
),
this
.
contextService
,
this
.
environmentService
));
break
;
}
return
description
;
}
public
getTitle
(
verbosity
:
Verbosity
):
string
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录