Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
55354382
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,发现更多精彩内容 >>
提交
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,8 +351,17 @@ export class TabsTitleControl extends TitleControl {
title
:
editor
.
getTitle
(
Verbosity
.
LONG
)
}));
// Shorten labels as needed
if
(
shortenDuplicates
)
{
// gather duplicate titles, while filtering out invalid descriptions
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
)
{
...
...
@@ -361,21 +371,23 @@ export class TabsTitleControl extends TitleControl {
}
}
// i
dentify duplicate titles and shorten descriptions
// I
dentify duplicate titles and shorten descriptions
mapTitleToDuplicates
.
forEach
(
duplicateTitles
=>
{
// remove description if the title isn't duplicated
// Remove description if the title isn't duplicated
if
(
duplicateTitles
.
length
===
1
)
{
duplicateTitles
[
0
].
description
=
''
;
return
;
}
// i
dentify duplicate descriptions
// I
dentify duplicate descriptions
const
mapDescriptionToDuplicates
=
new
Map
<
string
,
AugmentedLabel
[]
>
();
for
(
const
label
of
duplicateTitles
)
{
getOrSet
(
mapDescriptionToDuplicates
,
label
.
description
,
[]).
push
(
label
);
}
// f
or editors with duplicate descriptions, check whether any long descriptions differ
// F
or editors with duplicate descriptions, check whether any long descriptions differ
let
useLongDescriptions
=
false
;
mapDescriptionToDuplicates
.
forEach
((
duplicateDescriptions
,
name
)
=>
{
if
(
!
useLongDescriptions
&&
duplicateDescriptions
.
length
>
1
)
{
...
...
@@ -384,7 +396,7 @@ export class TabsTitleControl extends TitleControl {
}
});
// i
f so, replace all descriptions with long descriptions
// I
f so, replace all descriptions with long descriptions
if
(
useLongDescriptions
)
{
mapDescriptionToDuplicates
.
clear
();
duplicateTitles
.
forEach
(
label
=>
{
...
...
@@ -393,19 +405,20 @@ export class TabsTitleControl extends TitleControl {
});
}
// o
btain final set of descriptions
// O
btain final set of descriptions
const
descriptions
:
string
[]
=
[];
mapDescriptionToDuplicates
.
forEach
((
_
,
description
)
=>
descriptions
.
push
(
description
));
// r
emove description if all descriptions are identical
// R
emove description if all descriptions are identical
if
(
descriptions
.
length
===
1
)
{
for
(
const
label
of
mapDescriptionToDuplicates
.
get
(
descriptions
[
0
]))
{
label
.
description
=
''
;
}
return
;
}
// s
horten descriptions
// S
horten descriptions
const
shortenedDescriptions
=
shorten
(
descriptions
);
descriptions
.
forEach
((
description
,
i
)
=>
{
for
(
const
label
of
mapDescriptionToDuplicates
.
get
(
description
))
{
...
...
@@ -415,9 +428,6 @@ export class TabsTitleControl extends TitleControl {
});
}
return
labels
;
}
private
getSubtitleConfigFlags
(
value
:
string
)
{
switch
(
value
)
{
case
'
short
'
:
...
...
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录