如何在Visual Studio Code消息框中处理click事件?

问题描述 投票:2回答:1

根据API文档,消息框可以采用第二个参数:一个字符串数组,它充当消息框上的动作(通常只有一个关闭按钮/动作):

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

但这似乎不起作用。我得到了消息框以及正常的关闭按钮。但是,关闭按钮的左侧似乎是另一个没有文字或标题的单个按钮。

另一个函数定义是:

showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>

所以我尝试过这样的事情:

let message: vscode.MessageItem = { title: 'testing' };
vscode.window.showInformationMessage('hello', [message], function(value){
  console.log(value + " was clicked");
});

但这似乎也不起作用。关于这方面的文档很少,所以我无法弄明白。

visual-studio-code vscode-extensions
1个回答
7
投票
vscode.window
  .showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
  .then(selection => {
    console.log(selection);
  });

要么

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

两者都会产生如下所示的对话框:

© www.soinside.com 2019 - 2024. All rights reserved.