Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
377b177a
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,发现更多精彩内容 >>
提交
377b177a
编写于
8月 03, 2016
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce EditorAction2 and wire it up
上级
abe20b69
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
146 addition
and
2 deletion
+146
-2
src/vs/editor/browser/widget/codeEditorWidget.ts
src/vs/editor/browser/widget/codeEditorWidget.ts
+6
-0
src/vs/editor/common/editorAction.ts
src/vs/editor/common/editorAction.ts
+33
-0
src/vs/editor/common/editorCommonExtensions.ts
src/vs/editor/common/editorCommonExtensions.ts
+107
-2
未找到文件。
src/vs/editor/browser/widget/codeEditorWidget.ts
浏览文件 @
377b177a
...
...
@@ -29,6 +29,7 @@ import {View} from 'vs/editor/browser/view/viewImpl';
import
{
Disposable
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
IKeyboardEvent
}
from
'
vs/base/browser/keyboardEvent
'
;
import
{
NewEditorAction
}
from
'
vs/editor/common/editorAction
'
;
export
class
CodeEditorWidget
extends
CommonCodeEditor
implements
editorBrowser
.
ICodeEditor
{
...
...
@@ -107,6 +108,11 @@ export class CodeEditorWidget extends CommonCodeEditor implements editorBrowser.
onUnexpectedError
(
err
);
}
}
CommonEditorRegistry
.
getEditorActions
().
forEach
((
action
)
=>
{
let
contribution
=
new
NewEditorAction
(
action
,
this
,
this
.
_instantiationService
);
this
.
contributions
[
contribution
.
getId
()]
=
contribution
;
});
}
protected
_createConfiguration
(
options
:
editorCommon
.
ICodeEditorWidgetCreationOptions
):
CommonEditorConfiguration
{
...
...
src/vs/editor/common/editorAction.ts
浏览文件 @
377b177a
...
...
@@ -10,6 +10,8 @@ import {TPromise} from 'vs/base/common/winjs.base';
import
{
Behaviour
,
IEnablementState
,
createActionEnablement
}
from
'
vs/editor/common/editorActionEnablement
'
;
import
{
IActionDescriptor
,
IActionEnablement
,
ICommonCodeEditor
,
IEditorActionDescriptorData
,
IEditorContribution
}
from
'
vs/editor/common/editorCommon
'
;
import
{
ILineContext
}
from
'
vs/editor/common/modes
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
EditorAction2
}
from
'
vs/editor/common/editorCommonExtensions
'
;
var
defaultBehaviour
=
Behaviour
.
TextFocus
|
Behaviour
.
Writeable
|
Behaviour
.
UpdateOnModelChange
;
...
...
@@ -95,6 +97,37 @@ export class EditorAction extends Action implements IEditorContribution {
}
}
export
class
NewEditorAction
extends
EditorAction
{
private
_actual
:
EditorAction2
;
private
_instantiationService
:
IInstantiationService
;
constructor
(
actual
:
EditorAction2
,
editor
:
ICommonCodeEditor
,
instantiationService
:
IInstantiationService
)
{
super
({
id
:
actual
.
id
,
label
:
actual
.
label
,
alias
:
actual
.
alias
},
editor
,
0
);
this
.
_actual
=
actual
;
this
.
_instantiationService
=
instantiationService
;
}
public
get
enabled
():
boolean
{
return
this
.
_instantiationService
.
invokeFunction
((
accessor
)
=>
{
return
this
.
_actual
.
enabled
(
accessor
,
this
.
editor
);
});
}
public
isSupported
():
boolean
{
return
this
.
_instantiationService
.
invokeFunction
((
accessor
)
=>
{
return
this
.
_actual
.
supported
(
accessor
,
this
.
editor
);
});
}
public
run
():
TPromise
<
void
>
{
return
this
.
_instantiationService
.
invokeFunction
((
accessor
)
=>
{
this
.
_actual
.
run
(
accessor
,
this
.
editor
);
return
TPromise
.
as
(
void
0
);
});
}
}
export
class
HandlerEditorAction
extends
EditorAction
{
private
_handlerId
:
string
;
...
...
src/vs/editor/common/editorCommonExtensions.ts
浏览文件 @
377b177a
...
...
@@ -7,8 +7,7 @@
import
{
illegalArgument
,
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
SyncDescriptor1
,
createSyncDescriptor
}
from
'
vs/platform/instantiation/common/descriptors
'
;
import
{
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ServicesAccessor
,
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IKeybindings
,
KbExpr
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
ICommandHandler
}
from
'
vs/platform/commands/common/commands
'
;
import
{
ICommandDescriptor
,
KeybindingsRegistry
}
from
'
vs/platform/keybinding/common/keybindingsRegistry
'
;
...
...
@@ -20,6 +19,8 @@ import * as editorCommon from 'vs/editor/common/editorCommon';
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
MenuId
,
MenuRegistry
}
from
'
vs/platform/actions/common/actions
'
;
export
type
ServicesAccessor
=
ServicesAccessor
;
// --- Keybinding extensions to make it more concise to express keybindings conditions
export
enum
ContextKey
{
None
=
0
,
...
...
@@ -73,6 +74,14 @@ export module CommonEditorRegistry {
(
<
EditorContributionRegistry
>
Registry
.
as
(
Extensions
.
EditorCommonContributions
)).
registerEditorAction
(
desc
);
}
export
function
registerEditorAction2
(
desc
:
EditorAction2
)
{
(
<
EditorContributionRegistry
>
Registry
.
as
(
Extensions
.
EditorCommonContributions
)).
registerEditorAction2
(
desc
);
}
export
function
getEditorActions
():
EditorAction2
[]
{
return
(
<
EditorContributionRegistry
>
Registry
.
as
(
Extensions
.
EditorCommonContributions
)).
getEditorActions2
();
}
// --- Editor Contributions
export
function
registerEditorContribution
(
ctor
:
editorCommon
.
ICommonEditorContributionCtor
):
void
{
(
<
EditorContributionRegistry
>
Registry
.
as
(
Extensions
.
EditorCommonContributions
)).
registerEditorContribution2
(
ctor
);
...
...
@@ -171,15 +180,55 @@ var Extensions = {
class
EditorContributionRegistry
{
private
editorContributions
:
editorCommon
.
ICommonEditorContributionDescriptor
[];
private
editorActions
:
EditorAction2
[];
constructor
()
{
this
.
editorContributions
=
[];
this
.
editorActions
=
[];
}
public
registerEditorContribution2
(
ctor
:
editorCommon
.
ICommonEditorContributionCtor
):
void
{
this
.
editorContributions
.
push
(
new
SimpleEditorContributionDescriptor
(
ctor
));
}
public
registerEditorAction2
(
action
:
EditorAction2
)
{
if
(
action
.
menuOpts
)
{
let
{
menu
,
kbExpr
,
group
,
order
}
=
action
.
menuOpts
;
MenuRegistry
.
appendMenuItem
(
menu
||
MenuId
.
EditorContext
,
{
command
:
{
id
:
action
.
id
,
title
:
action
.
label
},
when
:
kbExpr
,
group
,
order
});
}
if
(
!
action
.
kbOpts
)
{
action
.
kbOpts
=
{
primary
:
0
};
}
let
commandDesc
:
ICommandDescriptor
=
{
id
:
action
.
id
,
handler
:
triggerEditorActionGlobal
.
bind
(
null
,
action
.
id
),
weight
:
KeybindingsRegistry
.
WEIGHT
.
editorContrib
(),
when
:
action
.
kbOpts
.
kbExpr
,
primary
:
action
.
kbOpts
.
primary
,
secondary
:
action
.
kbOpts
.
secondary
,
win
:
action
.
kbOpts
.
win
,
linux
:
action
.
kbOpts
.
linux
,
mac
:
action
.
kbOpts
.
mac
,
};
KeybindingsRegistry
.
registerCommandDesc
(
commandDesc
);
this
.
editorActions
.
push
(
action
);
}
public
registerEditorAction
(
desc
:
EditorActionDescriptor
):
void
{
let
handler
=
desc
.
kbOpts
.
handler
;
if
(
!
handler
)
{
...
...
@@ -235,6 +284,10 @@ class EditorContributionRegistry {
public
getEditorContributions2
():
editorCommon
.
ICommonEditorContributionDescriptor
[]
{
return
this
.
editorContributions
.
slice
(
0
);
}
public
getEditorActions2
():
EditorAction2
[]
{
return
this
.
editorActions
.
slice
(
0
);
}
}
Registry
.
add
(
Extensions
.
EditorCommonContributions
,
new
EditorContributionRegistry
());
...
...
@@ -283,3 +336,55 @@ function createCommandHandler(commandId: string, handler: IEditorCommandHandler)
});
};
}
export
interface
IEditorActionKeybindingOptions2
extends
IKeybindings
{
kbExpr
?:
KbExpr
;
}
export
abstract
class
EditorAction2
{
private
_needsWritableEditor
:
boolean
;
public
id
:
string
;
public
label
:
string
;
public
alias
:
string
;
public
kbOpts
:
IEditorActionKeybindingOptions2
;
public
menuOpts
:
IEditorCommandMenuOptions
;
constructor
(
id
:
string
,
label
:
string
,
alias
:
string
=
null
,
needsWritableEditor
:
boolean
=
false
)
{
this
.
id
=
id
;
this
.
label
=
label
;
this
.
alias
=
alias
;
this
.
_needsWritableEditor
=
needsWritableEditor
;
this
.
kbOpts
=
null
;
this
.
menuOpts
=
null
;
}
public
enabled
(
accessor
:
ServicesAccessor
,
editor
:
editorCommon
.
ICommonCodeEditor
):
boolean
{
if
(
this
.
_needsWritableEditor
)
{
return
!
editor
.
getConfiguration
().
readOnly
;
}
return
true
;
}
public
supported
(
accessor
:
ServicesAccessor
,
editor
:
editorCommon
.
ICommonCodeEditor
):
boolean
{
if
(
this
.
_needsWritableEditor
)
{
return
!
editor
.
getConfiguration
().
readOnly
;
}
return
true
;
}
public
abstract
run
(
accessor
:
ServicesAccessor
,
editor
:
editorCommon
.
ICommonCodeEditor
):
void
;
}
export
let
EditorKbExpr
:
{
TextFocus
:
KbExpr
;
Focus
:
KbExpr
;
ReadOnly
:
KbExpr
;
Writable
:
KbExpr
;
}
=
{
TextFocus
:
KbExpr
.
has
(
editorCommon
.
KEYBINDING_CONTEXT_EDITOR_TEXT_FOCUS
),
Focus
:
KbExpr
.
has
(
editorCommon
.
KEYBINDING_CONTEXT_EDITOR_FOCUS
),
ReadOnly
:
KbExpr
.
has
(
editorCommon
.
KEYBINDING_CONTEXT_EDITOR_READONLY
),
Writable
:
KbExpr
.
not
(
editorCommon
.
KEYBINDING_CONTEXT_EDITOR_READONLY
),
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录