Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2bf4a936
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,发现更多精彩内容 >>
提交
2bf4a936
编写于
6月 24, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
prepare for editor context menu
上级
78b4ea28
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
30 deletion
+43
-30
src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
+42
-29
src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
+1
-1
未找到文件。
src/vs/editor/contrib/contextmenu/browser/contextmenu.ts
浏览文件 @
2bf4a936
...
...
@@ -14,6 +14,7 @@ import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent';
import
{
ActionItem
,
Separator
}
from
'
vs/base/browser/ui/actionbar/actionbar
'
;
import
{
IContextMenuService
,
IContextViewService
}
from
'
vs/platform/contextview/browser/contextView
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybindingService
'
;
import
{
IMenuService
,
IMenu
,
MenuId
}
from
'
vs/platform/actions/common/actions
'
;
import
{
EditorAction
}
from
'
vs/editor/common/editorAction
'
;
import
{
Behaviour
}
from
'
vs/editor/common/editorActionEnablement
'
;
import
{
ICommonCodeEditor
,
IEditorActionDescriptorData
,
IEditorContribution
,
MouseTargetType
}
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -22,34 +23,33 @@ import {ICodeEditor, IEditorMouseEvent} from 'vs/editor/browser/editorBrowser';
import
{
EditorBrowserRegistry
}
from
'
vs/editor/browser/editorBrowserExtensions
'
;
interface
IPosition
{
x
:
number
;
y
:
number
;
x
:
number
;
y
:
number
;
}
class
ContextMenuController
implements
IEditorContribution
{
public
static
ID
=
'
editor.contrib.contextmenu
'
;
private
contextMenuService
:
IContextMenuService
;
private
contextViewService
:
IContextViewService
;
private
keybindingService
:
IKeybindingService
;
private
_editor
:
ICodeEditor
;
private
_toDispose
:
IDisposable
[];
private
_contextMenuIsBeingShownCount
:
number
;
constructor
(
editor
:
ICodeEditor
,
@
IContextMenuService
contextMenuService
:
IContextMenuService
,
@
IContextViewService
contextViewService
:
IContextViewService
,
@
IKeybindingService
keybindingService
:
IKeybindingService
)
{
this
.
contextMenuService
=
contextMenuService
;
this
.
contextViewService
=
contextViewService
;
this
.
keybindingService
=
keybindingService
;
private
_editor
:
ICodeEditor
;
private
_contextMenu
:
IMenu
;
private
_toDispose
:
IDisposable
[]
;
private
_contextMenuIsBeingShownCount
:
number
;
constructor
(
editor
:
ICodeEditor
,
@
IContextMenuService
private
_contextMenuService
:
IContextMenuService
,
@
IContextViewService
private
_contextViewService
:
IContextViewService
,
@
IKeybindingService
private
_keybindingService
:
IKeybindingService
,
@
IMenuService
private
_menuService
:
IMenuService
)
{
this
.
_editor
=
editor
;
this
.
_toDispose
=
[];
this
.
_contextMenuIsBeingShownCount
=
0
;
this
.
_toDispose
.
push
(
this
.
_editor
.
onContextMenu
((
e
:
IEditorMouseEvent
)
=>
this
.
_onContextMenu
(
e
)));
this
.
_toDispose
.
push
(
this
.
_editor
.
onKeyDown
((
e
:
IKeyboardEvent
)
=>
{
this
.
_toDispose
.
push
(
this
.
_editor
.
onContextMenu
((
e
:
IEditorMouseEvent
)
=>
this
.
_onContextMenu
(
e
)));
this
.
_toDispose
.
push
(
this
.
_editor
.
onKeyDown
((
e
:
IKeyboardEvent
)
=>
{
if
(
e
.
keyCode
===
KeyCode
.
ContextMenu
)
{
// Chrome is funny like that
e
.
preventDefault
();
...
...
@@ -59,7 +59,7 @@ class ContextMenuController implements IEditorContribution {
}));
}
private
_onContextMenu
(
e
:
IEditorMouseEvent
):
void
{
private
_onContextMenu
(
e
:
IEditorMouseEvent
):
void
{
if
(
!
this
.
_editor
.
getConfiguration
().
contribInfo
.
contextmenu
)
{
this
.
_editor
.
focus
();
// Ensure the cursor is at the position of the mouse click
...
...
@@ -79,6 +79,12 @@ class ContextMenuController implements IEditorContribution {
return
;
// only support mouse click into text or native context menu key for now
}
// Ensure menu is there
if
(
!
this
.
_contextMenu
)
{
this
.
_contextMenu
=
this
.
_menuService
.
createMenu
(
MenuId
.
EditorContext
,
this
.
_editor
.
getDomNode
());
this
.
_toDispose
.
push
(
this
.
_contextMenu
);
}
// Ensure the editor gets focus if it hasn't, so the right events are being sent to other contributions
this
.
_editor
.
focus
();
...
...
@@ -88,7 +94,7 @@ class ContextMenuController implements IEditorContribution {
}
// Unless the user triggerd the context menu through Shift+F10, use the mouse position as menu position
var
forcedPosition
:
IPosition
;
var
forcedPosition
:
IPosition
;
if
(
e
.
target
.
type
!==
MouseTargetType
.
TEXTAREA
)
{
forcedPosition
=
{
x
:
e
.
event
.
posx
,
y
:
e
.
event
.
posy
+
1
};
}
...
...
@@ -97,12 +103,12 @@ class ContextMenuController implements IEditorContribution {
this
.
showContextMenu
(
forcedPosition
);
}
public
showContextMenu
(
forcedPosition
?:
IPosition
):
void
{
public
showContextMenu
(
forcedPosition
?:
IPosition
):
void
{
if
(
!
this
.
_editor
.
getConfiguration
().
contribInfo
.
contextmenu
)
{
return
;
// Context menu is turned off through configuration
}
if
(
!
this
.
contextMenuService
)
{
if
(
!
this
.
_
contextMenuService
)
{
this
.
_editor
.
focus
();
return
;
// We need the context menu service to function
}
...
...
@@ -123,12 +129,19 @@ class ContextMenuController implements IEditorContribution {
}
private
_getMenuActions
():
IAction
[]
{
// const actions = this._contextMenu.getActions();
// if (actions.length > 0) {
// console.log(actions);
// return actions;
// }
const
editorModel
=
this
.
_editor
.
getModel
();
if
(
!
editorModel
)
{
return
[];
}
const
contributedActions
=
<
EditorAction
[]
>
this
.
_editor
.
getActions
().
filter
(
action
=>
{
const
contributedActions
=
<
EditorAction
[]
>
this
.
_editor
.
getActions
().
filter
(
action
=>
{
if
(
action
instanceof
EditorAction
)
{
return
action
.
shouldShowInContextMenu
()
&&
action
.
isSupported
();
}
...
...
@@ -172,7 +185,7 @@ class ContextMenuController implements IEditorContribution {
return
result
;
}
private
_doShowContextMenu
(
actions
:
IAction
[],
forcedPosition
:
IPosition
=
null
):
void
{
private
_doShowContextMenu
(
actions
:
IAction
[],
forcedPosition
:
IPosition
=
null
):
void
{
// Make the editor believe one of its widgets is focused
this
.
_editor
.
beginForcedWidgetFocus
();
...
...
@@ -200,7 +213,7 @@ class ContextMenuController implements IEditorContribution {
}
// Show menu
this
.
contextMenuService
.
showContextMenu
({
this
.
_
contextMenuService
.
showContextMenu
({
getAnchor
:
()
=>
menuPosition
,
getActions
:
()
=>
{
...
...
@@ -210,7 +223,7 @@ class ContextMenuController implements IEditorContribution {
getActionItem
:
(
action
)
=>
{
var
keybinding
=
this
.
_keybindingFor
(
action
);
if
(
keybinding
)
{
return
new
ActionItem
(
action
,
action
,
{
label
:
true
,
keybinding
:
this
.
keybindingService
.
getLabelFor
(
keybinding
)
});
return
new
ActionItem
(
action
,
action
,
{
label
:
true
,
keybinding
:
this
.
_
keybindingService
.
getLabelFor
(
keybinding
)
});
}
var
customActionItem
=
<
any
>
action
;
...
...
@@ -225,7 +238,7 @@ class ContextMenuController implements IEditorContribution {
return
this
.
_keybindingFor
(
action
);
},
onHide
:
(
wasCancelled
:
boolean
)
=>
{
onHide
:
(
wasCancelled
:
boolean
)
=>
{
this
.
_contextMenuIsBeingShownCount
--
;
this
.
_editor
.
focus
();
this
.
_editor
.
endForcedWidgetFocus
();
...
...
@@ -237,7 +250,7 @@ class ContextMenuController implements IEditorContribution {
}
private
_keybindingFor
(
action
:
IAction
):
Keybinding
{
var
opts
=
this
.
keybindingService
.
lookupKeybindings
(
action
.
id
);
var
opts
=
this
.
_
keybindingService
.
lookupKeybindings
(
action
.
id
);
if
(
opts
.
length
>
0
)
{
return
opts
[
0
];
// only take the first one
}
...
...
@@ -250,7 +263,7 @@ class ContextMenuController implements IEditorContribution {
public
dispose
():
void
{
if
(
this
.
_contextMenuIsBeingShownCount
>
0
)
{
this
.
contextViewService
.
hideContextView
();
this
.
_
contextViewService
.
hideContextView
();
}
this
.
_toDispose
=
dispose
(
this
.
_toDispose
);
...
...
@@ -261,7 +274,7 @@ class ShowContextMenu extends EditorAction {
public
static
ID
=
'
editor.action.showContextMenu
'
;
constructor
(
descriptor
:
IEditorActionDescriptorData
,
editor
:
ICommonCodeEditor
)
{
constructor
(
descriptor
:
IEditorActionDescriptorData
,
editor
:
ICommonCodeEditor
)
{
super
(
descriptor
,
editor
,
Behaviour
.
TextFocus
);
}
...
...
src/vs/platform/keybinding/browser/keybindingServiceImpl.ts
浏览文件 @
2bf4a936
...
...
@@ -261,7 +261,7 @@ export abstract class KeybindingService extends AbstractKeybindingService implem
const
ctx
=
Object
.
create
(
null
);
this
.
getContext
(
this
.
_findContextAttr
(
domNode
)).
fillInContext
(
ctx
);
this
.
_configurationContext
.
fillInContext
(
ctx
);
// console.log(JSON.stringify(c
ontextValue
, null, '\t'));
// console.log(JSON.stringify(c
tx
, null, '\t'));
return
KeybindingResolver
.
contextMatchesRules
(
ctx
,
rules
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录