Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7dc49956
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,发现更多精彩内容 >>
提交
7dc49956
编写于
12月 19, 2017
作者:
I
isidor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
execution: properly contribute actions to explorer
上级
50bc4383
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
33 addition
and
99 deletion
+33
-99
src/vs/workbench/parts/execution/electron-browser/execution.contribution.ts
...arts/execution/electron-browser/execution.contribution.ts
+33
-99
未找到文件。
src/vs/workbench/parts/execution/electron-browser/execution.contribution.ts
浏览文件 @
7dc49956
...
...
@@ -8,18 +8,14 @@ import * as nls from 'vs/nls';
import
*
as
env
from
'
vs/base/common/platform
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
IAction
,
Action
}
from
'
vs/base/common/actions
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
registerSingleton
}
from
'
vs/platform/instantiation/common/extensions
'
;
import
{
IWorkbenchActionRegistry
,
Extensions
as
ActionExtensions
}
from
'
vs/workbench/common/actions
'
;
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
resources
=
require
(
'
vs/base/common/resources
'
);
import
{
Scope
,
IActionBarRegistry
,
Extensions
as
ActionBarExtensions
,
ActionBarContributor
}
from
'
vs/workbench/browser/actions
'
;
import
uri
from
'
vs/base/common/uri
'
;
import
{
explorerItemToFileResource
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
ITerminalService
}
from
'
vs/workbench/parts/execution/common/execution
'
;
import
{
SyncActionDescriptor
,
MenuId
,
MenuRegistry
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IWorkbenchEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
toResource
,
IEditorContext
}
from
'
vs/workbench/common/editor
'
;
import
{
KeyMod
,
KeyCode
}
from
'
vs/base/common/keyCodes
'
;
...
...
@@ -30,7 +26,7 @@ import { WinTerminalService, MacTerminalService, LinuxTerminalService } from 'vs
import
{
IHistoryService
}
from
'
vs/workbench/services/history/common/history
'
;
import
{
CommandsRegistry
,
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
EditorWithResourceFocusedInOpenEditorsContext
}
from
'
vs/workbench/parts/files/electron-browser/fileCommands
'
;
import
{
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
ResourceContextKey
}
from
'
vs/workbench/common/resources
'
;
if
(
env
.
isWindows
)
{
registerSingleton
(
ITerminalService
,
WinTerminalService
);
...
...
@@ -109,74 +105,6 @@ class OpenConsoleAction extends Action {
}
}
class
OpenIntegratedTerminalAction
extends
Action
{
public
static
readonly
ID
=
'
workbench.action.terminal.openFolderInIntegratedTerminal
'
;
public
static
readonly
Label
=
nls
.
localize
(
'
openFolderInIntegratedTerminal
'
,
"
Open in Terminal
"
);
private
resource
:
uri
;
public
setResource
(
resource
:
uri
):
void
{
this
.
resource
=
resource
;
this
.
enabled
=
!
paths
.
isUNC
(
this
.
resource
.
fsPath
);
}
constructor
(
id
:
string
,
label
:
string
,
@
ICommandService
private
commandService
:
ICommandService
)
{
super
(
id
,
label
);
}
public
run
(
event
?:
any
):
TPromise
<
any
>
{
return
this
.
commandService
.
executeCommand
(
OPEN_CONSOLE_COMMAND_ID
,
this
.
resource
);
}
}
export
class
ExplorerViewerActionContributor
extends
ActionBarContributor
{
constructor
(
@
IInstantiationService
private
instantiationService
:
IInstantiationService
,
@
IConfigurationService
private
configurationService
:
IConfigurationService
)
{
super
();
}
public
hasSecondaryActions
(
context
:
any
):
boolean
{
const
fileResource
=
explorerItemToFileResource
(
context
.
element
);
return
fileResource
&&
fileResource
.
resource
.
scheme
===
'
file
'
;
}
public
getSecondaryActions
(
context
:
any
):
IAction
[]
{
let
fileResource
=
explorerItemToFileResource
(
context
.
element
);
let
resource
=
fileResource
.
resource
;
// We want the parent unless this resource is a directory
if
(
!
fileResource
.
isDirectory
)
{
resource
=
resources
.
dirname
(
resource
);
}
const
configuration
=
this
.
configurationService
.
getValue
<
ITerminalConfiguration
>
();
const
explorerKind
=
configuration
.
terminal
.
explorerKind
;
if
(
explorerKind
===
'
integrated
'
)
{
let
action
=
this
.
instantiationService
.
createInstance
(
OpenIntegratedTerminalAction
,
OpenIntegratedTerminalAction
.
ID
,
OpenIntegratedTerminalAction
.
Label
);
action
.
setResource
(
resource
);
return
[
action
];
}
else
{
let
action
=
this
.
instantiationService
.
createInstance
(
OpenConsoleAction
,
OpenConsoleAction
.
ID
,
OpenConsoleAction
.
ScopedLabel
);
action
.
setResource
(
resource
);
return
[
action
];
}
}
}
const
actionBarRegistry
=
Registry
.
as
<
IActionBarRegistry
>
(
ActionBarExtensions
.
Actionbar
);
actionBarRegistry
.
registerActionBarContributor
(
Scope
.
VIEWER
,
ExplorerViewerActionContributor
);
// Register Global Action to Open Console
Registry
.
as
<
IWorkbenchActionRegistry
>
(
ActionExtensions
.
WorkbenchActions
).
registerWorkbenchAction
(
new
SyncActionDescriptor
(
...
...
@@ -191,12 +119,17 @@ Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions).registe
const
OPEN_CONSOLE_COMMAND_ID
=
'
workbench.command.terminal.openNativeConsole
'
;
function
getPathToOpen
(
resource
:
uri
,
historyService
:
IHistoryService
,
editorService
:
IWorkbenchEditorService
):
string
{
CommandsRegistry
.
registerCommand
({
id
:
OPEN_CONSOLE_COMMAND_ID
,
handler
:
(
accessor
,
args
:
IEditorContext
)
=>
{
const
configurationService
=
accessor
.
get
(
IConfigurationService
);
const
historyService
=
accessor
.
get
(
IHistoryService
);
const
editorService
=
accessor
.
get
(
IWorkbenchEditorService
);
let
pathToOpen
:
string
;
// Try workspace path first
const
root
=
historyService
.
getLastActiveWorkspaceRoot
(
'
file
'
);
pathToOpen
=
resource
?
resource
.
fsPath
:
(
root
&&
root
.
fsPath
);
pathToOpen
=
args
.
resource
?
args
.
resource
.
fsPath
:
(
root
&&
root
.
fsPath
);
// Otherwise check if we have an active file open
if
(
!
pathToOpen
)
{
...
...
@@ -206,14 +139,6 @@ function getPathToOpen(resource: uri, historyService: IHistoryService, editorSer
}
}
return
pathToOpen
;
}
CommandsRegistry
.
registerCommand
({
id
:
OPEN_CONSOLE_COMMAND_ID
,
handler
:
(
accessor
,
args
:
IEditorContext
)
=>
{
const
configurationService
=
accessor
.
get
(
IConfigurationService
);
const
pathToOpen
=
getPathToOpen
(
args
.
resource
,
accessor
.
get
(
IHistoryService
),
accessor
.
get
(
IWorkbenchEditorService
));
if
(
configurationService
.
getValue
<
ITerminalConfiguration
>
().
terminal
.
explorerKind
===
'
integrated
'
)
{
const
integratedTerminalService
=
accessor
.
get
(
IIntegratedTerminalService
);
...
...
@@ -231,13 +156,22 @@ CommandsRegistry.registerCommand({
}
});
MenuRegistry
.
appendMenuItem
(
MenuId
.
OpenEditorsContext
,
{
group
:
'
1_files
'
,
order
:
30
,
command
:
{
const
openConsoleCommand
=
{
id
:
OPEN_CONSOLE_COMMAND_ID
,
title
:
env
.
isWindows
?
nls
.
localize
(
'
scopedConsoleActionWin
'
,
"
Open in Command Prompt
"
)
:
nls
.
localize
(
'
scopedConsoleActionMacLinux
'
,
"
Open in Terminal
"
)
},
when
:
ContextKeyExpr
.
and
(
EditorWithResourceFocusedInOpenEditorsContext
)
};
MenuRegistry
.
appendMenuItem
(
MenuId
.
OpenEditorsContext
,
{
group
:
'
1_files
'
,
order
:
30
,
command
:
openConsoleCommand
,
when
:
EditorWithResourceFocusedInOpenEditorsContext
});
MenuRegistry
.
appendMenuItem
(
MenuId
.
ExplorerContext
,
{
group
:
'
1_files
'
,
order
:
30
,
command
:
openConsoleCommand
,
when
:
ResourceContextKey
.
Scheme
.
isEqualTo
(
'
file
'
)
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录