5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 16:20:53 +08:00
wails/website/i18n/ja/docusaurus-plugin-content-docs/version-v2.1.0/reference/runtime/dialog.mdx
Lea Anthony a5fba5b218
Release/v2.1.0 (#1988)
* Add changelog. Fix zoom docs. Add Info.dev.plist info

* Update build assets README.md

* Update changelog

* actions/checkout@v2 => v3

* Docs
2022-10-18 07:21:07 +11:00

305 lines
11 KiB
Plaintext

---
sidebar_position: 5
---
# ダイアログ
ランタイムでは、ファイルセレクターやメッセージボックスといったネイティブダイアログへのアクセスを提供しています。
:::info Javascript
現在、Javascriptランタイムではダイアログをサポートしていません。
:::
### OpenDirectoryDialog
ユーザにディレクトリの選択を求めるダイアログを開きます。 [OpenDialogOptions](#opendialogoptions)を使用してカスタマイズできます。
Go: `OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error)`
返り値: 選択されたディレクトリ(キャンセルされた場合は空) またはエラー
### OpenFileDialog
ユーザにファイルの選択を求めるダイアログを開きます。 [OpenDialogOptions](#opendialogoptions)を使用してカスタマイズできます。
Go: `OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error)`
返り値: 選択されたファイル(キャンセルされた場合は空) またはエラー
### OpenMultipleFilesDialog
ユーザに複数ファイルの選択を求めるダイアログを開きます。 [OpenDialogOptions](#opendialogoptions)を使用してカスタマイズできます。
Go: `OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error)`
返り値: 選択された複数ファイル(キャンセルされた場合はnil) またはエラー
### SaveFileDialog
保存の目的でユーザにファイル名を入力選択させるダイアログを開きます。 [SaveDialogOptions](#savedialogoptions)を使用してカスタマイズできます。
Go: `SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error)`
返り値: 入力選択されたファイル(キャンセルされた場合は空) またはエラー
### MessageDialog
メッセージダイアログを使用してメッセージを表示します。 [MessageDialogOptions](#messagedialogoptions)を使用してカスタマイズできます。
Go: `MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error)`
返り値: 選択されたボタンのテキストまたはエラー
## オプション
### OpenDialogOptions
```go
type OpenDialogOptions struct {
DefaultDirectory string
DefaultFilename string
Title string
Filters []FileFilter
ShowHiddenFiles bool
CanCreateDirectories bool
ResolvesAliases bool
TreatPackagesAsDirectories bool
}
```
| Field | Description | Win | Mac | Lin |
| -------------------------- | ------------------------- | --- | --- | --- |
| DefaultDirectory | ダイアログが開かれたときに初期表示するディレクトリ | ✅ | ✅ | ✅ |
| DefaultFilename | デフォルトファイル名 | ✅ | ✅ | ✅ |
| Title | ダイアログのタイトル | ✅ | ✅ | ✅ |
| [Filters](#filefilter) | ファイルフィルタのリスト | ✅ | ✅ | ✅ |
| ShowHiddenFiles | システムの隠しファイルを表示 | | ✅ | ✅ |
| CanCreateDirectories | ユーザによるディレクトリの作成を許可する | | ✅ | |
| ResolvesAliases | エイリアスではなくファイルパスを返す | | ✅ | |
| TreatPackagesAsDirectories | パッケージへのナビゲーションを許可 | | ✅ | |
### SaveDialogOptions
```go
type SaveDialogOptions struct {
DefaultDirectory string
DefaultFilename string
Title string
Filters []FileFilter
ShowHiddenFiles bool
CanCreateDirectories bool
TreatPackagesAsDirectories bool
}
```
| Field | Description | Win | Mac | Lin |
| -------------------------- | ------------------------- | --- | --- | --- |
| DefaultDirectory | ダイアログが開かれたときに初期表示するディレクトリ | ✅ | ✅ | ✅ |
| DefaultFilename | デフォルトファイル名 | ✅ | ✅ | ✅ |
| Title | ダイアログのタイトル | ✅ | ✅ | ✅ |
| [Filters](#filefilter) | ファイルフィルタのリスト | ✅ | ✅ | ✅ |
| ShowHiddenFiles | システムの隠しファイルを表示 | | ✅ | ✅ |
| CanCreateDirectories | ユーザによるディレクトリの作成を許可する | | ✅ | |
| TreatPackagesAsDirectories | パッケージへのナビゲーションを許可 | | ✅ | |
### MessageDialogOptions
```go
type MessageDialogOptions struct {
Type DialogType
Title string
Message string
Buttons []string
DefaultButton string
CancelButton string
}
```
| Field | Description | Win | Mac | Lin |
| ------------- | ------------------------------------------------- | -------------- | --- | --- |
| Type | メッセージダイアログの種類 (質問、情報など) | ✅ | ✅ | ✅ |
| Title | ダイアログのタイトル | ✅ | ✅ | ✅ |
| Message | ユーザに表示するメッセージ | ✅ | ✅ | ✅ |
| Buttons | ボタンテキストのリスト | | ✅ | |
| DefaultButton | 指定されたテキストのボタンをデフォルトボタンとして扱う。 Bound to `return`. | ✅[*](#windows) | ✅ | |
| CancelButton | 指定されたテキストのボタンをキャンセルボタンとして扱う。 `escape`キーにバインドされます。 | | ✅ | |
#### Windows
Windowsでは、ボタンのカスタマイズができない標準ダイアログタイプがあります。 The value returned will be one of: "Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "Try Again" or "Continue".
For Question dialogs, the default button is "Yes" and the cancel button is "No". This can be changed by setting the `DefaultButton` value to `"No"`.
Example:
```go
result, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Question",
Message: "Do you want to continue?",
DefaultButton: "No",
})
```
#### Linux
Linux has standard dialog types in which the buttons are not customisable. The value returned will be one of: "Ok", "Cancel", "Yes", "No"
#### Mac
A message dialog on Mac may specify up to 4 buttons. If no `DefaultButton` or `CancelButton` is given, the first button is considered default and is bound to the `return` key.
For the following code:
```go
selection, err := runtime.MessageDialog(b.ctx, runtime.MessageDialogOptions{
Title: "It's your turn!",
Message: "Select a number",
Buttons: []string{"one", "two", "three", "four"},
})
```
1番目のボタンがデフォルトになります:
```mdx-code-block
<div class="text--center">
<img
src={require("@site/static/img/runtime/dialog_no_defaults.png").default}
width="30%"
class="screenshot"
/>
</div>
<br />
```
And if we specify `DefaultButton` to be "two":
```go
selection, err := runtime.MessageDialog(b.ctx, runtime.MessageDialogOptions{
Title: "It's your turn!",
Message: "Select a number",
Buttons: []string{"one", "two", "three", "four"},
DefaultButton: "two",
})
```
the second button is shown as default. When `return` is pressed, the value "two" is returned.
```mdx-code-block
<div class="text--center">
<img
src={require("@site/static/img/runtime/dialog_default_button.png").default}
width="30%"
class="screenshot"
/>
</div>
<br />
```
If we now specify `CancelButton` to be "three":
```go
selection, err := runtime.MessageDialog(b.ctx, runtime.MessageDialogOptions{
Title: "It's your turn!",
Message: "Select a number",
Buttons: []string{"one", "two", "three", "four"},
DefaultButton: "two",
CancelButton: "three",
})
```
the button with "three" is shown at the bottom of the dialog. When `escape` is pressed, the value "three" is returned:
```mdx-code-block
<div class="text--center">
<img
src={require("@site/static/img/runtime/dialog_default_cancel.png").default}
width="30%"
class="screenshot"
/>
</div>
<br />
<br />
<br />
```
#### DialogType
```go
const (
InfoDialog DialogType = "info"
WarningDialog DialogType = "warning"
ErrorDialog DialogType = "error"
QuestionDialog DialogType = "question"
)
```
### FileFilter
```go
type FileFilter struct {
DisplayName string // Filter information EG: "Image Files (*.jpg, *.png)"
Pattern string // semi-colon separated list of extensions, EG: "*.jpg;*.png"
}
```
#### Windows
Windows allows you to use multiple file filters in dialog boxes. Each FileFilter will show up as a separate entry in the dialog:
```mdx-code-block
<div class="text--center">
<img
src={require("@site/static/img/runtime/dialog_win_filters.png").default}
width="50%"
class="screenshot"
/>
</div>
<br />
<br />
<br />
```
#### Linux
Linux allows you to use multiple file filters in dialog boxes. Each FileFilter will show up as a separate entry in the dialog:
```mdx-code-block
<div class="text--center">
<img
src={require("@site/static/img/runtime/dialog_lin_filters.png").default}
width="50%"
class="screenshot"
/>
</div>
<br />
<br />
<br />
```
#### Mac
Mac dialogs only have the concept of a single set of patterns to filter files. If multiple FileFilters are provided, Wails will use all the Patterns defined.
Example:
```go
selection, err := runtime.OpenFileDialog(b.ctx, runtime.OpenDialogOptions{
Title: "Select File",
Filters: []runtime.FileFilter{
{
DisplayName: "Images (*.png;*.jpg)",
Pattern: "*.png;*.jpg",
}, {
DisplayName: "Videos (*.mov;*.mp4)",
Pattern: "*.mov;*.mp4",
},
},
})
```
This will result in the Open File dialog using `*.png,*.jpg,*.mov,*.mp4` as a filter.