Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
b643600e
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,发现更多精彩内容 >>
提交
b643600e
编写于
3月 07, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quick access - operate on picker from providers
上级
9a3c1d43
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
98 addition
and
28 deletion
+98
-28
src/vs/base/parts/quickinput/browser/quickInput.ts
src/vs/base/parts/quickinput/browser/quickInput.ts
+4
-3
src/vs/base/parts/quickinput/common/quickInput.ts
src/vs/base/parts/quickinput/common/quickInput.ts
+6
-0
src/vs/platform/quickinput/browser/quickAccess.ts
src/vs/platform/quickinput/browser/quickAccess.ts
+38
-10
src/vs/platform/quickinput/browser/quickAccessHelp.ts
src/vs/platform/quickinput/browser/quickAccessHelp.ts
+18
-3
src/vs/platform/quickinput/common/quickAccess.ts
src/vs/platform/quickinput/common/quickAccess.ts
+26
-8
src/vs/workbench/browser/parts/quickopen/quickopen.ts
src/vs/workbench/browser/parts/quickopen/quickopen.ts
+6
-4
未找到文件。
src/vs/base/parts/quickinput/browser/quickInput.ts
浏览文件 @
b643600e
...
...
@@ -402,7 +402,6 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
quickNavigate
:
IQuickNavigateConfiguration
|
undefined
;
get
value
()
{
return
this
.
_value
;
}
...
...
@@ -412,6 +411,8 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this
.
update
();
}
filterValue
=
(
value
:
string
)
=>
value
;
get
placeholder
()
{
return
this
.
_placeholder
;
}
...
...
@@ -597,7 +598,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
return
;
}
this
.
_value
=
value
;
this
.
ui
.
list
.
filter
(
this
.
ui
.
inputBox
.
value
);
this
.
ui
.
list
.
filter
(
this
.
filterValue
(
this
.
ui
.
inputBox
.
value
)
);
this
.
trySelectFirst
();
this
.
onDidChangeValueEmitter
.
fire
(
value
);
}));
...
...
@@ -771,7 +772,7 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
if
(
this
.
itemsUpdated
)
{
this
.
itemsUpdated
=
false
;
this
.
ui
.
list
.
setElements
(
this
.
items
);
this
.
ui
.
list
.
filter
(
this
.
ui
.
inputBox
.
value
);
this
.
ui
.
list
.
filter
(
this
.
filterValue
(
this
.
ui
.
inputBox
.
value
)
);
this
.
ui
.
checkAll
.
checked
=
this
.
ui
.
list
.
getAllVisibleChecked
();
this
.
ui
.
visibleCount
.
setCount
(
this
.
ui
.
list
.
getVisibleCount
());
this
.
ui
.
count
.
setCount
(
this
.
ui
.
list
.
getCheckedCount
());
...
...
src/vs/base/parts/quickinput/common/quickInput.ts
浏览文件 @
b643600e
...
...
@@ -156,6 +156,12 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
value
:
string
;
/**
* A method that allows to massage the value used
* for filtering, e.g, to remove certain parts.
*/
filterValue
:
(
value
:
string
)
=>
string
;
placeholder
:
string
|
undefined
;
readonly
onDidChangeValue
:
Event
<
string
>
;
...
...
src/vs/platform/quickinput/browser/quickAccess.ts
浏览文件 @
b643600e
...
...
@@ -5,15 +5,17 @@
import
'
vs/platform/quickinput/browser/quickAccessHelp
'
;
import
{
IQuickInputService
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
,
DisposableStore
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IQuickAccessController
,
IQuickAccessProvider
,
IQuickAccessRegistry
,
Extensions
,
IQuickAccessProviderDescriptor
}
from
'
vs/platform/quickinput/common/quickAccess
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
CancellationToken
Source
}
from
'
vs/base/common/cancellation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
once
}
from
'
vs/base/common/functional
'
;
export
class
QuickAccessController
extends
Disposable
implements
IQuickAccessController
{
private
readonly
registry
=
Registry
.
as
<
IQuickAccessRegistry
>
(
Extensions
.
Quickaccess
);
private
readonly
mapProviderToDescriptor
=
new
Map
<
IQuickAccessProviderDescriptor
,
IQuickAccessProvider
>
();
constructor
(
@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
,
...
...
@@ -22,16 +24,42 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
super
();
}
async
show
(
prefix
=
''
):
Promise
<
void
>
{
const
provider
=
this
.
getOrInstantiateProvider
(
prefix
);
show
(
value
=
''
):
void
{
provider
.
provide
(
this
.
quickInputService
,
CancellationToken
.
None
);
}
// Find provider for the value to show
const
[
provider
,
prefix
]
=
this
.
getOrInstantiateProvider
(
value
);
// Create a picker for the provider to use with the initial value
// and adjust the filtering to exclude the prefix from filtering
const
picker
=
this
.
quickInputService
.
createQuickPick
();
picker
.
value
=
value
;
picker
.
valueSelection
=
[
value
.
length
,
value
.
length
];
picker
.
filterValue
=
(
value
:
string
)
=>
value
.
substring
(
prefix
.
length
);
// Cleanup when picker hides
const
disposables
=
new
DisposableStore
();
once
(
picker
.
onDidHide
)(()
=>
disposables
.
dispose
());
private
mapProviderToDescriptor
=
new
Map
<
IQuickAccessProviderDescriptor
,
IQuickAccessProvider
>
();
// Whenever the value changes, check if the provider has
// changed and if so - re-create the picker from the beginning
disposables
.
add
(
picker
.
onDidChangeValue
(
value
=>
{
const
[
providerForValue
]
=
this
.
getOrInstantiateProvider
(
value
);
if
(
providerForValue
!==
provider
)
{
this
.
show
(
value
);
}
}));
// Create a cancellation token source that is valid
// as long as the picker has not been closed
const
cts
=
new
CancellationTokenSource
();
disposables
.
add
(
toDisposable
(()
=>
cts
.
dispose
(
true
)));
// Finally ask provider to fill the picker as needed
provider
.
provide
(
picker
,
cts
.
token
);
}
private
getOrInstantiateProvider
(
prefix
:
string
):
IQuickAccessProvider
{
const
providerDescriptor
=
this
.
registry
.
getQuickAccessProvider
(
prefix
)
||
this
.
registry
.
defaultProvider
;
private
getOrInstantiateProvider
(
value
:
string
):
[
IQuickAccessProvider
,
string
/* prefix */
]
{
const
providerDescriptor
=
this
.
registry
.
getQuickAccessProvider
(
value
)
||
this
.
registry
.
defaultProvider
;
let
provider
=
this
.
mapProviderToDescriptor
.
get
(
providerDescriptor
);
if
(
!
provider
)
{
...
...
@@ -39,6 +67,6 @@ export class QuickAccessController extends Disposable implements IQuickAccessCon
this
.
mapProviderToDescriptor
.
set
(
providerDescriptor
,
provider
);
}
return
provider
;
return
[
provider
,
providerDescriptor
.
prefix
]
;
}
}
src/vs/platform/quickinput/browser/quickAccessHelp.ts
浏览文件 @
b643600e
...
...
@@ -3,17 +3,21 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IQuickInputService
,
QuickPickInput
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
QuickPickInput
,
IQuickPick
,
IQuickPickItem
,
IQuickInputService
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IQuickAccessProvider
,
IQuickAccessRegistry
,
Extensions
}
from
'
vs/platform/quickinput/common/quickAccess
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
once
}
from
'
vs/base/common/functional
'
;
class
HelpQuickAccessProvider
implements
IQuickAccessProvider
{
private
readonly
registry
=
Registry
.
as
<
IQuickAccessRegistry
>
(
Extensions
.
Quickaccess
);
async
provide
(
service
:
IQuickInputService
,
token
:
CancellationToken
):
Promise
<
void
>
{
constructor
(@
IQuickInputService
private
readonly
quickInputService
:
IQuickInputService
)
{
}
async
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
Promise
<
void
>
{
const
picks
:
QuickPickInput
[]
=
[];
for
(
const
provider
of
this
.
registry
.
getQuickAccessProviders
())
{
...
...
@@ -25,7 +29,18 @@ class HelpQuickAccessProvider implements IQuickAccessProvider {
}
}
await
service
.
pick
(
picks
);
const
disposables
=
new
DisposableStore
();
once
(
token
.
onCancellationRequested
)(()
=>
disposables
.
dispose
());
disposables
.
add
(
picker
.
onDidAccept
(()
=>
{
const
items
=
picker
.
selectedItems
;
if
(
items
.
length
===
1
)
{
this
.
quickInputService
.
quickAccess
.
show
(
items
[
0
].
label
);
}
}));
picker
.
items
=
picks
;
picker
.
show
();
}
}
...
...
src/vs/platform/quickinput/common/quickAccess.ts
浏览文件 @
b643600e
...
...
@@ -3,9 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
IQuick
InputService
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IQuick
Pick
,
IQuickPickItem
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
IConstructorSignature0
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
first
}
from
'
vs/base/common/arrays
'
;
import
{
startsWith
}
from
'
vs/base/common/strings
'
;
...
...
@@ -14,9 +13,9 @@ import { assertIsDefined } from 'vs/base/common/types';
export
interface
IQuickAccessController
{
/**
* Open the quick access picker with the optional
prefix
.
* Open the quick access picker with the optional
value prefilled
.
*/
show
(
prefix
?:
string
):
Promise
<
void
>
;
show
(
value
?:
string
):
void
;
}
export
interface
IQuickAccessProvider
{
...
...
@@ -24,10 +23,12 @@ export interface IQuickAccessProvider {
/**
* Called whenever a prefix was typed into quick pick that matches the provider.
*
* @param service the service to use to drive the quick input widget
* @param token cancellation support
* @param picker the picker to use for showing provider results.
* @param token providers have to check the cancellation token everytime after
* a long running operation because it could be that the picker has been closed
* or changed meanwhile.
*/
provide
(
service
:
IQuickInputService
,
token
:
CancellationToken
):
Promise
<
void
>
;
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
Promise
<
void
>
;
}
export
interface
QuickAccessProviderHelp
{
...
...
@@ -50,9 +51,26 @@ export interface QuickAccessProviderHelp {
}
export
interface
IQuickAccessProviderDescriptor
{
readonly
ctor
:
IConstructorSignature0
<
IQuickAccessProvider
>
;
/**
* The actual provider that will be instantiated as needed.
*/
readonly
ctor
:
{
new
(...
services
:
any
/* TS BrandedService but no clue how to type this properly */
[]):
IQuickAccessProvider
};
/**
* The prefix for quick access picker to use the provider for.
*/
readonly
prefix
:
string
;
/**
* Documentation for the provider in the quick access help.
*/
readonly
helpEntries
:
QuickAccessProviderHelp
[];
/**
* A context key that will be set automatically when the
* picker for the provider is showing.
*/
readonly
contextKey
?:
string
;
}
...
...
src/vs/workbench/browser/parts/quickopen/quickopen.ts
浏览文件 @
b643600e
...
...
@@ -6,7 +6,7 @@
import
*
as
nls
from
'
vs/nls
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
IQuickOpenService
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
import
{
IQuickInputService
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IQuickInputService
,
IQuickPick
,
IQuickPickItem
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
ContextKeyExpr
,
RawContextKey
,
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ICommandHandler
,
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
...
...
@@ -209,12 +209,14 @@ export class LegacyQuickInputQuickOpenController extends Disposable {
Registry
.
as
<
IWorkbenchContributionsRegistry
>
(
WorkbenchExtensions
.
Workbench
).
registerWorkbenchContribution
(
LegacyQuickInputQuickOpenController
,
LifecyclePhase
.
Ready
);
class
SampleQuickAccessProvider
implements
IQuickAccessProvider
{
async
provide
(
service
:
IQuickInputService
,
token
:
CancellationToken
):
Promise
<
void
>
{
service
.
pick
(
[
async
provide
(
picker
:
IQuickPick
<
IQuickPickItem
>
,
token
:
CancellationToken
):
Promise
<
void
>
{
picker
.
items
=
[
{
label
:
'
1
'
},
{
label
:
'
2
'
},
{
label
:
'
3
'
}
]);
];
picker
.
show
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录