Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
efef7903
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,发现更多精彩内容 >>
提交
efef7903
编写于
6月 13, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Settings editor - Attempt 1 at introducing parent to the tree data model
上级
5989a718
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
48 deletion
+67
-48
src/vs/workbench/parts/preferences/browser/settingsEditor2.ts
...vs/workbench/parts/preferences/browser/settingsEditor2.ts
+13
-7
src/vs/workbench/parts/preferences/browser/settingsTree.ts
src/vs/workbench/parts/preferences/browser/settingsTree.ts
+49
-38
src/vs/workbench/parts/preferences/browser/tocTree.ts
src/vs/workbench/parts/preferences/browser/tocTree.ts
+5
-3
未找到文件。
src/vs/workbench/parts/preferences/browser/settingsEditor2.ts
浏览文件 @
efef7903
...
...
@@ -11,8 +11,9 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import
{
Color
}
from
'
vs/base/common/color
'
;
import
{
getErrorMessage
,
isPromiseCanceledError
}
from
'
vs/base/common/errors
'
;
import
{
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
import
{
escapeRegExpCharacters
}
from
'
vs/base/common/strings
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ITree
Configuration
,
ITree
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
{
ITree
,
ITreeConfiguration
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
{
DefaultTreestyler
}
from
'
vs/base/parts/tree/browser/treeDefaults
'
;
import
'
vs/css!./media/settingsEditor2
'
;
import
{
localize
}
from
'
vs/nls
'
;
...
...
@@ -29,14 +30,13 @@ import { ICssStyleCollector, ITheme, IThemeService, registerThemingParticipant }
import
{
BaseEditor
}
from
'
vs/workbench/browser/parts/editor/baseEditor
'
;
import
{
EditorOptions
,
IEditor
}
from
'
vs/workbench/common/editor
'
;
import
{
SearchWidget
,
SettingsTarget
,
SettingsTargetsWidget
}
from
'
vs/workbench/parts/preferences/browser/preferencesWidgets
'
;
import
{
ISettingsEditorViewState
,
SearchResultIdx
,
SearchResultModel
,
SettingsAccessibilityProvider
,
SettingsDataSource
,
SettingsRenderer
,
SettingsTreeController
,
SettingsTreeFilter
,
TreeElement
}
from
'
vs/workbench/parts/preferences/browser/settingsTree
'
;
import
{
tocData
}
from
'
vs/workbench/parts/preferences/browser/settingsLayout
'
;
import
{
ISettingsEditorViewState
,
SearchResultIdx
,
SearchResultModel
,
SettingsAccessibilityProvider
,
SettingsDataSource
,
SettingsRenderer
,
SettingsTreeController
,
SettingsTreeFilter
,
TreeElement
,
isTOCLeaf
}
from
'
vs/workbench/parts/preferences/browser/settingsTree
'
;
import
{
TOCDataSource
,
TOCRenderer
}
from
'
vs/workbench/parts/preferences/browser/tocTree
'
;
import
{
CONTEXT_SETTINGS_EDITOR
,
CONTEXT_SETTINGS_SEARCH_FOCUS
,
IPreferencesSearchService
,
ISearchProvider
}
from
'
vs/workbench/parts/preferences/common/preferences
'
;
import
{
IPreferencesService
,
ISearchResult
,
ISetting
,
ISettingsEditorModel
}
from
'
vs/workbench/services/preferences/common/preferences
'
;
import
{
SettingsEditor2Input
}
from
'
vs/workbench/services/preferences/common/preferencesEditorInput
'
;
import
{
DefaultSettingsEditorModel
}
from
'
vs/workbench/services/preferences/common/preferencesModels
'
;
import
{
tocData
}
from
'
vs/workbench/parts/preferences/browser/settingsLayout
'
;
import
{
escapeRegExpCharacters
}
from
'
vs/base/common/strings
'
;
const
$
=
DOM
.
$
;
...
...
@@ -638,19 +638,25 @@ export class SettingsEditor2 extends BaseEditor {
export
interface
ITOCEntry
<
T
>
{
id
:
string
;
label
:
string
;
}
export
interface
ITOCGroupEntry
<
T
>
extends
ITOCEntry
<
T
>
{
children
?:
ITOCEntry
<
T
>
[];
}
export
interface
ITOCLeafEntry
<
T
>
extends
ITOCEntry
<
T
>
{
settings
?:
T
[];
}
export
type
IRawTOCEntry
=
ITOCEntry
<
string
>
;
export
type
IResolvedTOCEntry
=
ITOCEntry
<
ISetting
>
;
export
type
IRawTOCEntry
=
ITOC
GroupEntry
<
string
>
|
ITOCLeaf
Entry
<
string
>
;
export
type
IResolvedTOCEntry
=
ITOC
GroupEntry
<
ISetting
>
|
ITOCLeaf
Entry
<
ISetting
>
;
function
resolveSettingsTree
(
tocData
:
IRawTOCEntry
,
defaultSettings
:
DefaultSettingsEditorModel
):
IResolvedTOCEntry
{
return
_resolveSettingsTree
(
tocData
,
getAllSettings
(
defaultSettings
));
}
function
_resolveSettingsTree
(
tocData
:
IRawTOCEntry
,
allSettings
:
Set
<
ISetting
>
):
IResolvedTOCEntry
{
if
(
tocData
.
settings
)
{
if
(
isTOCLeaf
(
tocData
)
)
{
return
<
IResolvedTOCEntry
>
{
id
:
tocData
.
id
,
label
:
tocData
.
label
,
...
...
src/vs/workbench/parts/preferences/browser/settingsTree.ts
浏览文件 @
efef7903
...
...
@@ -25,8 +25,8 @@ import { editorActiveLinkForeground, registerColor } from 'vs/platform/theme/com
import
{
attachButtonStyler
,
attachInputBoxStyler
,
attachSelectBoxStyler
}
from
'
vs/platform/theme/common/styler
'
;
import
{
ICssStyleCollector
,
ITheme
,
IThemeService
,
registerThemingParticipant
}
from
'
vs/platform/theme/common/themeService
'
;
import
{
SettingsTarget
}
from
'
vs/workbench/parts/preferences/browser/preferencesWidgets
'
;
import
{
IResolvedTOCEntry
,
ITOCGroupEntry
,
ITOCLeafEntry
,
ITOCEntry
}
from
'
vs/workbench/parts/preferences/browser/settingsEditor2
'
;
import
{
ISearchResult
,
ISetting
}
from
'
vs/workbench/services/preferences/common/preferences
'
;
import
{
IResolvedTOCEntry
}
from
'
vs/workbench/parts/preferences/browser/settingsEditor2
'
;
const
$
=
DOM
.
$
;
...
...
@@ -56,6 +56,7 @@ export interface ISettingElement extends ITreeItem {
type
:
TreeItemType
.
setting
;
setting
:
ISetting
;
parent
:
IGroupElement
|
SearchResultModel
;
displayCategory
:
string
;
displayLabel
:
string
;
value
:
any
;
...
...
@@ -68,6 +69,7 @@ export interface ISettingElement extends ITreeItem {
export
interface
IGroupElement
extends
ITreeItem
{
type
:
TreeItemType
.
groupTitle
;
parent
:
IGroupElement
|
IResolvedTOCEntry
;
group
:
IResolvedTOCEntry
;
index
:
number
;
}
...
...
@@ -92,16 +94,17 @@ export class SettingsDataSource implements IDataSource {
@
IConfigurationService
private
configurationService
:
IConfigurationService
)
{
}
getGroupElement
(
group
:
IResolvedTOCEntry
,
index
:
number
):
IGroupElement
{
getGroupElement
(
group
:
IResolvedTOCEntry
,
parent
:
IGroupElement
|
IResolvedTOCEntry
,
index
:
number
):
IGroupElement
{
return
<
IGroupElement
>
{
type
:
TreeItemType
.
groupTitle
,
group
,
parent
,
id
:
sanitizeElementId
(
group
.
id
),
index
};
}
getSettingElement
(
setting
:
ISetting
,
group
:
IResolvedTOCEntry
):
ISettingElement
{
getSettingElement
(
setting
:
ISetting
,
parent
:
IGroupElement
|
SearchResultModel
,
category
:
string
):
ISettingElement
{
const
{
isConfigured
,
inspected
,
targetSelector
}
=
inspectSetting
(
setting
.
key
,
this
.
viewState
.
settingsTarget
,
this
.
configurationService
);
const
displayValue
=
isConfigured
?
inspected
[
targetSelector
]
:
inspected
.
default
;
...
...
@@ -114,10 +117,10 @@ export class SettingsDataSource implements IDataSource {
overriddenScopeList
.
push
(
localize
(
'
user
'
,
"
User
"
));
}
const
displayKeyFormat
=
settingKeyToDisplayFormat
(
setting
.
key
,
group
);
const
displayKeyFormat
=
settingKeyToDisplayFormat
(
setting
.
key
,
category
);
return
<
ISettingElement
>
{
type
:
TreeItemType
.
setting
,
parent
:
group
,
parent
,
id
:
sanitizeElementId
(
setting
.
key
),
setting
,
...
...
@@ -139,7 +142,7 @@ export class SettingsDataSource implements IDataSource {
}
hasChildren
(
tree
:
ITree
,
element
:
TreeElementOrRoot
):
boolean
{
if
(
isRoot
(
element
))
{
if
(
is
TOC
Root
(
element
))
{
return
true
;
}
...
...
@@ -154,36 +157,44 @@ export class SettingsDataSource implements IDataSource {
return
false
;
}
_getChildren
(
element
:
TreeElementOrRoot
):
TreeElement
[]
{
if
(
isRoot
(
element
))
{
private
_getChildren
(
element
:
TreeElementOrRoot
):
TreeElement
[]
{
if
(
is
TOC
Root
(
element
))
{
return
this
.
getRootChildren
(
element
);
}
else
if
(
element
instanceof
SearchResultModel
)
{
return
this
.
get
GroupChildren
(
element
.
resultsAsGroup
()
);
return
this
.
get
SearchResultChildren
(
element
);
}
else
if
(
element
.
type
===
TreeItemType
.
groupTitle
)
{
return
this
.
getGroupChildren
(
element
.
group
);
return
this
.
getGroupChildren
(
element
);
}
else
{
// No children...
return
null
;
}
}
private
getSearchResultChildren
(
searchResult
:
SearchResultModel
):
ISettingElement
[]
{
return
searchResult
.
getFlatSettings
()
.
map
(
s
=>
this
.
getSettingElement
(
s
,
searchResult
,
'
searchResult
'
));
}
getChildren
(
tree
:
ITree
,
element
:
TreeElementOrRoot
):
TPromise
<
any
,
any
>
{
return
TPromise
.
as
(
this
.
_getChildren
(
element
));
}
private
getRootChildren
(
root
:
I
ResolvedTOCEntry
):
TreeElement
[]
{
private
getRootChildren
(
root
:
I
TOCGroupEntry
<
ISetting
>
):
TreeElement
[]
{
return
root
.
children
.
map
((
g
,
i
)
=>
this
.
getGroupElement
(
g
,
i
));
.
map
((
g
,
i
)
=>
this
.
getGroupElement
(
g
,
root
,
i
));
}
private
getGroupChildren
(
group
:
IResolvedTOCEntry
):
TreeElement
[]
{
return
group
.
children
?
group
.
children
.
map
((
child
,
i
)
=>
this
.
getGroupElement
(
child
,
i
))
:
group
.
settings
.
map
(
s
=>
this
.
getSettingElement
(
s
,
group
));
private
getGroupChildren
(
group
Element
:
IGroupElement
):
TreeElement
[]
{
return
isTOCLeaf
(
groupElement
.
group
)
?
group
Element
.
group
.
settings
.
map
(
s
=>
this
.
getSettingElement
(
s
,
groupElement
,
groupElement
.
id
))
:
group
Element
.
group
.
children
.
map
((
child
,
i
)
=>
this
.
getGroupElement
(
child
,
groupElement
,
i
));
}
getParent
(
tree
:
ITree
,
element
:
TreeElement
):
TPromise
<
any
,
any
>
{
return
TPromise
.
wrap
(
null
);
getParent
(
tree
:
ITree
,
element
:
TreeElementOrRoot
):
TPromise
<
any
,
any
>
{
return
TPromise
.
wrap
(
isTOCRoot
(
element
)
?
null
:
element
instanceof
SearchResultModel
?
null
:
element
.
parent
);
}
}
...
...
@@ -191,11 +202,11 @@ function sanitizeElementId(id: string): string {
return
id
.
replace
(
/
\.
/g
,
'
_
'
);
}
function
isRoot
(
element
:
TreeElementOrRoot
):
element
is
IResolvedTOCEntry
{
function
is
TOC
Root
(
element
:
TreeElementOrRoot
):
element
is
IResolvedTOCEntry
{
return
element
.
id
===
'
root
'
;
}
export
function
settingKeyToDisplayFormat
(
key
:
string
,
group
:
IResolvedTOCEntry
):
{
category
:
string
,
label
:
string
}
{
export
function
settingKeyToDisplayFormat
(
key
:
string
,
group
Id
:
string
):
{
category
:
string
,
label
:
string
}
{
let
label
=
key
.
replace
(
/
\.([
a-z
])
/g
,
(
match
,
p1
)
=>
`.
${
p1
.
toUpperCase
()}
`
)
.
replace
(
/
([
a-z
])([
A-Z
])
/g
,
'
$1 $2
'
)
// fooBar => foo Bar
...
...
@@ -208,14 +219,14 @@ export function settingKeyToDisplayFormat(key: string, group: IResolvedTOCEntry)
label
=
label
.
substr
(
lastDotIdx
+
1
);
}
category
=
trimCategoryForGroup
(
category
,
group
);
category
=
trimCategoryForGroup
(
category
,
group
Id
);
return
{
category
,
label
};
}
function
trimCategoryForGroup
(
category
:
string
,
group
:
IResolvedTOCEntry
):
string
{
function
trimCategoryForGroup
(
category
:
string
,
group
Id
:
string
):
string
{
const
doTrim
=
forward
=>
{
const
parts
=
group
.
i
d
.
split
(
'
.
'
);
const
parts
=
group
I
d
.
split
(
'
.
'
);
while
(
parts
.
length
)
{
const
reg
=
new
RegExp
(
`^
${
parts
.
join
(
'
\\
.
'
)}
(\\.|$)`
,
'
i
'
);
if
(
reg
.
test
(
category
))
{
...
...
@@ -571,16 +582,16 @@ export class SettingsTreeFilter implements IFilter {
return
true
;
}
private
groupHasConfiguredSetting
(
group
:
IResolvedTOCEntry
):
boolean
{
if
(
group
.
children
)
{
return
group
.
children
.
some
(
c
=>
this
.
groupHasConfiguredSetting
(
c
));
}
for
(
let
setting
of
group
.
settings
)
{
const
{
isConfigured
}
=
inspectSetting
(
setting
.
key
,
this
.
viewState
.
settingsTarget
,
this
.
configurationService
);
if
(
isConfigured
)
{
return
true
;
private
groupHasConfiguredSetting
(
element
:
IResolvedTOCEntry
):
boolean
{
if
(
isTOCLeaf
(
element
))
{
for
(
let
setting
of
element
.
settings
)
{
const
{
isConfigured
}
=
inspectSetting
(
setting
.
key
,
this
.
viewState
.
settingsTarget
,
this
.
configurationService
);
if
(
isConfigured
)
{
return
true
;
}
}
}
else
{
return
element
.
children
.
some
(
c
=>
this
.
groupHasConfiguredSetting
(
c
));
}
return
false
;
...
...
@@ -658,7 +669,7 @@ export class SearchResultModel {
this
.
rawSearchResults
[
type
]
=
result
;
}
resultsAsGroup
():
IResolvedTOCEntry
{
getFlatSettings
():
ISetting
[]
{
const
flatSettings
:
ISetting
[]
=
[];
this
.
getUniqueResults
()
.
filter
(
r
=>
!!
r
)
...
...
@@ -667,10 +678,10 @@ export class SearchResultModel {
...
r
.
filterMatches
.
map
(
m
=>
m
.
setting
));
});
return
<
IResolvedTOCEntry
>
{
id
:
'
settingsSearchResultGroup
'
,
settings
:
flatSettings
,
label
:
'
searchResults
'
};
return
flatSettings
;
}
}
export
function
isTOCLeaf
<
T
>
(
entry
:
ITOCEntry
<
T
>
):
entry
is
ITOCLeafEntry
<
T
>
{
return
!!
(
<
ITOCLeafEntry
<
T
>>
entry
).
settings
;
}
src/vs/workbench/parts/preferences/browser/tocTree.ts
浏览文件 @
efef7903
...
...
@@ -6,7 +6,9 @@
import
*
as
DOM
from
'
vs/base/browser/dom
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IDataSource
,
IRenderer
,
ITree
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
{
IResolvedTOCEntry
}
from
'
vs/workbench/parts/preferences/browser/settingsEditor2
'
;
import
{
IResolvedTOCEntry
,
ITOCGroupEntry
}
from
'
vs/workbench/parts/preferences/browser/settingsEditor2
'
;
import
{
ISetting
}
from
'
vs/workbench/services/preferences/common/preferences
'
;
import
{
isTOCLeaf
}
from
'
vs/workbench/parts/preferences/browser/settingsTree
'
;
const
$
=
DOM
.
$
;
...
...
@@ -21,10 +23,10 @@ export class TOCDataSource implements IDataSource {
}
hasChildren
(
tree
:
ITree
,
element
:
IResolvedTOCEntry
):
boolean
{
return
element
.
children
&&
element
.
children
.
length
&&
typeof
element
.
children
[
0
]
!==
'
string
'
;
return
!
isTOCLeaf
(
element
)
&&
element
.
children
.
length
&&
typeof
element
.
children
[
0
]
!==
'
string
'
;
}
getChildren
(
tree
:
ITree
,
element
:
I
ResolvedTOCEntry
):
TPromise
<
IResolvedTOCEntry
[],
any
>
{
getChildren
(
tree
:
ITree
,
element
:
I
TOCGroupEntry
<
ISetting
>
):
TPromise
<
IResolvedTOCEntry
[],
any
>
{
return
TPromise
.
as
(
<
IResolvedTOCEntry
[]
>
element
.
children
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录