dialog(對話框)
跳出系統對話框功能,包含開啓、儲存檔案、提示、警報等。
下面是一個選擇多個檔案的對話框範例:
let result = await eagle.dialog.showOpenDialog({
properties: ['openFile', 'multiSelections']
});
方法
showOpenDialog(options)
顯示開啓檔案對話框。
options
Objecttitle
string (可選) - 對話框視窗的標題defaultPath
string (可選) - 對話框的預設展示路徑buttonLabel
string (可選) - 「確認」按鈕的自定標籤, 當為空時, 將使用預設標籤。filters
FileFilter[] (可選)name
stringextensions
string[]
properties
string[] (可選) - 包含對話框相關屬性。 支援以下屬性值:openFile
- 允許選擇檔案openDirectory
- 允許選擇資料夾multiSelections
- 允許多選。showHiddenFiles
- 顯示對話框中的隱藏檔案。createDirectory
macOS
- 允許你透過對話框的形式新增新的目錄。promptToCreate
Windows
- 如果輸入的檔案路徑在對話框中不存在, 則提示新增。 這並不是真的在路徑上新增一個檔案,而是允許返回一些不存在的地址交由應用程式去創
message
string (可選)macOS
- 顯示在輸入框上方的消息。
返回
Promise<result: Object>
result
Objectcanceled
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']
});
showSaveDialog(options)
顯示儲存檔案對話框。
options
Objecttitle
string (可選) - 對話框視窗的標題defaultPath
string (可選) - 對話框的預設展示路徑buttonLabel
string (可選) - 「確認」按鈕的自定標籤, 當為空時, 將使用預設標籤。filters
FileFilter[] (可選)name
stringextensions
string[]
properties
string[] (可選) - 包含對話框相關屬性。 支援以下屬性值:openDirectory
- 允許選擇資料夾showHiddenFiles
- 顯示對話框中的隱藏檔案。createDirectory
macOS
- 允許你透過對話框的形式新增新的目錄。
返回
Promise<result: Object>
result
Objectcanceled
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']
});
showMessageBox(options)
顯示訊息對話框。
options
Objectmessage
string - 對話框主要內容title
string (可選) - 對話框標題detail
string (可選) - 額外資訊buttons
strings[] (可選) - 按鈕文字數組type
string (可選) - 可以為none
、info
、error
、question
或者warning
返回
Promise<result: Object>
result
Objectresponse
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}
showErrorBox(title, content)
顯示錯誤訊息的對話框。
title
string - 顯示在錯誤框中的標題content
string - 顯示在錯誤框中的文字內容返回
Promise<void>
await eagle.dialog.showErrorBox("Error box title", "Error message from the Plugin process");
Last updated