如何处理 Visual Studio Code 消息框中的单击事件? [英] How to handle click event in Visual Studio Code message box?
问题描述
根据 API 文档,消息框可以接受第二个参数:作为消息框操作的字符串数组(通常只有一个关闭按钮/操作):
According to the API docs, a Message box can take a second argument: an array of strings which act as actions on the message box (which normally just has a single close 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");
});
但这似乎不起作用.我像往常一样收到消息框和关闭按钮.但是在关闭按钮的左侧似乎是另一个没有文本或标题的按钮.
But this doesn't seem to work. I get the message box along with a Close button like normal. But then to the left of the close button appears to be another single button with no text or title.
另一个函数定义是:
showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>
所以我尝试了这样的事情:
So I tried something like this:
let message: vscode.MessageItem = { title: 'testing' };
vscode.window.showInformationMessage('hello', [message], function(value){
console.log(value + " was clicked");
});
但这似乎也不起作用.这方面的文档很少,所以我无法弄清楚.
But that doesn't seem to work either. There is a scarce amount of documentation on this so I cannot figure it out.
推荐答案
vscode.window
.showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
.then(selection => {
console.log(selection);
});
或
vscode.window
.showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
.then(selection => {
console.log(selection);
});
两者都会产生如下所示的对话框:
Both result in a dialog that looks like this:
这篇关于如何处理 Visual Studio Code 消息框中的单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!