Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
5dbfe32b
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,体验更适合开发者的 AI 搜索 >>
提交
5dbfe32b
编写于
12月 29, 2020
作者:
A
Alex Ross
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow tree item command to be resolved later
Part of #110498
上级
3a70241a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
11 deletion
+34
-11
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+3
-2
src/vs/workbench/api/common/extHostTreeViews.ts
src/vs/workbench/api/common/extHostTreeViews.ts
+12
-4
src/vs/workbench/browser/parts/views/treeView.ts
src/vs/workbench/browser/parts/views/treeView.ts
+16
-3
src/vs/workbench/common/views.ts
src/vs/workbench/common/views.ts
+3
-2
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
5dbfe32b
...
...
@@ -8867,7 +8867,8 @@ declare module 'vscode' {
getParent
?(
element
:
T
):
ProviderResult
<
T
>
;
/**
* Called only on hover to resolve the [TreeItem](#TreeItem.tooltip) property if it is undefined.
* Called on hover to resolve the [TreeItem](#TreeItem.tooltip) property if it is undefined.
* Called on tree item click/open to resolve the [TreeItem](#TreeItem.command) property if it is undefined.
* Only properties that were undefined can be resolved in `resolveTreeItem`.
* Functionality may be expanded later to include being called to resolve other missing
* properties on selection and/or on open.
...
...
@@ -8877,7 +8878,7 @@ declare module 'vscode' {
* onDidChangeTreeData should not be triggered from within resolveTreeItem.
*
* *Note* that this function is called when tree items are already showing in the UI.
* Because of that, no property that changes the presentation (label, description,
command,
etc.)
* Because of that, no property that changes the presentation (label, description, etc.)
* can be changed.
*
* @param element The object associated with the TreeItem
...
...
src/vs/workbench/api/common/extHostTreeViews.ts
浏览文件 @
5dbfe32b
...
...
@@ -21,6 +21,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import
{
MarkdownString
}
from
'
vs/workbench/api/common/extHostTypeConverters
'
;
import
{
IMarkdownString
}
from
'
vs/base/common/htmlContent
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
Command
}
from
'
vs/editor/common/modes
'
;
type
TreeItemHandle
=
string
;
...
...
@@ -184,6 +185,7 @@ interface TreeNode extends IDisposable {
extensionItem
:
vscode
.
TreeItem
;
parent
:
TreeNode
|
Root
;
children
?:
TreeNode
[];
disposableStore
:
DisposableStore
;
}
class
ExtHostTreeView
<
T
>
extends
Disposable
{
...
...
@@ -379,8 +381,9 @@ class ExtHostTreeView<T> extends Disposable {
const
node
=
this
.
nodes
.
get
(
element
);
if
(
node
)
{
const
resolve
=
await
this
.
dataProvider
.
resolveTreeItem
(
node
.
extensionItem
,
element
,
token
)
??
node
.
extensionItem
;
// Resolvable elements. Currently only tooltip.
// Resolvable elements. Currently only tooltip
and command
.
node
.
item
.
tooltip
=
this
.
getTooltip
(
resolve
.
tooltip
);
node
.
item
.
command
=
this
.
getCommand
(
node
.
disposableStore
,
resolve
.
command
);
return
node
.
item
;
}
}
...
...
@@ -573,8 +576,12 @@ class ExtHostTreeView<T> extends Disposable {
return
tooltip
;
}
private
getCommand
(
disposable
:
DisposableStore
,
command
?:
vscode
.
Command
):
Command
|
undefined
{
return
command
?
this
.
commands
.
toInternal
(
command
,
disposable
)
:
undefined
;
}
private
createTreeNode
(
element
:
T
,
extensionTreeItem
:
vscode
.
TreeItem
,
parent
:
TreeNode
|
Root
):
TreeNode
{
const
disposable
=
new
DisposableStore
();
const
disposable
Store
=
new
DisposableStore
();
const
handle
=
this
.
createHandle
(
element
,
extensionTreeItem
,
parent
);
const
icon
=
this
.
getLightIconPath
(
extensionTreeItem
);
const
item
:
ITreeItem
=
{
...
...
@@ -584,7 +591,7 @@ class ExtHostTreeView<T> extends Disposable {
description
:
extensionTreeItem
.
description
,
resourceUri
:
extensionTreeItem
.
resourceUri
,
tooltip
:
this
.
getTooltip
(
extensionTreeItem
.
tooltip
),
command
:
extensionTreeItem
.
command
?
this
.
commands
.
toInternal
(
extensionTreeItem
.
command
,
disposable
)
:
undefined
,
command
:
this
.
getCommand
(
disposableStore
,
extensionTreeItem
.
command
)
,
contextValue
:
extensionTreeItem
.
contextValue
,
icon
,
iconDark
:
this
.
getDarkIconPath
(
extensionTreeItem
)
||
icon
,
...
...
@@ -598,7 +605,8 @@ class ExtHostTreeView<T> extends Disposable {
extensionItem
:
extensionTreeItem
,
parent
,
children
:
undefined
,
dispose
():
void
{
disposable
.
dispose
();
}
disposableStore
,
dispose
():
void
{
disposableStore
.
dispose
();
}
};
}
...
...
src/vs/workbench/browser/parts/views/treeView.ts
浏览文件 @
5dbfe32b
...
...
@@ -52,7 +52,8 @@ import { IIconLabelMarkdownString } from 'vs/base/browser/ui/iconLabel/iconLabel
import
{
renderMarkdownAsPlaintext
}
from
'
vs/base/browser/markdownRenderer
'
;
import
{
API_OPEN_DIFF_EDITOR_COMMAND_ID
,
API_OPEN_EDITOR_COMMAND_ID
}
from
'
vs/workbench/browser/parts/editor/editorCommands
'
;
import
{
Codicon
}
from
'
vs/base/common/codicons
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
Command
}
from
'
vs/editor/common/modes
'
;
export
class
TreeViewPane
extends
ViewPane
{
...
...
@@ -535,12 +536,13 @@ export class TreeView extends Disposable implements ITreeView {
}));
this
.
tree
.
setInput
(
this
.
root
).
then
(()
=>
this
.
updateContentAreas
());
this
.
_register
(
this
.
tree
.
onDidOpen
(
e
=>
{
this
.
_register
(
this
.
tree
.
onDidOpen
(
async
(
e
)
=>
{
if
(
!
e
.
browserEvent
)
{
return
;
}
const
selection
=
this
.
tree
!
.
getSelection
();
const
command
=
selection
.
length
===
1
?
selection
[
0
].
command
:
undefined
;
const
command
=
await
this
.
resolveCommand
(
selection
.
length
===
1
?
selection
[
0
]
:
undefined
);
if
(
command
)
{
let
args
=
command
.
arguments
||
[];
if
(
command
.
id
===
API_OPEN_EDITOR_COMMAND_ID
||
command
.
id
===
API_OPEN_DIFF_EDITOR_COMMAND_ID
)
{
...
...
@@ -555,6 +557,17 @@ export class TreeView extends Disposable implements ITreeView {
}
private
async
resolveCommand
(
element
:
ITreeItem
|
undefined
):
Promise
<
Command
|
undefined
>
{
let
command
=
element
?.
command
;
if
(
element
&&
!
command
)
{
if
((
element
instanceof
ResolvableTreeItem
)
&&
element
.
hasResolve
)
{
await
element
.
resolve
(
new
CancellationTokenSource
().
token
);
command
=
element
.
command
;
}
}
return
command
;
}
private
onContextMenu
(
treeMenus
:
TreeMenus
,
treeEvent
:
ITreeContextMenuEvent
<
ITreeItem
>
,
actionRunner
:
MultipleSelectionActionRunner
):
void
{
this
.
hoverService
.
hideHover
();
const
node
:
ITreeItem
|
null
=
treeEvent
.
element
;
...
...
src/vs/workbench/common/views.ts
浏览文件 @
5dbfe32b
...
...
@@ -704,8 +704,9 @@ export class ResolvableTreeItem implements ITreeItem {
if
(
resolve
&&
!
this
.
resolved
)
{
const
resolvedItem
=
await
resolve
(
token
);
if
(
resolvedItem
)
{
// Resolvable elements. Currently only tooltip.
this
.
tooltip
=
resolvedItem
.
tooltip
;
// Resolvable elements. Currently tooltip and command.
this
.
tooltip
=
this
.
tooltip
??
resolvedItem
.
tooltip
;
this
.
command
=
this
.
command
??
resolvedItem
.
command
;
}
}
if
(
!
token
.
isCancellationRequested
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录