Dialog

对话框弹窗,当在插件进程使用的时候,弹出普通弹窗,如果在面板进程使用,则会弹出模态弹窗

通用接口说明

MessageDialogOptions

NameTypeDescription
title?string标题,在部分可能会被隐藏
detail?string详细描述
buttons?string array在弹窗上新增一个或者多个按钮
default?number打开弹窗时默认选中的按钮
cancel?number当弹窗关闭时,默认触发的按钮
checkboxLabel?number在弹窗上附加一个可选项
checkboxChecked?number弹窗上附加的可选项默认值

SelectDialogOptions

NameTypeDescription
title?string标题,在部分可能会被隐藏
button?string弹窗按钮上的文字
path?string默认打开位置
type?directory</td><td>file是选择文件夹还是文件
multi?boolean是否可以多选
filters?object array过滤弹窗可选择的对象
extensions?string array设置可选择的文件扩展名,例如 ‘png’

SaveDialogReturnValue

NameTypeDescription
canceledboolean用户是否取消
filePathstring选择的文件路径

OpenDialogReturnValue

NameTypeDescription
canceledboolean用户是否取消
filePathsstring array选择的文件路径

filters 示例

  1. {
  2. filters: [
  3. { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
  4. { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
  5. { name: 'Custom File Type', extensions: ['as'] },
  6. { name: 'All Files', extensions: ['*'] }
  7. ]
  8. }

函数

info

info(message: string, options?: MessageDialogOptions): Promise<MessageBoxReturnValue>

普通信息弹窗

请求参数

NameTypeDescription
messagestring显示的消息
options?MessageDialogOptions信息弹窗可选参数

返回结果

Promise<MessageBoxReturnValue>

  1. const result = await Editor.Dialog.info('Dialog Message', {
  2. buttons: ['confirm', 'cancel'],
  3. title: 'Dialog Title',
  4. });
  5. if (0 == result.response) {
  6. // ... confirm event
  7. } else {
  8. // ... cancel event
  9. }

warn

warn(message: string, options?: MessageDialogOptions): Promise<MessageBoxReturnValue>

警告弹窗

请求参数

NameTypeDescription
messagestring警告信息
options?MessageDialogOptions警告弹窗可选参数

返回结果

Promise<MessageBoxReturnValue>

  1. await Editor.Dialog.warn('Warn Message');

error

error(message: string, options?: MessageDialogOptions): Promise<MessageBoxReturnValue>

错误弹窗

请求参数

NameTypeDescription
messagestring错误信息
options?MessageDialogOptions错误弹窗可选参数

返回结果

Promise<MessageBoxReturnValue>

  1. await Editor.Dialog.error('error content', {
  2. title: 'options-title'
  3. });

save

save(options?: MessageDialogOptions): Promise<SaveDialogReturnValue>

保存文件弹窗,保存文件时只能选择文件夹,且无法多选,相关参数不会生效

请求参数

NameTypeDescription
options?SelectDialogOptions保存文件窗口参数

返回结果

Promise<SaveDialogReturnValue>

  1. const result = await Editor.Dialog.save({
  2. path: Editor.Project.path,
  3. title: 'Save Title',
  4. filters: [
  5. { name: 'Package', extensions: ['zip'] },
  6. ],
  7. });
  8. if (!result.filePath) {
  9. return;
  10. }

select

select(options?: SelectDialogOptions): Promise<OpenDialogReturnValue>

选择文件弹窗

请求参数

NameTypeDescription
options?SelectDialogOptions选择弹窗参数

返回结果

Promise<OpenDialogReturnValue>

  1. const result = await Editor.Dialog.select({
  2. title: 'Select Title',
  3. path: aEditor.Project.path,
  4. filters: [{ name: 'Package', extensions: ['zip'] }],
  5. });
  6. if (result.filePaths && result.filePaths[0]) {
  7. return result.filePaths[0];
  8. } else {
  9. return '';
  10. }

更多说明请参考 Electron 官方文档