dialog(對話框)

跳出系統對話框功能,包含開啓、儲存檔案、提示、警報等。

下面是一個選擇多個檔案的對話框範例:

let result = await eagle.dialog.showOpenDialog({ 
    properties: ['openFile', 'multiSelections'] 
});

方法

showOpenDialog(options)

顯示開啓檔案對話框。

  • options Object

    • title string (可選) - 對話框視窗的標題

    • defaultPath string (可選) - 對話框的預設展示路徑

    • buttonLabel string (可選) - 「確認」按鈕的自定標籤, 當為空時, 將使用預設標籤。

    • filters FileFilter[] (可選)

      • name string

      • extensions string[]

    • properties string[] (可選) - 包含對話框相關屬性。 支援以下屬性值:

      • openFile - 允許選擇檔案

      • openDirectory - 允許選擇資料夾

      • multiSelections- 允許多選。

      • showHiddenFiles- 顯示對話框中的隱藏檔案。

      • createDirectory macOS - 允許你透過對話框的形式新增新的目錄。

      • promptToCreate Windows- 如果輸入的檔案路徑在對話框中不存在, 則提示新增。 這並不是真的在路徑上新增一個檔案,而是允許返回一些不存在的地址交由應用程式去創

    • message string (可選) macOS - 顯示在輸入框上方的消息。

  • 返回 Promise<result: Object>

    • resultObject

      • canceled boolean - 對話框是否被取消

      • filePaths string[] - 使用者選擇的檔案路徑的數組. 如果對話框被取消,這將是一個空的數組。

{
  filters: [
    { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
    { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
    { name: 'Custom File Type', extensions: ['as'] },
    { name: 'All Files', extensions: ['*'] }
  ]
}
let result = await eagle.dialog.showOpenDialog({
    properties: ['openFile', 'openDirectory']
});

備註:此功能與 Electron API 的 dialog.showOpenDialog 功能類似。


showSaveDialog(options)

顯示儲存檔案對話框。

  • options Object

    • title string (可選) - 對話框視窗的標題

    • defaultPath string (可選) - 對話框的預設展示路徑

    • buttonLabel string (可選) - 「確認」按鈕的自定標籤, 當為空時, 將使用預設標籤。

    • filters FileFilter[] (可選)

      • name string

      • extensions string[]

    • properties string[] (可選) - 包含對話框相關屬性。 支援以下屬性值:

      • openDirectory - 允許選擇資料夾

      • showHiddenFiles- 顯示對話框中的隱藏檔案。

      • createDirectory macOS - 允許你透過對話框的形式新增新的目錄。

  • 返回 Promise<result: Object>

    • resultObject

      • canceled boolean - 對話框是否被取消

      • filePath string - 如果對話框被取消,該值為 undefined

{
  filters: [
    { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
    { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
    { name: 'Custom File Type', extensions: ['as'] },
    { name: 'All Files', extensions: ['*'] }
  ]
}
let result = await eagle.dialog.showSaveDialog({
    properties: ['openDirectory']
});

備註:此功能與 Electron API 的 dialog.showSaveDialog 功能類似。


showMessageBox(options)

顯示訊息對話框。

  • optionsObject

    • message string - 對話框主要內容

    • title string (可選) - 對話框標題

    • detail string (可選) - 額外資訊

    • buttons strings[] (可選) - 按鈕文字數組

    • type string (可選) - 可以為 noneinfoerrorquestion 或者 warning

  • 返回 Promise<result: Object>

    • resultObject

      • response Interger - 點擊按鈕的索引

let result = await eagle.dialog.showMessageBox({
    title: "Messagebox title",
    message: "Message from the Plugin process",
    detail: "Ultra message here",
    buttons: ["確定", "取消"],
    type: "info"
});

console.log(result);		// {response: 0}

此功能與 Electron API 的 dialog.showSaveDialog 功能類似。


showErrorBox(title, content)

顯示錯誤訊息的對話框。

  • title string - 顯示在錯誤框中的標題

  • content string - 顯示在錯誤框中的文字內容

  • 返回 Promise<void>

await eagle.dialog.showErrorBox("Error box title", "Error message from the Plugin process");

備註:此功能與 Electron API 的 dialog.showSaveDialog 功能類似。

\

最后更新于