siyumi_amarasinghe
siyumi_amarasinghe

Reputation: 293

How to make a click event in 'vscode.window.showInformationMessage'

I have a Information Box which contains a button, So when I click the button I need it to navigate to a web site in the button click event.

I was able to add a button inside Information box but now I don't have a clear understanding about how to make the button click event in 'vscode.window .showInformationMessage' since I'm new to typescript and extension development.So can anyone please guide me with this?

vscode.window
        .showInformationMessage("Click for more Info","Go to Help")
        .then(selection => {
        console.log(selection); 
        });

This prints 'Go to Help' in the debug console. this is just something I tried.But the expected result is when I click the Go to Help button it should navigate to specific url(ex: https://www.merriam-webster.com/dictionary/hep). Can anyone guide me to get the expected output since I don't have any idea of how to get the result.

Upvotes: 1

Views: 2991

Answers (1)

Gama11
Gama11

Reputation: 34158

You don't need a "click event", simply check if the option has been selected in the callback:

let GoToHelp = 'Go to Help';
vscode.window.showInformationMessage('Click for more Info', GoToHelp)
    .then(selection => {
      if (selection === GoToHelp) {
        vscode.env.openExternal(vscode.Uri.parse(
            'https://www.merriam-webster.com/dictionary/hep'));
      }
    });

Upvotes: 5

Related Questions