Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
65d45fd9
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,发现更多精彩内容 >>
提交
65d45fd9
编写于
10月 03, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip - make IWorkbenchActionRegistry not hold any data but make it just a forwarder
上级
64e6e228
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
146 deletion
+72
-146
src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
+8
-26
src/vs/workbench/common/actions.ts
src/vs/workbench/common/actions.ts
+61
-58
src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
+2
-38
src/vs/workbench/test/browser/actionRegistry.test.ts
src/vs/workbench/test/browser/actionRegistry.test.ts
+1
-24
未找到文件。
src/vs/workbench/browser/parts/statusbar/statusbarPart.ts
浏览文件 @
65d45fd9
...
...
@@ -17,7 +17,6 @@ import { Registry } from 'vs/platform/registry/common/platform';
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
Part
}
from
'
vs/workbench/browser/part
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actions
'
;
import
{
StatusbarAlignment
,
IStatusbarRegistry
,
Extensions
,
IStatusbarItem
}
from
'
vs/workbench/browser/parts/statusbar/statusbar
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
...
...
@@ -287,29 +286,6 @@ class StatusBarEntryItem implements IStatusbarItem {
private
executeCommand
(
id
:
string
,
args
?:
any
[])
{
args
=
args
||
[];
// Lookup built in commands
const
builtInActionDescriptor
=
Registry
.
as
<
IWorkbenchActionRegistry
>
(
ActionExtensions
.
WorkbenchActions
).
getWorkbenchAction
(
id
);
if
(
builtInActionDescriptor
)
{
const
action
=
this
.
instantiationService
.
createInstance
(
builtInActionDescriptor
.
syncDescriptor
);
if
(
action
.
enabled
)
{
/* __GDPR__
"workbenchActionExecuted" : {
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this
.
telemetryService
.
publicLog
(
'
workbenchActionExecuted
'
,
{
id
:
action
.
id
,
from
:
'
status bar
'
});
(
action
.
run
()
||
TPromise
.
as
(
null
)).
done
(()
=>
{
action
.
dispose
();
},
(
err
)
=>
this
.
messageService
.
show
(
Severity
.
Error
,
toErrorMessage
(
err
)));
}
else
{
this
.
messageService
.
show
(
Severity
.
Warning
,
nls
.
localize
(
'
canNotRun
'
,
"
Command '{0}' is currently not enabled and can not be run.
"
,
action
.
label
||
id
));
}
return
;
}
// Maintain old behaviour of always focusing the editor here
const
activeEditor
=
this
.
editorService
.
getActiveEditor
();
const
codeEditor
=
getCodeEditor
(
activeEditor
);
...
...
@@ -317,7 +293,13 @@ class StatusBarEntryItem implements IStatusbarItem {
codeEditor
.
focus
();
}
// Fallback to the command service for any other case
/* __GDPR__
"workbenchActionExecuted" : {
"id" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
"from": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this
.
telemetryService
.
publicLog
(
'
workbenchActionExecuted
'
,
{
id
,
from
:
'
status bar
'
});
this
.
commandService
.
executeCommand
(
id
,
...
args
).
done
(
undefined
,
err
=>
this
.
messageService
.
show
(
Severity
.
Error
,
toErrorMessage
(
err
)));
}
}
...
...
@@ -355,4 +337,4 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
if
(
statusBarProminentItemHoverBackground
)
{
collector
.
addRule
(
`.monaco-workbench > .part.statusbar > .statusbar-item a.status-bar-info:hover:not([disabled]):not(.disabled) { background-color:
${
statusBarProminentItemHoverBackground
}
; }`
);
}
});
\ No newline at end of file
});
src/vs/workbench/common/actions.ts
浏览文件 @
65d45fd9
...
...
@@ -5,13 +5,12 @@
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
collections
=
require
(
'
vs/base/common/collections
'
);
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
IAction
}
from
'
vs/base/common/actions
'
;
import
{
KeybindingsRegistry
,
ICommandAndKeybindingRule
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
import
{
IPartService
}
from
'
vs/workbench/services/part/common/partService
'
;
import
{
ICommandHandler
}
from
'
vs/platform/commands/common/commands
'
;
import
{
SyncActionDescriptor
}
from
'
vs/platform/actions/common/actions
'
;
import
{
ICommandHandler
,
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
SyncActionDescriptor
,
MenuRegistry
,
MenuId
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
...
...
@@ -65,83 +64,87 @@ interface IActionMeta {
}
class
WorkbenchActionRegistry
implements
IWorkbenchActionRegistry
{
private
workbenchActions
:
collections
.
IStringDictionary
<
SyncActionDescriptor
>
;
private
mapActionIdToMeta
:
{
[
id
:
string
]:
IActionMeta
;
};
constructor
()
{
this
.
workbenchActions
=
Object
.
create
(
null
);
this
.
mapActionIdToMeta
=
Object
.
create
(
null
);
}
public
registerWorkbenchAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
{
if
(
!
this
.
workbenchActions
[
descriptor
.
id
])
{
this
.
workbenchActions
[
descriptor
.
id
]
=
descriptor
;
registerWorkbenchCommandFromAction
(
descriptor
);
const
meta
:
IActionMeta
=
{
alias
};
if
(
typeof
category
===
'
string
'
)
{
meta
.
category
=
category
;
}
this
.
mapActionIdToMeta
[
descriptor
.
id
]
=
meta
;
}
registerWorkbenchCommandFromAction
(
descriptor
,
alias
,
category
);
}
public
unregisterWorkbenchAction
(
id
:
string
):
boolean
{
if
(
!
this
.
workbenchActions
[
id
])
{
return
false
;
}
delete
this
.
workbenchActions
[
id
];
delete
this
.
mapActionIdToMeta
[
id
];
return
true
;
}
public
getWorkbenchAction
(
id
:
string
):
SyncActionDescriptor
{
return
this
.
workbenchActions
[
id
]
||
null
;
return
null
;
}
public
getCategory
(
id
:
string
):
string
{
return
(
this
.
mapActionIdToMeta
[
id
]
&&
this
.
mapActionIdToMeta
[
id
].
category
)
||
null
;
const
commandAction
=
MenuRegistry
.
getCommand
(
id
);
if
(
!
commandAction
||
!
commandAction
.
category
)
{
return
null
;
}
const
{
category
}
=
commandAction
;
if
(
typeof
category
===
'
string
'
)
{
return
category
;
}
else
{
return
category
.
value
;
}
}
public
getAlias
(
id
:
string
):
string
{
return
(
this
.
mapActionIdToMeta
[
id
]
&&
this
.
mapActionIdToMeta
[
id
].
alias
)
||
null
;
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
collections
.
values
(
this
.
workbenchActions
);
}
public
setWorkbenchActions
(
actions
:
SyncActionDescriptor
[]):
void
{
this
.
workbenchActions
=
Object
.
create
(
null
);
this
.
mapActionIdToMeta
=
Object
.
create
(
null
);
actions
.
forEach
(
action
=>
this
.
registerWorkbenchAction
(
action
,
''
),
this
);
return
[];
}
}
Registry
.
add
(
Extensions
.
WorkbenchActions
,
new
WorkbenchActionRegistry
());
function
registerWorkbenchCommandFromAction
(
descriptor
:
SyncActionDescriptor
):
void
{
const
when
=
descriptor
.
keybindingContext
;
const
weight
=
(
typeof
descriptor
.
keybindingWeight
===
'
undefined
'
?
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
()
:
descriptor
.
keybindingWeight
);
const
keybindings
=
descriptor
.
keybindings
;
const
desc
:
ICommandAndKeybindingRule
=
{
id
:
descriptor
.
id
,
handler
:
createCommandHandler
(
descriptor
),
weight
:
weight
,
when
:
when
,
primary
:
keybindings
&&
keybindings
.
primary
,
secondary
:
keybindings
&&
keybindings
.
secondary
,
win
:
keybindings
&&
keybindings
.
win
,
mac
:
keybindings
&&
keybindings
.
mac
,
linux
:
keybindings
&&
keybindings
.
linux
};
function
registerWorkbenchCommandFromAction
(
descriptor
:
SyncActionDescriptor
,
alias
:
string
,
category
?:
string
):
void
{
CommandsRegistry
.
registerCommand
(
descriptor
.
id
,
createCommandHandler
(
descriptor
));
{
// register keybinding
const
when
=
descriptor
.
keybindingContext
;
const
weight
=
(
typeof
descriptor
.
keybindingWeight
===
'
undefined
'
?
KeybindingsRegistry
.
WEIGHT
.
workbenchContrib
()
:
descriptor
.
keybindingWeight
);
const
keybindings
=
descriptor
.
keybindings
;
KeybindingsRegistry
.
registerKeybindingRule
({
id
:
descriptor
.
id
,
weight
:
weight
,
when
:
when
,
primary
:
keybindings
&&
keybindings
.
primary
,
secondary
:
keybindings
&&
keybindings
.
secondary
,
win
:
keybindings
&&
keybindings
.
win
,
mac
:
keybindings
&&
keybindings
.
mac
,
linux
:
keybindings
&&
keybindings
.
linux
});
}
KeybindingsRegistry
.
registerCommandAndKeybindingRule
(
desc
);
{
// register menu item
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
MenuRegistry
.
appendMenuItem
(
MenuId
.
CommandPalette
,
{
command
:
{
id
:
descriptor
.
id
,
title
:
{
value
:
descriptor
.
label
,
original
:
alias
},
category
}
});
}
}
}
function
createCommandHandler
(
descriptor
:
SyncActionDescriptor
):
ICommandHandler
{
...
...
@@ -193,4 +196,4 @@ function triggerAndDisposeAction(instantitationService: IInstantiationService, t
return
TPromise
.
wrapError
(
err
);
}
});
}
\ No newline at end of file
}
src/vs/workbench/parts/quickopen/browser/commandsHandler.ts
浏览文件 @
65d45fd9
...
...
@@ -16,8 +16,6 @@ import { Mode, IEntryRunContext, IAutoFocus, IModel, IQuickNavigateConfiguration
import
{
QuickOpenEntryGroup
,
IHighlight
,
QuickOpenModel
,
QuickOpenEntry
}
from
'
vs/base/parts/quickopen/browser/quickOpenModel
'
;
import
{
SyncActionDescriptor
,
IMenuService
,
MenuId
,
MenuItemAction
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IContextKeyService
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actions
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
QuickOpenHandler
,
IWorkbenchQuickOpenConfiguration
}
from
'
vs/workbench/browser/quickopen
'
;
import
{
IEditorAction
,
IEditor
,
ICommonCodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
matchesWords
,
matchesPrefix
,
matchesContiguousSubString
,
or
}
from
'
vs/base/common/filters
'
;
...
...
@@ -418,11 +416,6 @@ export class CommandsHandler extends QuickOpenHandler {
searchValue
=
searchValue
.
trim
();
this
.
lastSearchValue
=
searchValue
;
// Workbench Actions
let
workbenchEntries
:
CommandEntry
[]
=
[];
const
workbenchActions
=
Registry
.
as
<
IWorkbenchActionRegistry
>
(
ActionExtensions
.
WorkbenchActions
).
getWorkbenchActions
();
workbenchEntries
=
this
.
actionDescriptorsToEntries
(
workbenchActions
,
searchValue
);
// Editor Actions
const
activeEditor
=
this
.
editorService
.
getActiveEditor
();
const
activeEditorControl
=
activeEditor
?
activeEditor
.
getControl
()
:
null
;
...
...
@@ -443,7 +436,7 @@ export class CommandsHandler extends QuickOpenHandler {
const
commandEntries
=
this
.
menuItemActionsToEntries
(
menuActions
,
searchValue
);
// Concat
let
entries
=
[...
workbenchEntries
,
...
editorEntries
,
...
commandEntries
];
let
entries
=
[...
editorEntries
,
...
commandEntries
];
// Remove duplicates
entries
=
arrays
.
distinct
(
entries
,
entry
=>
`
${
entry
.
getLabel
()}${
entry
.
getGroupLabel
()}${
entry
.
getCommandId
()}
`
);
...
...
@@ -498,35 +491,6 @@ export class CommandsHandler extends QuickOpenHandler {
return
TPromise
.
as
(
new
QuickOpenModel
(
entries
));
}
private
actionDescriptorsToEntries
(
actionDescriptors
:
SyncActionDescriptor
[],
searchValue
:
string
):
CommandEntry
[]
{
const
entries
:
CommandEntry
[]
=
[];
const
registry
=
Registry
.
as
<
IWorkbenchActionRegistry
>
(
ActionExtensions
.
WorkbenchActions
);
for
(
let
i
=
0
;
i
<
actionDescriptors
.
length
;
i
++
)
{
const
actionDescriptor
=
actionDescriptors
[
i
];
if
(
actionDescriptor
.
label
)
{
// Label (with optional category)
let
label
=
actionDescriptor
.
label
;
const
category
=
registry
.
getCategory
(
actionDescriptor
.
id
);
if
(
category
)
{
label
=
nls
.
localize
(
'
commandLabel
'
,
"
{0}: {1}
"
,
category
,
label
);
}
// Alias for non default languages
const
alias
=
(
language
!==
LANGUAGE_DEFAULT
)
?
registry
.
getAlias
(
actionDescriptor
.
id
)
:
null
;
const
labelHighlights
=
wordFilter
(
searchValue
,
label
);
const
aliasHighlights
=
alias
?
wordFilter
(
searchValue
,
alias
)
:
null
;
if
(
labelHighlights
||
aliasHighlights
)
{
entries
.
push
(
this
.
instantiationService
.
createInstance
(
CommandEntry
,
actionDescriptor
.
id
,
this
.
keybindingService
.
lookupKeybinding
(
actionDescriptor
.
id
),
label
,
alias
,
{
label
:
labelHighlights
,
alias
:
aliasHighlights
},
actionDescriptor
,
(
id
:
string
)
=>
this
.
onBeforeRunCommand
(
id
)));
}
}
}
return
entries
;
}
private
editorActionsToEntries
(
actions
:
IEditorAction
[],
searchValue
:
string
):
EditorActionCommandEntry
[]
{
const
entries
:
EditorActionCommandEntry
[]
=
[];
...
...
@@ -621,4 +585,4 @@ export class CommandsHandler extends QuickOpenHandler {
lastCommandPaletteInput
=
void
0
;
// clear last input when user canceled quick open
}
}
}
\ No newline at end of file
}
src/vs/workbench/test/browser/actionRegistry.test.ts
浏览文件 @
65d45fd9
...
...
@@ -6,10 +6,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
*
as
Platform
from
'
vs/platform/registry/common/platform
'
;
import
{
SyncActionDescriptor
}
from
'
vs/platform/actions/common/actions
'
;
import
{
Separator
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
Extensions
,
IWorkbenchActionRegistry
}
from
'
vs/workbench/common/actions
'
;
import
{
prepareActions
}
from
'
vs/workbench/browser/actions
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
...
...
@@ -22,26 +19,6 @@ class MyClass extends Action {
suite
(
'
Workbench Action Registry
'
,
()
=>
{
test
(
'
Workbench Action Registration
'
,
function
()
{
let
Registry
=
<
IWorkbenchActionRegistry
>
Platform
.
Registry
.
as
(
Extensions
.
WorkbenchActions
);
let
d
=
new
SyncActionDescriptor
(
MyClass
,
'
id
'
,
'
name
'
);
let
oldActions
=
Registry
.
getWorkbenchActions
().
slice
(
0
);
let
oldCount
=
Registry
.
getWorkbenchActions
().
length
;
Registry
.
registerWorkbenchAction
(
d
,
'
My Alias
'
,
'
category
'
);
Registry
.
registerWorkbenchAction
(
d
,
null
);
assert
.
equal
(
Registry
.
getWorkbenchActions
().
length
,
1
+
oldCount
);
assert
.
strictEqual
(
d
,
Registry
.
getWorkbenchAction
(
'
id
'
));
assert
.
deepEqual
(
Registry
.
getAlias
(
d
.
id
),
'
My Alias
'
);
assert
.
equal
(
Registry
.
getCategory
(
d
.
id
),
'
category
'
);
(
<
any
>
Registry
).
setWorkbenchActions
(
oldActions
);
});
test
(
'
Workbench Action Bar prepareActions()
'
,
function
()
{
let
a1
=
new
Separator
();
let
a2
=
new
Separator
();
...
...
@@ -57,4 +34,4 @@ suite('Workbench Action Registry', () => {
assert
(
actions
[
1
]
===
a5
);
assert
(
actions
[
2
]
===
a6
);
});
});
\ No newline at end of file
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录