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 {
...
@@ -87,7 +87,7 @@ export interface IMenuRegistry {
getMenuItems
(
loc
:
MenuId
):
IMenuItem
[];
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
);
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';
...
@@ -15,6 +15,7 @@ import { IMessageService } from 'vs/platform/message/common/message';
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
IDisposable
,
combinedDisposable
}
from
'
vs/base/common/lifecycle
'
;
export
const
Extensions
=
{
export
const
Extensions
=
{
WorkbenchActions
:
'
workbench.contributions.actions
'
WorkbenchActions
:
'
workbench.contributions.actions
'
...
@@ -30,92 +31,22 @@ export interface IWorkbenchActionRegistry {
...
@@ -30,92 +31,22 @@ export interface IWorkbenchActionRegistry {
* Registers a workbench action to the platform. Workbench actions are not
* Registers a workbench action to the platform. Workbench actions are not
* visible by default and can only be invoked through a keybinding if provided.
* visible by default and can only be invoked through a keybinding if provided.
*/
*/
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
;
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
IDisposable
;
/**
* 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
{
Registry
.
add
(
Extensions
.
WorkbenchActions
,
new
class
implements
IWorkbenchActionRegistry
{
alias
:
string
;
category
?:
string
;
}
class
WorkbenchActionRegistry
implements
IWorkbenchActionRegistry
{
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
IDisposable
{
return
this
.
_registerWorkbenchCommandFromAction
(
descriptor
,
alias
,
category
);
public
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
{
registerWorkbenchCommandFromAction
(
descriptor
,
alias
,
category
);
}
public
unregisterWorkbenchAction
(
id
:
string
):
boolean
{
return
true
;
}
public
getWorkbenchAction
(
id
:
string
):
SyncActionDescriptor
{
return
null
;
}
}
public
getCategory
(
id
:
string
):
string
{
private
_registerWorkbenchCommandFromAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
IDisposable
{
const
commandAction
=
MenuRegistry
.
getCommand
(
id
);
let
registrations
:
IDisposable
[]
=
[];
if
(
!
commandAction
||
!
commandAction
.
category
)
{
return
null
;
}
const
{
category
}
=
commandAction
;
if
(
typeof
category
===
'
string
'
)
{
return
category
;
}
else
{
return
category
.
value
;
}
}
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
());
// command
registrations
.
push
(
CommandsRegistry
.
registerCommand
(
descriptor
.
id
,
this
.
_createCommandHandler
(
descriptor
)));
function
registerWorkbenchCommandFromAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
{
// keybinding
CommandsRegistry
.
registerCommand
(
descriptor
.
id
,
createCommandHandler
(
descriptor
));
{
// register keybinding
const
when
=
descriptor
.
keybindingContext
;
const
when
=
descriptor
.
keybindingContext
;
const
weight
=
(
typeof
descriptor
.
keybindingWeight
===
'
undefined
'
?
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
()
:
descriptor
.
keybindingWeight
);
const
weight
=
(
typeof
descriptor
.
keybindingWeight
===
'
undefined
'
?
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
()
:
descriptor
.
keybindingWeight
);
const
keybindings
=
descriptor
.
keybindings
;
const
keybindings
=
descriptor
.
keybindings
;
...
@@ -129,71 +60,78 @@ function registerWorkbenchCommandFromAction(descriptor: SyncActionDescriptor, al
...
@@ -129,71 +60,78 @@ function registerWorkbenchCommandFromAction(descriptor: SyncActionDescriptor, al
mac
:
keybindings
&&
keybindings
.
mac
,
mac
:
keybindings
&&
keybindings
.
mac
,
linux
:
keybindings
&&
keybindings
.
linux
linux
:
keybindings
&&
keybindings
.
linux
});
});
}
{
// menu item
// register 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
if
(
descriptor
.
label
)
{
if
(
descriptor
.
label
)
{
// slightly weird if-check required because of
// https://github.com/Microsoft/vscode/blob/d28ace31aa147596e35adf101a27768a048c79ec/src/vs/workbench/parts/files/browser/fileActions.contribution.ts#L194
const
command
=
{
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
{
id
:
descriptor
.
id
,
command
:
{
title
:
{
value
:
descriptor
.
label
,
original
:
alias
},
id
:
descriptor
.
id
,
category
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
)
=>
{
return
(
accessor
,
args
)
=>
{
const
messageService
=
accessor
.
get
(
IMessageService
);
const
messageService
=
accessor
.
get
(
IMessageService
);
const
instantiationService
=
accessor
.
get
(
IInstantiationService
);
const
instantiationService
=
accessor
.
get
(
IInstantiationService
);
const
telemetryService
=
accessor
.
get
(
ITelemetryService
);
const
telemetryService
=
accessor
.
get
(
ITelemetryService
);
const
partService
=
accessor
.
get
(
IPartService
);
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
);
messageService
.
show
(
Severity
.
Error
,
err
);
});
});
};
};
}
}
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
;
function
triggerAndDisposeAction
(
instantitationService
:
IInstantiationService
,
telemetryService
:
ITelemetryService
,
partService
:
IPartService
,
descriptor
:
SyncActionDescriptor
,
args
:
any
):
TPromise
<
any
>
{
// don't run the action when not enabled
const
actionInstance
=
instantitationService
.
createInstance
(
descriptor
.
syncDescriptor
);
if
(
!
actionInstance
.
enabled
)
{
actionInstance
.
label
=
descriptor
.
label
||
actionInstance
.
label
;
actionInstance
.
dispose
()
;
// don't run the action when not enabled
return
void
0
;
if
(
!
actionInstance
.
enabled
)
{
}
actionInstance
.
dispose
();
return
void
0
;
const
from
=
args
&&
args
.
from
||
'
keybinding
'
;
}
if
(
telemetryService
)
{
/* __GDPR__
"workbenchActionExecuted" : {
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
telemetryService
.
publicLog
(
'
workbenchActionExecuted
'
,
{
id
:
actionInstance
.
id
,
from
});
}
const
from
=
args
&&
args
.
from
||
'
keybinding
'
;
// run action when workbench is created
if
(
telemetryService
)
{
return
partService
.
joinCreation
().
then
(()
=>
{
/* __GDPR__
try
{
"workbenchActionExecuted" : {
return
TPromise
.
as
(
actionInstance
.
run
(
undefined
,
{
from
})).
then
(()
=>
{
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
actionInstance
.
dispose
();
"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
},
(
err
)
=>
{
actionInstance
.
dispose
();
return
TPromise
.
wrapError
(
err
);
});
}
catch
(
err
)
{
actionInstance
.
dispose
();
return
TPromise
.
wrapError
(
err
);
}
}
*/
});
telemetryService
.
publicLog
(
'
workbenchActionExecuted
'
,
{
id
:
actionInstance
.
id
,
from
});
}
}
});
// run action when workbench is created
return
partService
.
joinCreation
().
then
(()
=>
{
try
{
return
TPromise
.
as
(
actionInstance
.
run
(
undefined
,
{
from
})).
then
(()
=>
{
actionInstance
.
dispose
();
},
(
err
)
=>
{
actionInstance
.
dispose
();
return
TPromise
.
wrapError
(
err
);
});
}
catch
(
err
)
{
actionInstance
.
dispose
();
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';
...
@@ -13,7 +13,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
import
{
ResolvedKeybinding
,
ResolvedKeybindingPart
}
from
'
vs/base/common/keyCodes
'
;
import
{
ResolvedKeybinding
,
ResolvedKeybindingPart
}
from
'
vs/base/common/keyCodes
'
;
import
{
AriaLabelProvider
,
UserSettingsLabelProvider
,
UILabelProvider
,
ModifierLabels
as
ModLabels
}
from
'
vs/base/common/keybindingLabels
'
;
import
{
AriaLabelProvider
,
UserSettingsLabelProvider
,
UILabelProvider
,
ModifierLabels
as
ModLabels
}
from
'
vs/base/common/keybindingLabels
'
;
import
{
CommonEditorRegistry
,
EditorAction
}
from
'
vs/editor/common/editorCommonExtensions
'
;
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
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actions
'
;
import
{
EditorModel
}
from
'
vs/workbench/common/editor
'
;
import
{
EditorModel
}
from
'
vs/workbench/common/editor
'
;
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
import
{
IExtensionService
}
from
'
vs/platform/extensions/common/extensions
'
;
...
@@ -200,26 +200,21 @@ export class KeybindingsEditorModel extends EditorModel {
...
@@ -200,26 +200,21 @@ export class KeybindingsEditorModel extends EditorModel {
}
}
private
static
toKeybindingEntry
(
command
:
string
,
keybindingItem
:
ResolvedKeybindingItem
,
workbenchActionsRegistry
:
IWorkbenchActionRegistry
,
editorActions
:
{}):
IKeybindingItem
{
private
static
toKeybindingEntry
(
command
:
string
,
keybindingItem
:
ResolvedKeybindingItem
,
workbenchActionsRegistry
:
IWorkbenchActionRegistry
,
editorActions
:
{}):
IKeybindingItem
{
const
workbenchAction
=
workbenchActionsRegistry
.
getWorkbenchAction
(
command
);
const
menuCommand
=
MenuRegistry
.
getCommand
(
command
);
const
menuCommand
=
MenuRegistry
.
getCommand
(
command
);
const
editorAction
:
EditorAction
=
editorActions
[
command
];
const
editorAction
:
EditorAction
=
editorActions
[
command
];
return
<
IKeybindingItem
>
{
return
<
IKeybindingItem
>
{
keybinding
:
keybindingItem
.
resolvedKeybinding
,
keybinding
:
keybindingItem
.
resolvedKeybinding
,
keybindingItem
,
keybindingItem
,
command
,
command
,
commandLabel
:
KeybindingsEditorModel
.
getCommandLabel
(
workbenchAction
,
menuCommand
,
editorAction
),
commandLabel
:
KeybindingsEditorModel
.
getCommandLabel
(
menuCommand
,
editorAction
),
commandDefaultLabel
:
KeybindingsEditorModel
.
getCommandDefaultLabel
(
workbenchAction
,
menuCommand
,
workbenchActionsRegistry
),
commandDefaultLabel
:
KeybindingsEditorModel
.
getCommandDefaultLabel
(
menuCommand
,
workbenchActionsRegistry
),
when
:
keybindingItem
.
when
?
keybindingItem
.
when
.
serialize
()
:
''
,
when
:
keybindingItem
.
when
?
keybindingItem
.
when
.
serialize
()
:
''
,
source
:
keybindingItem
.
isDefault
?
localize
(
'
default
'
,
"
Default
"
)
:
localize
(
'
user
'
,
"
User
"
)
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
(
language
!==
LANGUAGE_DEFAULT
)
{
if
(
workbenchAction
)
{
return
workbenchActionsRegistry
.
getAlias
(
workbenchAction
.
id
);
}
if
(
menuCommand
&&
menuCommand
.
title
&&
(
<
ILocalizedString
>
menuCommand
.
title
).
original
)
{
if
(
menuCommand
&&
menuCommand
.
title
&&
(
<
ILocalizedString
>
menuCommand
.
title
).
original
)
{
return
(
<
ILocalizedString
>
menuCommand
.
title
).
original
;
return
(
<
ILocalizedString
>
menuCommand
.
title
).
original
;
}
}
...
@@ -227,11 +222,7 @@ export class KeybindingsEditorModel extends EditorModel {
...
@@ -227,11 +222,7 @@ export class KeybindingsEditorModel extends EditorModel {
return
null
;
return
null
;
}
}
private
static
getCommandLabel
(
workbenchAction
:
SyncActionDescriptor
,
menuCommand
:
ICommandAction
,
editorAction
:
EditorAction
):
string
{
private
static
getCommandLabel
(
menuCommand
:
ICommandAction
,
editorAction
:
EditorAction
):
string
{
if
(
workbenchAction
)
{
return
workbenchAction
.
label
;
}
if
(
menuCommand
)
{
if
(
menuCommand
)
{
return
typeof
menuCommand
.
title
===
'
string
'
?
menuCommand
.
title
:
menuCommand
.
title
.
value
;
return
typeof
menuCommand
.
title
===
'
string
'
?
menuCommand
.
title
:
menuCommand
.
title
.
value
;
}
}
...
@@ -560,4 +551,4 @@ class KeybindingItemMatches {
...
@@ -560,4 +551,4 @@ class KeybindingItemMatches {
}
}
return
false
;
return
false
;
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录