How to handle click event in Visual Studio Code message box?

和自甴很熟 提交于 2019-12-07 18:02:35

问题


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>

So I tried this:

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.

Another function definition is:

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.


回答1:


vscode.window
  .showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
  .then(selection => {
    console.log(selection);
  });

or

vscode.window
  .showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
  .then(selection => {
    console.log(selection);
  });

Both result in a dialog that looks like this:



来源:https://stackoverflow.com/questions/39442735/how-to-handle-click-event-in-visual-studio-code-message-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!