Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
67f09910
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,发现更多精彩内容 >>
提交
67f09910
编写于
1月 09, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
scm: getResourceFromURI
上级
992704e8
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
286 addition
and
193 deletion
+286
-193
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+33
-21
extensions/git/src/model.ts
extensions/git/src/model.ts
+132
-1
extensions/git/src/scmProvider.ts
extensions/git/src/scmProvider.ts
+2
-132
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+1
-0
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+5
-0
src/vs/workbench/api/node/extHostSCM.ts
src/vs/workbench/api/node/extHostSCM.ts
+81
-23
src/vs/workbench/parts/scm/browser/scmMenus.ts
src/vs/workbench/parts/scm/browser/scmMenus.ts
+28
-12
src/vs/workbench/parts/scm/browser/scmViewlet.ts
src/vs/workbench/parts/scm/browser/scmViewlet.ts
+4
-4
未找到文件。
extensions/git/src/commands.ts
浏览文件 @
67f09910
...
...
@@ -5,62 +5,74 @@
'
use strict
'
;
import
{
commands
,
Disposable
,
SCMResourceGroup
,
SCMResource
}
from
'
vscode
'
;
import
{
Model
}
from
'
./model
'
;
import
{
Uri
,
commands
,
scm
,
Disposable
,
SCMResourceGroup
,
SCMResource
}
from
'
vscode
'
;
import
{
Model
,
Resource
,
ResourceGroup
}
from
'
./model
'
;
import
{
log
}
from
'
./util
'
;
type
Command
=
(...
args
:
any
[])
=>
any
;
function
refresh
(
model
:
Model
):
void
{
log
(
'
refresh
'
);
model
.
update
();
}
function
openChange
(
model
:
Model
,
resource
:
SCM
Resource
):
void
{
function
openChange
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
open change
'
,
resource
);
}
function
openFile
(
model
:
Model
,
resource
:
SCM
Resource
):
void
{
function
openFile
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
open file
'
,
resource
);
}
function
stage
(
model
:
Model
,
resource
:
SCM
Resource
):
void
{
function
stage
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
stage
'
,
resource
);
}
function
stageAll
(
model
:
Model
,
resourceGroup
:
SCM
ResourceGroup
):
void
{
function
stageAll
(
model
:
Model
,
resourceGroup
:
ResourceGroup
):
void
{
log
(
'
stageAll
'
,
resourceGroup
);
}
function
unstage
(
model
:
Model
,
resource
:
SCM
Resource
):
void
{
function
unstage
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
unstage
'
,
resource
);
}
function
unstageAll
(
model
:
Model
,
resourceGroup
:
SCM
ResourceGroup
):
void
{
function
unstageAll
(
model
:
Model
,
resourceGroup
:
ResourceGroup
):
void
{
log
(
'
unstageAll
'
,
resourceGroup
);
}
function
clean
(
model
:
Model
,
resource
:
SCM
Resource
):
void
{
function
clean
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
clean
'
,
resource
);
}
function
cleanAll
(
model
:
Model
,
resourceGroup
:
SCM
ResourceGroup
):
void
{
function
cleanAll
(
model
:
Model
,
resourceGroup
:
ResourceGroup
):
void
{
log
(
'
clean all
'
,
resourceGroup
);
}
function
bind
(
command
:
(
model
:
Model
,
...
args
:
any
[])
=>
any
,
model
:
Model
):
(...
args
:
any
[])
=>
any
{
return
command
.
bind
(
null
,
model
);
function
resolveURI
<
R
>
(
command
:
(
t
:
SCMResource
|
SCMResourceGroup
|
undefined
)
=>
R
):
(
uri
:
Uri
)
=>
R
|
undefined
{
return
uri
=>
uri
.
authority
!==
'
git
'
?
undefined
:
command
(
scm
.
getResourceFromURI
(
uri
));
}
function
skipUndefined
<
T
,
R
>
(
command
:
(
t
:
T
)
=>
R
):
(
t
:
T
|
undefined
)
=>
R
|
undefined
{
return
t
=>
t
===
undefined
?
undefined
:
command
(
t
);
}
function
compose
(
command
:
Command
,
...
args
:
Function
[]):
Command
{
return
args
.
reduce
((
r
,
fn
)
=>
fn
(
r
),
command
)
as
Command
;
}
export
function
registerCommands
(
model
:
Model
):
Disposable
{
const
bindModel
=
command
=>
(...
args
:
any
[])
=>
command
(
model
,
...
args
);
const
disposables
=
[
commands
.
registerCommand
(
'
git.refresh
'
,
bind
(
refresh
,
m
odel
)),
commands
.
registerCommand
(
'
git.openChange
'
,
bind
(
openChange
,
model
)),
commands
.
registerCommand
(
'
git.openFile
'
,
bind
(
openFile
,
model
)),
commands
.
registerCommand
(
'
git.stage
'
,
bind
(
stage
,
model
)),
commands
.
registerCommand
(
'
git.stageAll
'
,
bind
(
stageAll
,
model
)),
commands
.
registerCommand
(
'
git.unstage
'
,
bind
(
unstage
,
model
)),
commands
.
registerCommand
(
'
git.unstageAll
'
,
bind
(
unstageAll
,
model
)),
commands
.
registerCommand
(
'
git.clean
'
,
bind
(
clean
,
model
)),
commands
.
registerCommand
(
'
git.cleanAll
'
,
bind
(
cleanAll
,
model
)),
commands
.
registerCommand
(
'
git.refresh
'
,
compose
(
refresh
,
bindM
odel
)),
commands
.
registerCommand
(
'
git.openChange
'
,
compose
(
openChange
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.openFile
'
,
compose
(
openFile
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.stage
'
,
compose
(
stage
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.stageAll
'
,
compose
(
stageAll
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.unstage
'
,
compose
(
unstage
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.unstageAll
'
,
compose
(
unstageAll
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.clean
'
,
compose
(
clean
,
bindModel
,
resolveURI
,
skipUndefined
)),
commands
.
registerCommand
(
'
git.cleanAll
'
,
compose
(
cleanAll
,
bindModel
,
resolveURI
,
skipUndefined
)),
];
return
Disposable
.
from
(...
disposables
);
...
...
extensions/git/src/model.ts
浏览文件 @
67f09910
...
...
@@ -5,10 +5,141 @@
'
use strict
'
;
import
{
EventEmitter
,
Event
}
from
'
vscode
'
;
import
{
Uri
,
EventEmitter
,
Event
,
SCMResource
,
SCMResourceDecorations
,
SCMResourceGroup
}
from
'
vscode
'
;
import
{
Repository
,
IRef
,
IFileStatus
,
IRemote
}
from
'
./git
'
;
import
{
throttle
}
from
'
./util
'
;
import
{
decorate
,
debounce
}
from
'
core-decorators
'
;
import
*
as
path
from
'
path
'
;
const
iconsRootPath
=
path
.
join
(
path
.
dirname
(
__dirname
),
'
resources
'
,
'
icons
'
);
function
getIconUri
(
iconName
:
string
,
theme
:
string
):
Uri
{
return
Uri
.
file
(
path
.
join
(
iconsRootPath
,
theme
,
`
${
iconName
}
.svg`
));
}
export
enum
Status
{
INDEX_MODIFIED
,
INDEX_ADDED
,
INDEX_DELETED
,
INDEX_RENAMED
,
INDEX_COPIED
,
MODIFIED
,
DELETED
,
UNTRACKED
,
IGNORED
,
ADDED_BY_US
,
ADDED_BY_THEM
,
DELETED_BY_US
,
DELETED_BY_THEM
,
BOTH_ADDED
,
BOTH_DELETED
,
BOTH_MODIFIED
}
export
class
Resource
implements
SCMResource
{
get
uri
():
Uri
{
return
this
.
_uri
;
}
get
type
():
Status
{
return
this
.
_type
;
}
private
static
Icons
=
{
light
:
{
Modified
:
getIconUri
(
'
status-modified
'
,
'
light
'
),
Added
:
getIconUri
(
'
status-added
'
,
'
light
'
),
Deleted
:
getIconUri
(
'
status-deleted
'
,
'
light
'
),
Renamed
:
getIconUri
(
'
status-renamed
'
,
'
light
'
),
Copied
:
getIconUri
(
'
status-copied
'
,
'
light
'
),
Untracked
:
getIconUri
(
'
status-untracked
'
,
'
light
'
),
Ignored
:
getIconUri
(
'
status-ignored
'
,
'
light
'
),
Conflict
:
getIconUri
(
'
status-conflict
'
,
'
light
'
),
},
dark
:
{
Modified
:
getIconUri
(
'
status-modified
'
,
'
dark
'
),
Added
:
getIconUri
(
'
status-added
'
,
'
dark
'
),
Deleted
:
getIconUri
(
'
status-deleted
'
,
'
dark
'
),
Renamed
:
getIconUri
(
'
status-renamed
'
,
'
dark
'
),
Copied
:
getIconUri
(
'
status-copied
'
,
'
dark
'
),
Untracked
:
getIconUri
(
'
status-untracked
'
,
'
dark
'
),
Ignored
:
getIconUri
(
'
status-ignored
'
,
'
dark
'
),
Conflict
:
getIconUri
(
'
status-conflict
'
,
'
dark
'
)
}
};
private
getIconPath
(
theme
:
string
):
Uri
|
undefined
{
switch
(
this
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
return
Resource
.
Icons
[
theme
].
Modified
;
case
Status
.
MODIFIED
:
return
Resource
.
Icons
[
theme
].
Modified
;
case
Status
.
INDEX_ADDED
:
return
Resource
.
Icons
[
theme
].
Added
;
case
Status
.
INDEX_DELETED
:
return
Resource
.
Icons
[
theme
].
Deleted
;
case
Status
.
DELETED
:
return
Resource
.
Icons
[
theme
].
Deleted
;
case
Status
.
INDEX_RENAMED
:
return
Resource
.
Icons
[
theme
].
Renamed
;
case
Status
.
INDEX_COPIED
:
return
Resource
.
Icons
[
theme
].
Copied
;
case
Status
.
UNTRACKED
:
return
Resource
.
Icons
[
theme
].
Untracked
;
case
Status
.
IGNORED
:
return
Resource
.
Icons
[
theme
].
Ignored
;
case
Status
.
BOTH_DELETED
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
ADDED_BY_US
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
DELETED_BY_THEM
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
ADDED_BY_THEM
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
DELETED_BY_US
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
BOTH_ADDED
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
BOTH_MODIFIED
:
return
Resource
.
Icons
[
theme
].
Conflict
;
default
:
return
void
0
;
}
}
private
get
strikeThrough
():
boolean
{
switch
(
this
.
type
)
{
case
Status
.
DELETED
:
case
Status
.
BOTH_DELETED
:
case
Status
.
DELETED_BY_THEM
:
case
Status
.
DELETED_BY_US
:
return
true
;
default
:
return
false
;
}
}
get
decorations
():
SCMResourceDecorations
{
const
light
=
{
iconPath
:
this
.
getIconPath
(
'
light
'
)
};
const
dark
=
{
iconPath
:
this
.
getIconPath
(
'
dark
'
)
};
return
{
strikeThrough
:
this
.
strikeThrough
,
light
,
dark
};
}
constructor
(
private
_uri
:
Uri
,
private
_type
:
Status
)
{
}
}
export
class
ResourceGroup
implements
SCMResourceGroup
{
get
id
():
string
{
return
this
.
_id
;
}
get
label
():
string
{
return
this
.
_label
;
}
get
resources
():
SCMResource
[]
{
return
this
.
_resources
;
}
constructor
(
private
_id
:
string
,
private
_label
:
string
,
private
_resources
:
SCMResource
[])
{
}
}
export
class
MergeGroup
extends
ResourceGroup
{
constructor
(
resources
:
SCMResource
[])
{
super
(
'
merge
'
,
'
Merge Changes
'
,
resources
);
}
}
export
class
IndexGroup
extends
ResourceGroup
{
constructor
(
resources
:
SCMResource
[])
{
super
(
'
index
'
,
'
Staged Changes
'
,
resources
);
}
}
export
class
WorkingTreeGroup
extends
ResourceGroup
{
constructor
(
resources
:
SCMResource
[])
{
super
(
'
workingTree
'
,
'
Changes
'
,
resources
);
}
}
export
class
Model
{
...
...
extensions/git/src/scmProvider.ts
浏览文件 @
67f09910
...
...
@@ -6,142 +6,12 @@
'
use strict
'
;
import
{
Uri
,
Disposable
,
SCMProvider
,
SCMResource
,
SCMResourceDecorations
,
Uri
,
Disposable
,
SCMProvider
,
SCMResource
,
SCMResourceGroup
,
EventEmitter
,
Event
,
commands
}
from
'
vscode
'
;
import
{
Model
}
from
'
./model
'
;
import
{
Model
,
Status
,
WorkingTreeGroup
,
IndexGroup
,
MergeGroup
,
Resource
,
ResourceGroup
}
from
'
./model
'
;
import
*
as
path
from
'
path
'
;
const
iconsRootPath
=
path
.
join
(
path
.
dirname
(
__dirname
),
'
resources
'
,
'
icons
'
);
function
getIconUri
(
iconName
:
string
,
theme
:
string
):
Uri
{
return
Uri
.
file
(
path
.
join
(
iconsRootPath
,
theme
,
`
${
iconName
}
.svg`
));
}
export
enum
Status
{
INDEX_MODIFIED
,
INDEX_ADDED
,
INDEX_DELETED
,
INDEX_RENAMED
,
INDEX_COPIED
,
MODIFIED
,
DELETED
,
UNTRACKED
,
IGNORED
,
ADDED_BY_US
,
ADDED_BY_THEM
,
DELETED_BY_US
,
DELETED_BY_THEM
,
BOTH_ADDED
,
BOTH_DELETED
,
BOTH_MODIFIED
}
export
class
Resource
implements
SCMResource
{
get
uri
():
Uri
{
return
this
.
_uri
;
}
get
type
():
Status
{
return
this
.
_type
;
}
private
static
Icons
=
{
light
:
{
Modified
:
getIconUri
(
'
status-modified
'
,
'
light
'
),
Added
:
getIconUri
(
'
status-added
'
,
'
light
'
),
Deleted
:
getIconUri
(
'
status-deleted
'
,
'
light
'
),
Renamed
:
getIconUri
(
'
status-renamed
'
,
'
light
'
),
Copied
:
getIconUri
(
'
status-copied
'
,
'
light
'
),
Untracked
:
getIconUri
(
'
status-untracked
'
,
'
light
'
),
Ignored
:
getIconUri
(
'
status-ignored
'
,
'
light
'
),
Conflict
:
getIconUri
(
'
status-conflict
'
,
'
light
'
),
},
dark
:
{
Modified
:
getIconUri
(
'
status-modified
'
,
'
dark
'
),
Added
:
getIconUri
(
'
status-added
'
,
'
dark
'
),
Deleted
:
getIconUri
(
'
status-deleted
'
,
'
dark
'
),
Renamed
:
getIconUri
(
'
status-renamed
'
,
'
dark
'
),
Copied
:
getIconUri
(
'
status-copied
'
,
'
dark
'
),
Untracked
:
getIconUri
(
'
status-untracked
'
,
'
dark
'
),
Ignored
:
getIconUri
(
'
status-ignored
'
,
'
dark
'
),
Conflict
:
getIconUri
(
'
status-conflict
'
,
'
dark
'
)
}
};
private
getIconPath
(
theme
:
string
):
Uri
|
undefined
{
switch
(
this
.
type
)
{
case
Status
.
INDEX_MODIFIED
:
return
Resource
.
Icons
[
theme
].
Modified
;
case
Status
.
MODIFIED
:
return
Resource
.
Icons
[
theme
].
Modified
;
case
Status
.
INDEX_ADDED
:
return
Resource
.
Icons
[
theme
].
Added
;
case
Status
.
INDEX_DELETED
:
return
Resource
.
Icons
[
theme
].
Deleted
;
case
Status
.
DELETED
:
return
Resource
.
Icons
[
theme
].
Deleted
;
case
Status
.
INDEX_RENAMED
:
return
Resource
.
Icons
[
theme
].
Renamed
;
case
Status
.
INDEX_COPIED
:
return
Resource
.
Icons
[
theme
].
Copied
;
case
Status
.
UNTRACKED
:
return
Resource
.
Icons
[
theme
].
Untracked
;
case
Status
.
IGNORED
:
return
Resource
.
Icons
[
theme
].
Ignored
;
case
Status
.
BOTH_DELETED
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
ADDED_BY_US
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
DELETED_BY_THEM
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
ADDED_BY_THEM
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
DELETED_BY_US
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
BOTH_ADDED
:
return
Resource
.
Icons
[
theme
].
Conflict
;
case
Status
.
BOTH_MODIFIED
:
return
Resource
.
Icons
[
theme
].
Conflict
;
default
:
return
void
0
;
}
}
private
get
strikeThrough
():
boolean
{
switch
(
this
.
type
)
{
case
Status
.
DELETED
:
case
Status
.
BOTH_DELETED
:
case
Status
.
DELETED_BY_THEM
:
case
Status
.
DELETED_BY_US
:
return
true
;
default
:
return
false
;
}
}
get
decorations
():
SCMResourceDecorations
{
const
light
=
{
iconPath
:
this
.
getIconPath
(
'
light
'
)
};
const
dark
=
{
iconPath
:
this
.
getIconPath
(
'
dark
'
)
};
return
{
strikeThrough
:
this
.
strikeThrough
,
light
,
dark
};
}
constructor
(
private
_uri
:
Uri
,
private
_type
:
Status
)
{
}
}
export
class
ResourceGroup
implements
SCMResourceGroup
{
get
id
():
string
{
return
this
.
_id
;
}
get
label
():
string
{
return
this
.
_label
;
}
get
resources
():
SCMResource
[]
{
return
this
.
_resources
;
}
constructor
(
private
_id
:
string
,
private
_label
:
string
,
private
_resources
:
SCMResource
[])
{
}
}
export
class
MergeGroup
extends
ResourceGroup
{
constructor
(
resources
:
SCMResource
[])
{
super
(
'
merge
'
,
'
Merge Changes
'
,
resources
);
}
}
export
class
IndexGroup
extends
ResourceGroup
{
constructor
(
resources
:
SCMResource
[])
{
super
(
'
index
'
,
'
Staged Changes
'
,
resources
);
}
}
export
class
WorkingTreeGroup
extends
ResourceGroup
{
constructor
(
resources
:
SCMResource
[])
{
super
(
'
workingTree
'
,
'
Changes
'
,
resources
);
}
}
export
class
GitSCMProvider
implements
SCMProvider
{
private
disposables
:
Disposable
[]
=
[];
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
67f09910
...
...
@@ -121,6 +121,7 @@ declare module 'vscode' {
export
namespace
scm
{
export
const
onDidChangeActiveProvider
:
Event
<
SCMProvider
>
;
export
let
activeProvider
:
SCMProvider
|
undefined
;
export
function
getResourceFromURI
(
uri
:
Uri
):
SCMResource
|
SCMResourceGroup
|
undefined
;
export
function
registerSCMProvider
(
id
:
string
,
provider
:
SCMProvider
):
Disposable
;
}
}
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
67f09910
...
...
@@ -399,6 +399,11 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
return
extHostSCM
.
onDidChangeActiveProvider
;
}
@
proposed
(
extension
)
getResourceFromURI
(
uri
)
{
return
extHostSCM
.
getResourceFromURI
(
uri
);
}
@
proposed
(
extension
)
registerSCMProvider
(
id
,
provider
)
{
return
extHostSCM
.
registerSCMProvider
(
id
,
provider
);
...
...
src/vs/workbench/api/node/extHostSCM.ts
浏览文件 @
67f09910
...
...
@@ -15,7 +15,7 @@ import * as vscode from 'vscode';
function
getIconPath
(
decorations
:
vscode
.
SCMResourceThemableDecorations
)
{
if
(
!
decorations
)
{
return
void
0
;
return
undefined
;
}
else
if
(
typeof
decorations
.
iconPath
===
'
string
'
)
{
return
URI
.
file
(
decorations
.
iconPath
).
toString
();
}
else
if
(
decorations
.
iconPath
)
{
...
...
@@ -24,9 +24,11 @@ function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
}
export
interface
Cache
{
[
groupId
:
string
]:
{
resourceGroup
:
vscode
.
SCMResourceGroup
,
resources
:
{
[
uri
:
string
]:
vscode
.
SCMResource
}
[
providerId
:
string
]:
{
[
groupId
:
string
]:
{
resourceGroup
:
vscode
.
SCMResourceGroup
,
resources
:
{
[
uri
:
string
]:
vscode
.
SCMResource
}
};
};
}
...
...
@@ -47,15 +49,69 @@ export class ExtHostSCM {
this
.
_proxy
=
threadService
.
get
(
MainContext
.
MainThreadSCM
);
}
registerSCMProvider
(
id
:
string
,
provider
:
vscode
.
SCMProvider
):
Disposable
{
if
(
this
.
_providers
[
id
])
{
throw
new
Error
(
`Provider
${
id
}
already registered`
);
getResourceFromURI
(
uri
:
vscode
.
Uri
):
vscode
.
SCMResource
|
vscode
.
SCMResourceGroup
|
undefined
{
if
(
uri
.
scheme
!==
'
scm
'
)
{
return
undefined
;
}
const
providerId
=
uri
.
authority
;
const
providerCache
=
this
.
cache
[
providerId
];
if
(
!
providerCache
)
{
return
undefined
;
}
const
match
=
/^
\/([^/]
+
)(\/(
.*
))?
$/
.
exec
(
uri
.
path
);
if
(
!
match
)
{
return
undefined
;
}
const
resourceGroupId
=
match
[
1
];
const
resourceGroupRef
=
providerCache
[
resourceGroupId
];
if
(
!
resourceGroupRef
)
{
return
undefined
;
}
const
rawResourceUri
=
match
[
3
];
if
(
!
rawResourceUri
)
{
return
resourceGroupRef
.
resourceGroup
;
}
let
resourceUri
:
string
;
try
{
const
rawResource
=
JSON
.
parse
(
rawResourceUri
);
const
resource
=
URI
.
from
(
rawResource
);
resourceUri
=
resource
.
toString
();
}
catch
(
err
)
{
resourceUri
=
undefined
;
}
if
(
!
resourceUri
)
{
return
undefined
;
}
const
resource
=
resourceGroupRef
.
resources
[
resourceUri
];
if
(
!
resource
)
{
return
undefined
;
}
return
resource
;
}
registerSCMProvider
(
providerId
:
string
,
provider
:
vscode
.
SCMProvider
):
Disposable
{
if
(
this
.
_providers
[
providerId
])
{
throw
new
Error
(
`Provider
${
providerId
}
already registered`
);
}
// TODO@joao: should pluck all the things out of the provider
this
.
_providers
[
i
d
]
=
provider
;
this
.
_providers
[
providerI
d
]
=
provider
;
this
.
_proxy
.
$register
(
i
d
,
{
this
.
_proxy
.
$register
(
providerI
d
,
{
label
:
provider
.
label
,
supportsCommit
:
!!
provider
.
commit
,
supportsOpen
:
!!
provider
.
open
,
...
...
@@ -65,7 +121,7 @@ export class ExtHostSCM {
const
onDidChange
=
debounceEvent
(
provider
.
onDidChange
,
(
l
,
e
)
=>
e
,
100
);
const
onDidChangeListener
=
onDidChange
(
resourceGroups
=>
{
this
.
cache
=
Object
.
create
(
null
);
this
.
cache
[
providerId
]
=
Object
.
create
(
null
);
const
rawResourceGroups
=
resourceGroups
.
map
(
g
=>
{
const
resources
:
{
[
id
:
string
]:
vscode
.
SCMResource
;
}
=
Object
.
create
(
null
);
...
...
@@ -91,23 +147,23 @@ export class ExtHostSCM {
return
[
uri
,
icons
,
strikeThrough
]
as
SCMRawResource
;
});
this
.
cache
[
g
.
id
]
=
{
resourceGroup
:
g
,
resources
};
this
.
cache
[
providerId
][
g
.
id
]
=
{
resourceGroup
:
g
,
resources
};
return
[
g
.
id
,
g
.
label
,
rawResources
]
as
SCMRawResourceGroup
;
});
this
.
_proxy
.
$onChange
(
i
d
,
rawResourceGroups
);
this
.
_proxy
.
$onChange
(
providerI
d
,
rawResourceGroups
);
});
return
new
Disposable
(()
=>
{
onDidChangeListener
.
dispose
();
delete
this
.
_providers
[
i
d
];
this
.
_proxy
.
$unregister
(
i
d
);
delete
this
.
_providers
[
providerI
d
];
this
.
_proxy
.
$unregister
(
providerI
d
);
});
}
$commit
(
i
d
:
string
,
message
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_providers
[
i
d
];
$commit
(
providerI
d
:
string
,
message
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_providers
[
providerI
d
];
if
(
!
provider
)
{
return
TPromise
.
as
(
null
);
...
...
@@ -116,14 +172,15 @@ export class ExtHostSCM {
return
asWinJsPromise
(
token
=>
provider
.
commit
(
message
,
token
));
}
$open
(
i
d
:
string
,
resourceGroupId
:
string
,
uri
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_providers
[
i
d
];
$open
(
providerI
d
:
string
,
resourceGroupId
:
string
,
uri
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_providers
[
providerI
d
];
if
(
!
provider
)
{
return
TPromise
.
as
(
null
);
}
const
resourceGroup
=
this
.
cache
[
resourceGroupId
];
const
providerCache
=
this
.
cache
[
providerId
];
const
resourceGroup
=
providerCache
[
resourceGroupId
];
const
resource
=
resourceGroup
&&
resourceGroup
.
resources
[
uri
];
if
(
!
resource
)
{
...
...
@@ -133,16 +190,17 @@ export class ExtHostSCM {
return
asWinJsPromise
(
token
=>
provider
.
open
(
resource
,
token
));
}
$drag
(
i
d
:
string
,
fromResourceGroupId
:
string
,
fromUri
:
string
,
toResourceGroupId
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_providers
[
i
d
];
$drag
(
providerI
d
:
string
,
fromResourceGroupId
:
string
,
fromUri
:
string
,
toResourceGroupId
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_providers
[
providerI
d
];
if
(
!
provider
)
{
return
TPromise
.
as
(
null
);
}
const
fromResourceGroup
=
this
.
cache
[
fromResourceGroupId
];
const
providerCache
=
this
.
cache
[
providerId
];
const
fromResourceGroup
=
providerCache
[
fromResourceGroupId
];
const
resource
=
fromResourceGroup
&&
fromResourceGroup
.
resources
[
fromUri
];
const
toResourceGroup
=
this
.
c
ache
[
toResourceGroupId
];
const
toResourceGroup
=
providerC
ache
[
toResourceGroupId
];
const
resourceGroup
=
toResourceGroup
&&
toResourceGroup
.
resourceGroup
;
if
(
!
resource
||
!
resourceGroup
)
{
...
...
src/vs/workbench/parts/scm/browser/scmMenus.ts
浏览文件 @
67f09910
...
...
@@ -10,9 +10,9 @@ import { IDisposable, dispose, empty as EmptyDisposable, toDisposable } from 'vs
import
{
IContextKeyService
,
IContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
IMenuService
,
MenuId
}
from
'
vs/platform/actions/common/actions
'
;
import
{
IAction
}
from
'
vs/base/common/actions
'
;
import
URI
from
'
vs/base/common/uri
'
;
import
{
fillInActions
}
from
'
vs/platform/actions/browser/menuItemActionItem
'
;
import
{
ISCMService
,
ISCMProvider
}
from
'
vs/workbench/services/scm/common/scm
'
;
import
{
ISCMService
,
ISCMProvider
,
ISCMResource
,
ISCMResourceGroup
}
from
'
vs/workbench/services/scm/common/scm
'
;
export
class
SCMMenus
implements
IDisposable
{
...
...
@@ -67,25 +67,41 @@ export class SCMMenus implements IDisposable {
return
this
.
titleSecondaryActions
;
}
getResourceGroupActions
(
resourceGroupId
:
string
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResourceGroupContext
,
resourceGroupId
).
primary
;
getResourceGroupActions
(
group
:
ISCMResourceGroup
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResourceGroupContext
,
this
.
getSCMResourceGroupURI
(
group
),
group
.
id
).
primary
;
}
getResourceGroupContextActions
(
group
:
ISCMResourceGroup
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResourceGroupContext
,
this
.
getSCMResourceGroupURI
(
group
),
group
.
id
).
secondary
;
}
getResource
GroupContextActions
(
resourceGroupId
:
string
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResource
GroupContext
,
resourceGroupId
).
second
ary
;
getResource
Actions
(
resource
:
ISCMResource
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResource
Context
,
this
.
getSCMResourceURI
(
resource
),
resource
.
resourceGroupId
).
prim
ary
;
}
getResource
Actions
(
resourceGroupId
:
string
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResourceContext
,
resourceGroupId
).
prim
ary
;
getResource
ContextActions
(
resource
:
ISCMResource
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResourceContext
,
this
.
getSCMResourceURI
(
resource
),
resource
.
resourceGroupId
).
second
ary
;
}
getResourceContextActions
(
resourceGroupId
:
string
):
IAction
[]
{
return
this
.
getActions
(
MenuId
.
SCMResourceContext
,
resourceGroupId
).
secondary
;
private
getSCMResourceGroupURI
(
resourceGroup
:
ISCMResourceGroup
):
URI
{
return
URI
.
from
({
scheme
:
'
scm
'
,
authority
:
this
.
activeProviderContextKey
.
get
(),
path
:
`/
${
resourceGroup
.
id
}
`
});
}
private
getSCMResourceURI
(
resource
:
ISCMResource
):
URI
{
return
URI
.
from
({
scheme
:
'
scm
'
,
authority
:
this
.
activeProviderContextKey
.
get
(),
path
:
`/
${
resource
.
resourceGroupId
}
/
${
JSON
.
stringify
(
resource
.
uri
)}
`
});
}
private
static
readonly
NoActions
=
{
primary
:
[],
secondary
:
[]
};
private
getActions
(
menuId
:
MenuId
,
resourceGroupId
:
string
):
{
primary
:
IAction
[];
secondary
:
IAction
[];
}
{
private
getActions
(
menuId
:
MenuId
,
context
:
URI
,
resourceGroupId
:
string
):
{
primary
:
IAction
[];
secondary
:
IAction
[];
}
{
if
(
!
this
.
scmService
.
activeProvider
)
{
return
SCMMenus
.
NoActions
;
}
...
...
@@ -97,7 +113,7 @@ export class SCMMenus implements IDisposable {
const
primary
=
[];
const
secondary
=
[];
const
result
=
{
primary
,
secondary
};
fillInActions
(
menu
,
null
,
result
,
g
=>
g
===
'
inline
'
);
fillInActions
(
menu
,
context
,
result
,
g
=>
g
===
'
inline
'
);
menu
.
dispose
();
contextKeyService
.
dispose
();
...
...
src/vs/workbench/parts/scm/browser/scmViewlet.ts
浏览文件 @
67f09910
...
...
@@ -74,7 +74,7 @@ class ResourceGroupRenderer implements IRenderer<ISCMResourceGroup, ResourceGrou
template
.
name
.
textContent
=
group
.
label
;
template
.
count
.
setCount
(
group
.
resources
.
length
);
template
.
actionBar
.
clear
();
template
.
actionBar
.
push
(
this
.
scmMenus
.
getResourceGroupActions
(
group
.
id
));
template
.
actionBar
.
push
(
this
.
scmMenus
.
getResourceGroupActions
(
group
));
}
disposeTemplate
(
template
:
ResourceGroupTemplate
):
void
{
...
...
@@ -117,7 +117,7 @@ class ResourceRenderer implements IRenderer<ISCMResource, ResourceTemplate> {
renderElement
(
resource
:
ISCMResource
,
index
:
number
,
template
:
ResourceTemplate
):
void
{
template
.
fileLabel
.
setFile
(
resource
.
uri
);
template
.
actionBar
.
clear
();
template
.
actionBar
.
push
(
this
.
scmMenus
.
getResourceActions
(
resource
.
resourceGroupId
));
template
.
actionBar
.
push
(
this
.
scmMenus
.
getResourceActions
(
resource
));
toggleClass
(
template
.
name
,
'
strike-through
'
,
resource
.
decorations
.
strikeThrough
);
const
theme
=
this
.
themeService
.
getColorTheme
();
...
...
@@ -299,10 +299,10 @@ export class SCMViewlet extends Viewlet {
if
((
element
as
ISCMResource
).
uri
)
{
const
resource
=
element
as
ISCMResource
;
actions
=
this
.
menus
.
getResourceContextActions
(
resource
.
resourceGroupId
);
actions
=
this
.
menus
.
getResourceContextActions
(
resource
);
}
else
{
const
resourceGroup
=
element
as
ISCMResourceGroup
;
actions
=
this
.
menus
.
getResourceGroupContextActions
(
resourceGroup
.
id
);
actions
=
this
.
menus
.
getResourceGroupContextActions
(
resourceGroup
);
}
this
.
contextMenuService
.
showContextMenu
({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录