Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 732
Jake Wilson Avatar asked Sep 12 '16 02:09

Jake Wilson


People also ask

How does VS Code trigger IntelliSense?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.)

What is click event in Visual Basic?

The Click event is raised every time a control is double-clicked. For example, if you have event handlers for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called.


1 Answers

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:

like image 168
Markus Liebschner Avatar answered Sep 23 '22 03:09

Markus Liebschner