如何处理Visual Studio代码消息框的点击事件?
How to handle click event in Visual Studio Code message box?
根据 API 文档,消息框可以采用第二个参数:一个字符串数组,作为对消息框的操作(通常只有一个关闭 button/action) :
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_window
showInformationMessage(message: string, ...items: string[]): Thenable<string>
所以我尝试了这个:
vscode.window.showInformationMessage('hello world', ['test','taco','cheeseburger'], function(value){
console.log(value + " was clicked");
});
但这似乎不起作用。我像往常一样收到消息框和关闭按钮。但是关闭按钮的左侧似乎是另一个没有文本或标题的按钮。
另一个函数定义是:
showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>
所以我尝试了这样的事情:
let message: vscode.MessageItem = { title: 'testing' };
vscode.window.showInformationMessage('hello', [message], function(value){
console.log(value + " was clicked");
});
但这似乎也不起作用。这方面的文档很少,所以我无法弄清楚。
vscode.window
.showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
.then(selection => {
console.log(selection);
});
或
vscode.window
.showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
.then(selection => {
console.log(selection);
});
两者都会产生如下所示的对话框:
根据 API 文档,消息框可以采用第二个参数:一个字符串数组,作为对消息框的操作(通常只有一个关闭 button/action) :
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_window
showInformationMessage(message: string, ...items: string[]): Thenable<string>
所以我尝试了这个:
vscode.window.showInformationMessage('hello world', ['test','taco','cheeseburger'], function(value){
console.log(value + " was clicked");
});
但这似乎不起作用。我像往常一样收到消息框和关闭按钮。但是关闭按钮的左侧似乎是另一个没有文本或标题的按钮。
另一个函数定义是:
showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>
所以我尝试了这样的事情:
let message: vscode.MessageItem = { title: 'testing' };
vscode.window.showInformationMessage('hello', [message], function(value){
console.log(value + " was clicked");
});
但这似乎也不起作用。这方面的文档很少,所以我无法弄清楚。
vscode.window
.showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
.then(selection => {
console.log(selection);
});
或
vscode.window
.showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
.then(selection => {
console.log(selection);
});
两者都会产生如下所示的对话框: