Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
54a46c85
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,发现更多精彩内容 >>
提交
54a46c85
编写于
10月 04, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make the registry be just a forwarder
上级
65d45fd9
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
79 addition
and
150 deletion
+79
-150
src/vs/platform/actions/common/actions.ts
src/vs/platform/actions/common/actions.ts
+1
-1
src/vs/workbench/common/actions.ts
src/vs/workbench/common/actions.ts
+72
-134
src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts
...kbench/parts/preferences/common/keybindingsEditorModel.ts
+6
-15
未找到文件。
src/vs/platform/actions/common/actions.ts
浏览文件 @
54a46c85
...
...
@@ -87,7 +87,7 @@ export interface IMenuRegistry {
getMenuItems
(
loc
:
MenuId
):
IMenuItem
[];
}
export
const
MenuRegistry
:
IMenuRegistry
=
new
class
{
export
const
MenuRegistry
:
IMenuRegistry
=
new
class
implements
IMenuRegistry
{
private
_commands
:
{
[
id
:
string
]:
ICommandAction
}
=
Object
.
create
(
null
);
...
...
src/vs/workbench/common/actions.ts
浏览文件 @
54a46c85
...
...
@@ -15,6 +15,7 @@ import { IMessageService } from 'vs/platform/message/common/message';
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
IDisposable
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
export
const
Extensions
=
{
WorkbenchActions
:
'
workbench.contributions.actions
'
...
...
@@ -30,92 +31,22 @@ export interface IWorkbenchActionRegistry {
* Registers a workbench action to the platform. Workbench actions are not
* visible by default and can only be invoked through a keybinding if provided.
*/
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
;
/**
* Unregisters a workbench action from the platform.
*/
unregisterWorkbenchAction
(
id
:
string
):
boolean
;
/**
* Returns the workbench action descriptor for the given id or null if none.
*/
getWorkbenchAction
(
id
:
string
):
SyncActionDescriptor
;
/**
* Returns an array of registered workbench actions known to the platform.
*/
getWorkbenchActions
():
SyncActionDescriptor
[];
/**
* Returns the alias associated with the given action or null if none.
*/
getAlias
(
actionId
:
string
):
string
;
/**
* Returns the category for the given action or null if none.
*/
getCategory
(
actionId
:
string
):
string
;
}
interface
IActionMeta
{
alias
:
string
;
category
?:
string
;
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
IDisposable
;
}
class
WorkbenchActionRegistry
implements
IWorkbenchActionRegistry
{
public
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
{
registerWorkbenchCommandFromAction
(
descriptor
,
alias
,
category
);
}
Registry
.
add
(
Extensions
.
WorkbenchActions
,
new
class
implements
IWorkbenchActionRegistry
{
public
unregisterWorkbenchAction
(
id
:
string
):
boolean
{
return
t
rue
;
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
IDisposable
{
return
t
his
.
_registerWorkbenchCommandFromAction
(
descriptor
,
alias
,
category
)
;
}
public
getWorkbenchAction
(
id
:
string
):
SyncActionDescriptor
{
return
null
;
}
private
_registerWorkbenchCommandFromAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
IDisposable
{
let
registrations
:
IDisposable
[]
=
[];
public
getCategory
(
id
:
string
):
string
{
const
commandAction
=
MenuRegistry
.
getCommand
(
id
);
if
(
!
commandAction
||
!
commandAction
.
category
)
{
return
null
;
}
const
{
category
}
=
commandAction
;
if
(
typeof
category
===
'
string
'
)
{
return
category
;
}
else
{
return
category
.
value
;
}
}
// command
registrations
.
push
(
CommandsRegistry
.
registerCommand
(
descriptor
.
id
,
this
.
_createCommandHandler
(
descriptor
)));
public
getAlias
(
id
:
string
):
string
{
const
commandAction
=
MenuRegistry
.
getCommand
(
id
);
if
(
!
commandAction
)
{
return
null
;
}
const
{
title
}
=
commandAction
;
if
(
typeof
title
===
'
string
'
)
{
return
null
;
}
else
{
return
title
.
original
;
}
}
public
getWorkbenchActions
():
SyncActionDescriptor
[]
{
return
[];
}
}
Registry
.
add
(
Extensions
.
WorkbenchActions
,
new
WorkbenchActionRegistry
());
function
registerWorkbenchCommandFromAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
{
CommandsRegistry
.
registerCommand
(
descriptor
.
id
,
createCommandHandler
(
descriptor
));
{
// register keybinding
// keybinding
const
when
=
descriptor
.
keybindingContext
;
const
weight
=
(
typeof
descriptor
.
keybindingWeight
===
'
undefined
'
?
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
()
:
descriptor
.
keybindingWeight
);
const
keybindings
=
descriptor
.
keybindings
;
...
...
@@ -129,38 +60,43 @@ function registerWorkbenchCommandFromAction(descriptor: SyncActionDescriptor, al
mac
:
keybindings
&&
keybindings
.
mac
,
linux
:
keybindings
&&
keybindings
.
linux
});
}
{
// register menu item
if
(
descriptor
.
label
)
{
// slightly weird if-check required because of
// menu item
// TODO@Ben slightly weird if-check required because of
// https://github.com/Microsoft/vscode/blob/d28ace31aa147596e35adf101a27768a048c79ec/src/vs/workbench/parts/files/browser/fileActions.contribution.ts#L194
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
{
command
:
{
if
(
descriptor
.
label
)
{
const
command
=
{
id
:
descriptor
.
id
,
title
:
{
value
:
descriptor
.
label
,
original
:
alias
},
category
};
MenuRegistry
.
addCommand
(
command
);
registrations
.
push
(
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
{
command
}));
}
});
}
// TODO@alex,joh
// support removal of keybinding rule
// support removal of command-ui
return
combinedDisposable
(
registrations
);
}
}
function
createCommandHandler
(
descriptor
:
SyncActionDescriptor
):
ICommandHandler
{
private
_
createCommandHandler
(
descriptor
:
SyncActionDescriptor
):
ICommandHandler
{
return
(
accessor
,
args
)
=>
{
const
messageService
=
accessor
.
get
(
IMessageService
);
const
instantiationService
=
accessor
.
get
(
IInstantiationService
);
const
telemetryService
=
accessor
.
get
(
ITelemetryService
);
const
partService
=
accessor
.
get
(
IPartService
);
TPromise
.
as
(
triggerAndDisposeAction
(
instantiationService
,
telemetryService
,
partService
,
descriptor
,
args
)).
done
(
null
,
(
err
)
=>
{
TPromise
.
as
(
this
.
_
triggerAndDisposeAction
(
instantiationService
,
telemetryService
,
partService
,
descriptor
,
args
)).
done
(
null
,
(
err
)
=>
{
messageService
.
show
(
Severity
.
Error
,
err
);
});
};
}
}
function
triggerAndDisposeAction
(
instantitationService
:
IInstantiationService
,
telemetryService
:
ITelemetryService
,
partService
:
IPartService
,
descriptor
:
SyncActionDescriptor
,
args
:
any
):
TPromise
<
any
>
{
private
_
triggerAndDisposeAction
(
instantitationService
:
IInstantiationService
,
telemetryService
:
ITelemetryService
,
partService
:
IPartService
,
descriptor
:
SyncActionDescriptor
,
args
:
any
):
TPromise
<
any
>
{
const
actionInstance
=
instantitationService
.
createInstance
(
descriptor
.
syncDescriptor
);
actionInstance
.
label
=
descriptor
.
label
||
actionInstance
.
label
;
...
...
@@ -196,4 +132,6 @@ function triggerAndDisposeAction(instantitationService: IInstantiationService, t
return
TPromise
.
wrapError
(
err
);
}
});
}
}
});
src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts
浏览文件 @
54a46c85
...
...
@@ -13,7 +13,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import
{
ResolvedKeybinding
,
ResolvedKeybindingPart
}
from
'
vs/base/common/keyCodes
'
;
import
{
AriaLabelProvider
,
UserSettingsLabelProvider
,
UILabelProvider
,
ModifierLabels
as
ModLabels
}
from
'
vs/base/common/keybindingLabels
'
;
import
{
CommonEditorRegistry
,
EditorAction
}
from
'
vs/editor/common/editorCommonExtensions
'
;
import
{
MenuRegistry
,
ILocalizedString
,
SyncActionDescriptor
,
ICommandAction
}
from
'
vs/platform/actions/common/actions
'
;
import
{
MenuRegistry
,
ILocalizedString
,
ICommandAction
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actions
'
;
import
{
EditorModel
}
from
'
vs/workbench/common/editor
'
;
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
...
...
@@ -200,26 +200,21 @@ export class KeybindingsEditorModel extends EditorModel {
}
private
static
toKeybindingEntry
(
command
:
string
,
keybindingItem
:
ResolvedKeybindingItem
,
workbenchActionsRegistry
:
IWorkbenchActionRegistry
,
editorActions
:
{}):
IKeybindingItem
{
const
workbenchAction
=
workbenchActionsRegistry
.
getWorkbenchAction
(
command
);
const
menuCommand
=
MenuRegistry
.
getCommand
(
command
);
const
editorAction
:
EditorAction
=
editorActions
[
command
];
return
<
IKeybindingItem
>
{
keybinding
:
keybindingItem
.
resolvedKeybinding
,
keybindingItem
,
command
,
commandLabel
:
KeybindingsEditorModel
.
getCommandLabel
(
workbenchAction
,
menuCommand
,
editorAction
),
commandDefaultLabel
:
KeybindingsEditorModel
.
getCommandDefaultLabel
(
workbenchAction
,
menuCommand
,
workbenchActionsRegistry
),
commandLabel
:
KeybindingsEditorModel
.
getCommandLabel
(
menuCommand
,
editorAction
),
commandDefaultLabel
:
KeybindingsEditorModel
.
getCommandDefaultLabel
(
menuCommand
,
workbenchActionsRegistry
),
when
:
keybindingItem
.
when
?
keybindingItem
.
when
.
serialize
()
:
''
,
source
:
keybindingItem
.
isDefault
?
localize
(
'
default
'
,
"
Default
"
)
:
localize
(
'
user
'
,
"
User
"
)
};
}
private
static
getCommandDefaultLabel
(
workbenchAction
:
SyncActionDescriptor
,
menuCommand
:
ICommandAction
,
workbenchActionsRegistry
:
IWorkbenchActionRegistry
):
string
{
private
static
getCommandDefaultLabel
(
menuCommand
:
ICommandAction
,
workbenchActionsRegistry
:
IWorkbenchActionRegistry
):
string
{
if
(
language
!==
LANGUAGE_DEFAULT
)
{
if
(
workbenchAction
)
{
return
workbenchActionsRegistry
.
getAlias
(
workbenchAction
.
id
);
}
if
(
menuCommand
&&
menuCommand
.
title
&&
(
<
ILocalizedString
>
menuCommand
.
title
).
original
)
{
return
(
<
ILocalizedString
>
menuCommand
.
title
).
original
;
}
...
...
@@ -227,11 +222,7 @@ export class KeybindingsEditorModel extends EditorModel {
return
null
;
}
private
static
getCommandLabel
(
workbenchAction
:
SyncActionDescriptor
,
menuCommand
:
ICommandAction
,
editorAction
:
EditorAction
):
string
{
if
(
workbenchAction
)
{
return
workbenchAction
.
label
;
}
private
static
getCommandLabel
(
menuCommand
:
ICommandAction
,
editorAction
:
EditorAction
):
string
{
if
(
menuCommand
)
{
return
typeof
menuCommand
.
title
===
'
string
'
?
menuCommand
.
title
:
menuCommand
.
title
.
value
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录