Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
7a9470db
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,发现更多精彩内容 >>
提交
7a9470db
编写于
2月 03, 2017
作者:
J
João Moreno
提交者:
GitHub
2月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19717 from joaomoreno/modal-message-api
Implement modal message API
上级
5aa30a0d
ee0316de
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
228 addition
and
28 deletion
+228
-28
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+86
-0
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+7
-7
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+1
-1
src/vs/workbench/api/node/extHostMessageService.ts
src/vs/workbench/api/node/extHostMessageService.ts
+23
-9
src/vs/workbench/api/node/mainThreadMessageService.ts
src/vs/workbench/api/node/mainThreadMessageService.ts
+38
-6
src/vs/workbench/test/node/api/extHostMessagerService.test.ts
...vs/workbench/test/node/api/extHostMessagerService.test.ts
+73
-5
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
7a9470db
...
...
@@ -1411,6 +1411,21 @@ declare module 'vscode' {
isCloseAffordance
?:
boolean
;
}
/**
* Options to configure the behavior of the message.
*
* @see [showInformationMessage](#window.showInformationMessage)
* @see [showWarningMessage](#window.showWarningMessage)
* @see [showErrorMessage](#window.showErrorMessage)
*/
export
interface
MessageOptions
{
/**
* Indicates that this message should be modal.
*/
modal
?:
boolean
;
}
/**
* Options to configure the behavior of the input box UI.
*/
...
...
@@ -3586,6 +3601,17 @@ declare module 'vscode' {
*/
export
function
showInformationMessage
(
message
:
string
,
...
items
:
string
[]):
Thenable
<
string
|
undefined
>
;
/**
* Show an information message to users. Optionally provide an array of items which will be presented as
* clickable buttons.
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
export
function
showInformationMessage
(
message
:
string
,
options
:
MessageOptions
,
...
items
:
string
[]):
Thenable
<
string
|
undefined
>
;
/**
* Show an information message.
*
...
...
@@ -3597,6 +3623,18 @@ declare module 'vscode' {
*/
export
function
showInformationMessage
<
T
extends
MessageItem
>
(
message
:
string
,
...
items
:
T
[]):
Thenable
<
T
|
undefined
>
;
/**
* Show an information message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
export
function
showInformationMessage
<
T
extends
MessageItem
>
(
message
:
string
,
options
:
MessageOptions
,
...
items
:
T
[]):
Thenable
<
T
|
undefined
>
;
/**
* Show a warning message.
*
...
...
@@ -3608,6 +3646,18 @@ declare module 'vscode' {
*/
export
function
showWarningMessage
(
message
:
string
,
...
items
:
string
[]):
Thenable
<
string
|
undefined
>
;
/**
* Show a warning message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
export
function
showWarningMessage
(
message
:
string
,
options
:
MessageOptions
,
...
items
:
string
[]):
Thenable
<
string
|
undefined
>
;
/**
* Show a warning message.
*
...
...
@@ -3619,6 +3669,18 @@ declare module 'vscode' {
*/
export
function
showWarningMessage
<
T
extends
MessageItem
>
(
message
:
string
,
...
items
:
T
[]):
Thenable
<
T
|
undefined
>
;
/**
* Show a warning message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
export
function
showWarningMessage
<
T
extends
MessageItem
>
(
message
:
string
,
options
:
MessageOptions
,
...
items
:
T
[]):
Thenable
<
T
|
undefined
>
;
/**
* Show an error message.
*
...
...
@@ -3630,6 +3692,18 @@ declare module 'vscode' {
*/
export
function
showErrorMessage
(
message
:
string
,
...
items
:
string
[]):
Thenable
<
string
|
undefined
>
;
/**
* Show an error message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
export
function
showErrorMessage
(
message
:
string
,
options
:
MessageOptions
,
...
items
:
string
[]):
Thenable
<
string
|
undefined
>
;
/**
* Show an error message.
*
...
...
@@ -3641,6 +3715,18 @@ declare module 'vscode' {
*/
export
function
showErrorMessage
<
T
extends
MessageItem
>
(
message
:
string
,
...
items
:
T
[]):
Thenable
<
T
|
undefined
>
;
/**
* Show an error message.
*
* @see [showInformationMessage](#window.showInformationMessage)
*
* @param message The message to show.
* @param options Configures the behaviour of the message.
* @param items A set of items that will be rendered as actions in the message.
* @return A thenable that resolves to the selected item or `undefined` when being dismissed.
*/
export
function
showErrorMessage
<
T
extends
MessageItem
>
(
message
:
string
,
options
:
MessageOptions
,
...
items
:
T
[]):
Thenable
<
T
|
undefined
>
;
/**
* Shows a selection list.
*
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
7a9470db
...
...
@@ -291,14 +291,14 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
onDidCloseTerminal
(
listener
,
thisArg
?,
disposables
?)
{
return
extHostTerminalService
.
onDidCloseTerminal
(
listener
,
thisArg
,
disposables
);
},
showInformationMessage
(
message
,
...
items
)
{
return
extHostMessageService
.
showMessage
(
Severity
.
Info
,
message
,
items
);
showInformationMessage
(
message
,
first
,
...
rest
)
{
return
extHostMessageService
.
showMessage
(
Severity
.
Info
,
message
,
first
,
rest
);
},
showWarningMessage
(
message
,
...
items
)
{
return
extHostMessageService
.
showMessage
(
Severity
.
Warning
,
message
,
items
);
showWarningMessage
(
message
,
first
,
...
rest
)
{
return
extHostMessageService
.
showMessage
(
Severity
.
Warning
,
message
,
first
,
rest
);
},
showErrorMessage
(
message
,
...
items
)
{
return
extHostMessageService
.
showMessage
(
Severity
.
Error
,
message
,
items
);
showErrorMessage
(
message
,
first
,
...
rest
)
{
return
extHostMessageService
.
showMessage
(
Severity
.
Error
,
message
,
first
,
rest
);
},
showQuickPick
(
items
:
any
,
options
:
vscode
.
QuickPickOptions
,
token
?:
vscode
.
CancellationToken
)
{
return
extHostQuickOpen
.
showQuickPick
(
items
,
options
,
token
);
...
...
@@ -329,7 +329,7 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
},
// proposed API
sampleFunction
:
proposedApiFunction
(
extension
,
()
=>
{
return
extHostMessageService
.
showMessage
(
Severity
.
Info
,
'
Hello Proposed Api!
'
,
[]);
return
extHostMessageService
.
showMessage
(
Severity
.
Info
,
'
Hello Proposed Api!
'
,
{},
[]);
}),
registerTreeExplorerNodeProvider
:
proposedApiFunction
(
extension
,
(
providerId
:
string
,
provider
:
vscode
.
TreeExplorerNodeProvider
<
any
>
)
=>
{
return
extHostExplorers
.
registerTreeExplorerNodeProvider
(
providerId
,
provider
);
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
7a9470db
...
...
@@ -177,7 +177,7 @@ export abstract class MainThreadLanguagesShape {
}
export
abstract
class
MainThreadMessageServiceShape
{
$showMessage
(
severity
:
Severity
,
message
:
string
,
commands
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]):
Thenable
<
number
>
{
throw
ni
();
}
$showMessage
(
severity
:
Severity
,
message
:
string
,
options
:
vscode
.
MessageOptions
,
commands
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]):
Thenable
<
number
>
{
throw
ni
();
}
}
export
abstract
class
MainThreadOutputServiceShape
{
...
...
src/vs/workbench/api/node/extHostMessageService.ts
浏览文件 @
7a9470db
...
...
@@ -9,6 +9,20 @@ import Severity from 'vs/base/common/severity';
import
vscode
=
require
(
'
vscode
'
);
import
{
MainContext
,
MainThreadMessageServiceShape
}
from
'
./extHost.protocol
'
;
const
emptyMessageOptions
:
vscode
.
MessageOptions
=
Object
.
create
(
null
);
function
isMessageItem
<
T
>
(
item
:
any
):
item
is
vscode
.
MessageItem
{
return
item
&&
item
.
title
;
}
function
parseMessageArguments
(
first
:
vscode
.
MessageOptions
|
string
|
vscode
.
MessageItem
,
rest
:
(
string
|
vscode
.
MessageItem
)[]):
{
options
:
vscode
.
MessageOptions
;
items
:
(
string
|
vscode
.
MessageItem
)[];
}
{
if
(
typeof
first
===
'
string
'
||
isMessageItem
(
first
))
{
return
{
options
:
emptyMessageOptions
,
items
:
[
first
,
...
rest
]
};
}
else
{
return
{
options
:
first
||
emptyMessageOptions
,
items
:
rest
};
}
}
export
class
ExtHostMessageService
{
private
_proxy
:
MainThreadMessageServiceShape
;
...
...
@@ -17,25 +31,25 @@ export class ExtHostMessageService {
this
.
_proxy
=
threadService
.
get
(
MainContext
.
MainThreadMessageService
);
}
showMessage
(
severity
:
Severity
,
message
:
string
,
commands
:
(
string
|
vscode
.
MessageItem
)[]):
Thenable
<
string
|
vscode
.
MessageItem
>
{
const
item
s
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]
=
[];
showMessage
(
severity
:
Severity
,
message
:
string
,
optionsOrFirstItem
:
vscode
.
MessageOptions
|
string
|
vscode
.
MessageItem
,
rest
:
(
string
|
vscode
.
MessageItem
)[]):
Thenable
<
string
|
vscode
.
MessageItem
>
{
const
{
options
,
items
}
=
parseMessageArguments
(
optionsOrFirstItem
,
rest
);
const
command
s
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]
=
[];
for
(
let
handle
=
0
;
handle
<
command
s
.
length
;
handle
++
)
{
let
command
=
command
s
[
handle
];
for
(
let
handle
=
0
;
handle
<
item
s
.
length
;
handle
++
)
{
let
command
=
item
s
[
handle
];
if
(
typeof
command
===
'
string
'
)
{
item
s
.
push
({
title
:
command
,
handle
,
isCloseAffordance
:
false
});
command
s
.
push
({
title
:
command
,
handle
,
isCloseAffordance
:
false
});
}
else
if
(
typeof
command
===
'
object
'
)
{
let
{
title
,
isCloseAffordance
}
=
command
;
item
s
.
push
({
title
,
isCloseAffordance
,
handle
});
command
s
.
push
({
title
,
isCloseAffordance
,
handle
});
}
else
{
console
.
warn
(
'
Invalid message item:
'
,
command
);
}
}
return
this
.
_proxy
.
$showMessage
(
severity
,
message
,
item
s
).
then
(
handle
=>
{
return
this
.
_proxy
.
$showMessage
(
severity
,
message
,
options
,
command
s
).
then
(
handle
=>
{
if
(
typeof
handle
===
'
number
'
)
{
return
command
s
[
handle
];
return
item
s
[
handle
];
}
return
undefined
;
});
...
...
src/vs/workbench/api/node/mainThreadMessageService.ts
浏览文件 @
7a9470db
...
...
@@ -5,22 +5,31 @@
'
use strict
'
;
import
nls
=
require
(
'
vs/nls
'
);
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
IMessageService
,
IChoiceService
}
from
'
vs/platform/message/common/message
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
TPromise
as
Promise
}
from
'
vs/base/common/winjs.base
'
;
import
{
MainThreadMessageServiceShape
}
from
'
./extHost.protocol
'
;
import
*
as
vscode
from
'
vscode
'
;
export
class
MainThreadMessageService
extends
MainThreadMessageServiceShape
{
private
_messageService
:
IMessageService
;
constructor
(
@
IMessageService
messageService
:
IMessageService
)
{
constructor
(
@
IMessageService
private
_messageService
:
IMessageService
,
@
IChoiceService
private
_choiceService
:
IChoiceService
)
{
super
();
this
.
_messageService
=
messageService
;
}
$showMessage
(
severity
:
Severity
,
message
:
string
,
commands
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]):
Thenable
<
number
>
{
$showMessage
(
severity
:
Severity
,
message
:
string
,
options
:
vscode
.
MessageOptions
,
commands
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]):
Thenable
<
number
>
{
if
(
options
.
modal
)
{
return
this
.
showModalMessage
(
severity
,
message
,
commands
);
}
else
{
return
this
.
showMessage
(
severity
,
message
,
commands
);
}
}
private
showMessage
(
severity
:
Severity
,
message
:
string
,
commands
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]):
Thenable
<
number
>
{
return
new
Promise
<
number
>
(
resolve
=>
{
...
...
@@ -58,4 +67,27 @@ export class MainThreadMessageService extends MainThreadMessageServiceShape {
});
});
}
private
showModalMessage
(
severity
:
Severity
,
message
:
string
,
commands
:
{
title
:
string
;
isCloseAffordance
:
boolean
;
handle
:
number
;
}[]):
Thenable
<
number
>
{
let
hasCloseAffordance
=
false
;
const
options
=
commands
.
map
((
command
,
index
)
=>
{
if
(
command
.
isCloseAffordance
===
true
)
{
hasCloseAffordance
=
true
;
}
return
command
.
title
;
});
if
(
!
hasCloseAffordance
)
{
if
(
options
.
length
>
0
)
{
options
.
push
(
nls
.
localize
(
'
cancel
'
,
"
Cancel
"
));
}
else
{
options
.
push
(
nls
.
localize
(
'
ok
'
,
"
OK
"
));
}
}
return
this
.
_choiceService
.
choose
(
severity
,
message
,
options
,
true
)
.
then
(
result
=>
result
===
commands
.
length
?
undefined
:
commands
[
result
].
handle
);
}
}
src/vs/workbench/test/node/api/extHostMessagerService.test.ts
浏览文件 @
7a9470db
...
...
@@ -8,8 +8,9 @@
import
*
as
assert
from
'
assert
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
MainThreadMessageService
}
from
'
vs/workbench/api/node/mainThreadMessageService
'
;
import
{
TPromise
as
Promise
}
from
'
vs/base/common/winjs.base
'
;
suite
(
'
ExtHostMessageService
'
,
function
()
{
suite
(
'
`ExtHostMessageService`
'
,
function
()
{
test
(
'
propagte handle on select
'
,
function
()
{
...
...
@@ -19,9 +20,13 @@ suite('ExtHostMessageService', function () {
setImmediate
(()
=>
m
.
actions
[
0
].
run
());
return
()
=>
{
};
}
},
<
any
>
{
choose
()
{
throw
new
Error
(
'
not implemented
'
);
}
});
return
service
.
$showMessage
(
1
,
'
h
'
,
[{
handle
:
42
,
title
:
'
a thing
'
,
isCloseAffordance
:
true
}]).
then
(
handle
=>
{
return
service
.
$showMessage
(
1
,
'
h
'
,
{},
[{
handle
:
42
,
title
:
'
a thing
'
,
isCloseAffordance
:
true
}]).
then
(
handle
=>
{
assert
.
equal
(
handle
,
42
);
});
});
...
...
@@ -33,17 +38,21 @@ suite('ExtHostMessageService', function () {
show
(
sev
:
number
,
m
:
{
message
;
actions
:
Action
[]
})
{
actions
=
m
.
actions
;
}
},
<
any
>
{
choose
()
{
throw
new
Error
(
'
not implemented
'
);
}
});
// default close action
service
.
$showMessage
(
1
,
''
,
[{
title
:
'
a thing
'
,
isCloseAffordance
:
false
,
handle
:
0
}]);
service
.
$showMessage
(
1
,
''
,
{},
[{
title
:
'
a thing
'
,
isCloseAffordance
:
false
,
handle
:
0
}]);
assert
.
equal
(
actions
.
length
,
2
);
let
[
first
,
second
]
=
actions
;
assert
.
equal
(
first
.
label
,
'
a thing
'
);
assert
.
equal
(
second
.
label
,
'
Close
'
);
// override close action
service
.
$showMessage
(
1
,
''
,
[{
title
:
'
a thing
'
,
isCloseAffordance
:
true
,
handle
:
0
}]);
service
.
$showMessage
(
1
,
''
,
{},
[{
title
:
'
a thing
'
,
isCloseAffordance
:
true
,
handle
:
0
}]);
assert
.
equal
(
actions
.
length
,
1
);
first
=
actions
[
0
];
assert
.
equal
(
first
.
label
,
'
a thing
'
);
...
...
@@ -61,12 +70,71 @@ suite('ExtHostMessageService', function () {
c
+=
1
;
};
}
},
<
any
>
{
choose
()
{
throw
new
Error
(
'
not implemented
'
);
}
});
service
.
$showMessage
(
1
,
''
,
[{
title
:
'
a thing
'
,
isCloseAffordance
:
true
,
handle
:
0
}]);
service
.
$showMessage
(
1
,
''
,
{},
[{
title
:
'
a thing
'
,
isCloseAffordance
:
true
,
handle
:
0
}]);
assert
.
equal
(
actions
.
length
,
1
);
actions
[
0
].
run
();
assert
.
equal
(
c
,
1
);
});
suite
(
'
modal
'
,
()
=>
{
test
(
'
calls choice service
'
,
()
=>
{
const
service
=
new
MainThreadMessageService
(
<
any
>
{
show
(
sev
:
number
,
m
:
{
message
;
actions
:
Action
[]
})
{
throw
new
Error
(
'
not implemented
'
);
}
},
<
any
>
{
choose
(
severity
,
message
,
options
,
modal
)
{
assert
.
equal
(
severity
,
1
);
assert
.
equal
(
message
,
'
h
'
);
assert
.
equal
(
options
.
length
,
2
);
assert
.
equal
(
options
[
1
],
'
Cancel
'
);
return
Promise
.
as
(
0
);
}
});
return
service
.
$showMessage
(
1
,
'
h
'
,
{
modal
:
true
},
[{
handle
:
42
,
title
:
'
a thing
'
,
isCloseAffordance
:
false
}]).
then
(
handle
=>
{
assert
.
equal
(
handle
,
42
);
});
});
test
(
'
returns undefined when cancelled
'
,
()
=>
{
const
service
=
new
MainThreadMessageService
(
<
any
>
{
show
(
sev
:
number
,
m
:
{
message
;
actions
:
Action
[]
})
{
throw
new
Error
(
'
not implemented
'
);
}
},
<
any
>
{
choose
(
severity
,
message
,
options
,
modal
)
{
return
Promise
.
as
(
1
);
}
});
return
service
.
$showMessage
(
1
,
'
h
'
,
{
modal
:
true
},
[{
handle
:
42
,
title
:
'
a thing
'
,
isCloseAffordance
:
false
}]).
then
(
handle
=>
{
assert
.
equal
(
handle
,
undefined
);
});
});
test
(
'
hides Cancel button when not needed
'
,
()
=>
{
const
service
=
new
MainThreadMessageService
(
<
any
>
{
show
(
sev
:
number
,
m
:
{
message
;
actions
:
Action
[]
})
{
throw
new
Error
(
'
not implemented
'
);
}
},
<
any
>
{
choose
(
severity
,
message
,
options
,
modal
)
{
assert
.
equal
(
options
.
length
,
1
);
return
Promise
.
as
(
0
);
}
});
return
service
.
$showMessage
(
1
,
'
h
'
,
{
modal
:
true
},
[{
handle
:
42
,
title
:
'
a thing
'
,
isCloseAffordance
:
true
}]).
then
(
handle
=>
{
assert
.
equal
(
handle
,
42
);
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录