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

▼魔方 西西 提交于 2019-12-31 05:03:07

问题


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.


回答1:


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'));
      }
    });


来源:https://stackoverflow.com/questions/57416105/how-to-make-a-click-event-in-vscode-window-showinformationmessage

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