如何处理 Visual Studio Code 消息框中的单击事件? [英] How to handle click event in Visual Studio Code message box?

查看:44
本文介绍了如何处理 Visual Studio Code 消息框中的单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆