diff --git a/README.md b/README.md index 545fd231a..c8641ea3a 100644 --- a/README.md +++ b/README.md @@ -18,42 +18,57 @@ ## Internationalization -English | [简体中文](README.zh-Hans.md) +[English](README.md) | [简体中文](README.zh-Hans.md) + + + +## Table of Contents + +
+ Click me to Open/Close the directory listing + +- [1. Internationalization](#nav-1) +- [2. Table of Contents](#nav-2) +- [3. Introductions](#nav-3) + - [3.1 Official Website](#nav-3-1) +- [4. Features](#nav-4) +- [5. Sponsors](#nav-5) +- [6. Installation](#nav-6) + - [6.1 MacOS](#nav-6-1) + - [6.2 Linux](#nav-6-2) + - [6.2.1 Debian/Ubuntu](#nav-6-2-1) + - [6.2.2 Arch Linux / ArchLabs / Ctlos Linux](#nav-6-2-2) + - [6.2.3 Centos](#nav-6-2-3) + - [6.2.4 Fedora](#nav-6-2-4) + - [6.2.5 VoidLinux & VoidLinux-musl](#nav-6-2-5) + - [6.2.6 Gentoo](#nav-6-2-6) + - [6.3 Windows](#nav-6-3) +- [7. Usage](#nav-7) + - [7.1 Next Steps](#nav-7-1) +- [8. FAQ](#nav-8) +- [9. Contributors](#nav-9) +- [10. Special Mentions](#nav-10) +- [12. Special Thanks](#nav-11) + +
+ + + +## Introductions The traditional method of providing web interfaces to Go programs is via a built-in web server. Wails offers a different approach: it provides the ability to wrap both Go code and a web frontend into a single binary. Tools are provided to make this easy for you by handling project creation, compilation and bundling. All you have to do is get creative! + + +### Official Website + The official docs can be found at [https://wails.app](https://wails.app). Click [here](https://wails.io) if you are interested in trying out v2 Beta for Windows. - - -## Contents - -- [1. Internationalization](#nav-1) -- [2. Contents](#nav-2) -- [3. Features](#nav-3) -- [4. Sponsors](#nav-4) -- [5. Installation](#nav-5) - - [5.1 MacOS](#nav-5-1) - - [5.2 Linux](#nav-5-2) - - [5.2.1 Debian/Ubuntu](#nav-5-2-1) - - [5.2.2 Arch Linux / ArchLabs / Ctlos Linux](#nav-5-2-2) - - [5.2.3 Centos](#nav-5-2-3) - - [5.2.4 Fedora](#nav-5-2-4) - - [5.2.5 VoidLinux & VoidLinux-musl](#nav-5-2-5) - - [5.2.6 Gentoo](#nav-5-2-6) - - [5.3 Windows](#nav-5-3) -- [6. Installation](#nav-6) -- [7. Next Steps](#nav-7) -- [8. FAQ](#nav-8) -- [9. Contributors](#nav-9) -- [10. Special Mentions](#nav-10) -- [11. Special Thanks](#nav-11) - - + ## Features @@ -67,7 +82,7 @@ Click [here](https://wails.io) if you are interested in trying out v2 Beta for W - Powerful cli tool - Multiplatform - + ## Sponsors @@ -142,7 +157,7 @@ This project is supported by these kind people / companies: - + ## Installation @@ -152,7 +167,7 @@ an installation of Go. The basic requirements are: - Go 1.16 - npm - + ### MacOS @@ -160,11 +175,11 @@ Make sure you have the xcode command line tools installed. This can be done by r `xcode-select --install` - + ### Linux - + #### Debian/Ubuntu @@ -176,7 +191,7 @@ _Ubuntu: 16.04, 18.04, 19.04_ _Also succesfully tested on: Zorin 15, Parrot 4.7, Linuxmint 19, Elementary 5, Kali, Neon_, Pop!\_OS - + #### Arch Linux / ArchLabs / Ctlos Linux @@ -184,7 +199,7 @@ _Also succesfully tested on: Zorin 15, Parrot 4.7, Linuxmint 19, Elementary 5, K _Also succesfully test on: Manjaro & ArcoLinux_ - + #### Centos @@ -192,7 +207,7 @@ _Also succesfully test on: Manjaro & ArcoLinux_ _CentOS 6, 7_ - + #### Fedora @@ -200,19 +215,19 @@ _CentOS 6, 7_ _Fedora 29, 30_ - + #### VoidLinux & VoidLinux-musl `xbps-install gtk+3-devel webkit2gtk-devel` - + #### Gentoo `sudo emerge gtk+:3 webkit-gtk` - + ### Windows @@ -220,21 +235,21 @@ Windows requires gcc and related tooling. The recommended download is from [http://tdm-gcc.tdragon.net/download](http://tdm-gcc.tdragon.net/download). Once this is installed, you are good to go. - + -## Installation +## Usage **Ensure Go modules are enabled: GO111MODULE=on and go/bin is in your PATH variable.** Installation is as simple as running the following command: -
+```
 go get -u github.com/wailsapp/wails/cmd/wails
-
+``` - + -## Next Steps +### Next Steps It is recommended at this stage to read the comprehensive documentation at [https://wails.app](https://wails.app). @@ -345,7 +360,7 @@ This project was mainly coded to the following albums:


- A huge thanks to Pace for sponsoring the project and helping the efforts to get Wails ported to Apple Silicon!

+ A huge thanks to Pace for sponsoring the project and helping the efforts to get Wails ported to Apple Silicon!

If you are looking for a Project Management tool that's powerful but quick and easy to use, check them out!

diff --git a/README.zh-Hans.md b/README.zh-Hans.md index fc310183e..7095dab46 100644 --- a/README.zh-Hans.md +++ b/README.zh-Hans.md @@ -1,5 +1,5 @@

-
+

使用 Go 和 Web 技术构建桌面应用程序。

@@ -18,44 +18,62 @@ ## 国际化 -[English](README.md) | 简体中文 - -向 Go 程序提供 Web 接口的传统方法是通过内置 Web 服务器。Wails 提供了一种不同的方法:它提供了将 Go 代码和 Web -前端都包装成单个二进制文件的能力。通过提供工具,可以很轻松的完成项目的创建、编译和打包。你所要做的就是发挥创意! - -官方文档可以在 [https://wails.app](https://wails.app) 中找到。 - -国内镜像站点 [https://wails.top](https://wails.top)。 +[English](README.md) | [简体中文](README.zh-Hans.md) ## 内容目录 +

+ 点我 打开/关闭 目录列表 + - [1. 国际化](#nav-1) - [2. 内容目录](#nav-2) -- [3. 特征](#nav-3) -- [4. 赞助商](#nav-4) -- [5. 安装](#nav-5) - - [5.1 MacOS](#nav-5-1) - - [5.2 Linux](#nav-5-2) - - [5.2.1 Debian/Ubuntu](#nav-5-2-1) - - [5.2.2 Arch Linux / ArchLabs / Ctlos Linux](#nav-5-2-2) - - [5.2.3 Centos](#nav-5-2-3) - - [5.2.4 Fedora](#nav-5-2-4) - - [5.2.5 VoidLinux & VoidLinux-musl](#nav-5-2-5) - - [5.2.6 Gentoo](#nav-5-2-6) - - [5.3 Windows](#nav-5-3) +- [3. 项目介绍](#nav-3) + - [3.1 官方网站](#nav-3-1) +- [4. 功能](#nav-4) +- [5. 赞助商](#nav-5) - [6. 安装](#nav-6) -- [7. 下一步](#nav-7) + - [6.1 MacOS](#nav-6-1) + - [6.2 Linux](#nav-6-2) + - [6.2.1 Debian/Ubuntu](#nav-6-2-1) + - [6.2.2 Arch Linux / ArchLabs / Ctlos Linux](#nav-6-2-2) + - [6.2.3 Centos](#nav-6-2-3) + - [6.2.4 Fedora](#nav-6-2-4) + - [6.2.5 VoidLinux & VoidLinux-musl](#nav-6-2-5) + - [6.2.6 Gentoo](#nav-6-2-6) + - [6.3 Windows](#nav-6-3) +- [7. 使用方法](#nav-7) + - [7.1 下一步](#nav-7-1) - [8. 常见问题](#nav-8) - [9. 贡献者](#nav-9) - [10. 特别提及](#nav-10) -- [11. 许可协议](#nav-11) -- [12. 特别感谢](#nav-12) +- [12. 特别感谢](#nav-11) + +
-## 特征 +## 项目介绍 + +为 Go 程序提供 Web 界面的传统方法是通过内置 Web 服务器。Wails 提供了一种不同的方法:它提供了将 Go 代码和 Web +前端一起打包成单个二进制文件的能力。通过提供的工具,可以很轻松的完成项目的创建、编译和打包。你所要做的就是发挥想象力! + + + +### 官方网站 + +官方文档可以在 [https://wails.app](https://wails.app) 中找到。 + +如果您对适用于 Windows 的 v2 测试版感兴趣,可以点击[此处](https://wails.io)查看。 + +镜像网站: + +- [中国大陆镜像站点 - https://wails.top](https://wails.top) + + + +## 功能 - 后端使用标准 Go - 使用任意前端技术构建 UI 界面 @@ -67,13 +85,12 @@ - 强大的命令行工具 - 跨多个平台 - + ## 赞助商 这个项目由以下这些人或者公司支持: - @@ -143,7 +160,7 @@ - + ## 安装 @@ -152,7 +169,7 @@ Wails 使用 cgo 与原生渲染引擎结合,因此需要依赖一些平台的 - Go 1.16 - npm - + ### MacOS @@ -160,11 +177,11 @@ Wails 使用 cgo 与原生渲染引擎结合,因此需要依赖一些平台的 `xcode-select --install` - + ### Linux - + #### Debian/Ubuntu @@ -176,7 +193,7 @@ _Ubuntu: 16.04, 18.04, 19.04_ _也成功测试了: Zorin 15, Parrot 4.7, Linuxmint 19, Elementary 5, Kali, Neon_, Pop!\_OS - + #### Arch Linux / ArchLabs / Ctlos Linux @@ -184,7 +201,7 @@ _也成功测试了: Zorin 15, Parrot 4.7, Linuxmint 19, Elementary 5, Kali, Neo _也成功测试了: Manjaro & ArcoLinux_ - + #### Centos @@ -192,7 +209,7 @@ _也成功测试了: Manjaro & ArcoLinux_ _CentOS 6, 7_ - + #### Fedora @@ -200,39 +217,39 @@ _CentOS 6, 7_ _Fedora 29, 30_ - + #### VoidLinux & VoidLinux-musl `xbps-install gtk+3-devel webkit2gtk-devel` - + #### Gentoo `sudo emerge gtk+:3 webkit-gtk` - + ### Windows Windows 需要 GCC 和相关工具。 建议从 [http://tdm-gcc.tdragon.net/download](http://tdm-gcc.tdragon.net/download) 下载, 安装完成,您就可以开始了。 - + -## 安装 +## 使用方法 **确保 Go modules 是开启的:GO111MODULE=on 并且 go/bin 在您的 PATH 变量中。** 安装很简单,运行以下命令: -
+```
 go get -u github.com/wailsapp/wails/cmd/wails
-
+``` - + -## 下一步 +### 下一步 建议在此时阅读 [https://wails.app](https://wails.app) 上面的文档. @@ -244,14 +261,14 @@ go get -u github.com/wailsapp/wails/cmd/wails 取决于您的要求。它旨在使 Go 程序员可以轻松制作轻量级桌面应用程序或在其现有应用程序中添加前端。尽管 Wails 当前不提供对诸如菜单之类的原生元素的钩子,但将来可能会改变。 -- 这个项目针对的是谁? +- 这个项目针对的是哪些人? 希望将 HTML / JS / CSS 前端与其应用程序捆绑在一起的程序员,而不是借助创建服务并打开浏览器进行查看的方式。 - 名字怎么来的? 当我看到 WebView 时,我想"我真正想要的是围绕构建 WebView 应用程序工作,有点像 Rails 对于 Ruby"。因此,最初它是一个文字游戏(Webview on - Rails)。碰巧也是我来自的 [国家](https://en.wikipedia.org/wiki/Wales) 的英文名字的同音。所以就是他了。 + Rails)。碰巧也是我来自的 [国家](https://en.wikipedia.org/wiki/Wales) 的英文名字的同音。所以就是它了。 @@ -302,6 +319,7 @@ go get -u github.com/wailsapp/wails/cmd/wails + @@ -311,9 +329,9 @@ go get -u github.com/wailsapp/wails/cmd/wails - [Dustin Krysak](https://wiki.ubuntu.com/bashfulrobot) - 他的支持和反馈是巨大的。 - [Serge Zaitsev](https://github.com/zserge) - Wails 窗口所使用的 [Webview](https://github.com/zserge/webview) 的作者。 -- [Byron](https://github.com/bh90210) - 有时,Byron 单枪匹马地保持这个项目活着。没有他令人难以置信的投入,我们永远不会得到 v1 。 +- [Byron](https://github.com/bh90210) - 有时,Byron 一个人保持这个项目活跃着。没有他令人难以置信的投入,我们永远不会得到 v1 。 -This project was mainly coded to the following albums: +编写项目代码时伴随着以下专辑: - [Manic Street Preachers - Resistance Is Futile](https://open.spotify.com/album/1R2rsEUqXjIvAbzM0yHrxA) - [Manic Street Preachers - This Is My Truth, Tell Me Yours](https://open.spotify.com/album/4VzCL9kjhgGQeKCiojK1YN) @@ -331,17 +349,11 @@ This project was mainly coded to the following albums: -## 许可协议 - -[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fwailsapp%2Fwails.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fwailsapp%2Fwails?ref=badge_large) - - - ## 特别感谢


- 非常感谢Pace对项目的赞助,并帮助将 Wails 移植到 Apple Silicon !

+ 非常 感谢Pace对项目的赞助,并帮助将 Wails 移植到 Apple Silicon !

如果您正在寻找一个强大并且快速和易于使用的项目管理工具,可以看看他们!

diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/application-development.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/application-development.mdx index 6cd13c452..aa2c51f35 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/application-development.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/application-development.mdx @@ -149,11 +149,16 @@ Wails v2 处理资源的方式的伟大之处在于它没有!您唯一需要 ## 内置开发服务器 -TODO: 待同步 +运行`wails dev`将启动内置的开发服务器,它将在您的项目目录中启动一个文件监听器。 +默认情况下,如果有任何文件更改,wails 会检查它是否是应用程序文件(默认:.go,可使用`-e`标志配置)。如果是,那么它将重新构建您的应用程序并重新启动它。如果更改的文件在`assetdir`目录中,它会在很短的时间后重新加载。 + +开发服务器使用一种称为“防抖”的技术,这意味着它不会立即重新加载,因为可能会在短时间内更改多个文件。当触发发生时,它会在发出重新加载之前等待一定的时间。 +如果发生另一个触发,它会再次重置为等待时间。默认情况下,此值为 100ms。如果此值不适用于您的项目,则可以使用`-debounce`标志进行配置。如果使用,此值将保存到您的项目配置中并成为默认值。 ## 外部开发服务器 -TODO: 待同步 +一些框架带有自己的实时重新加载服务器,但是它们将无法利用 Wails Go 绑定。在这种情况下,最好运行一个监听脚本,将项目重新构建到构建目录中,Wails 将监视该目录。 +有关示例,请参阅使用[rollup](https://rollupjs.org/guide/en/)的默认 svelte 模板。对于[create-react-app](https://create-react-app.dev/),可以使用[此脚本](https://gist.github.com/int128/e0cdec598c5b3db728ff35758abdbafd)来实现类似的结果。 ## Go 模块 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/frameless.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/frameless.mdx index aad005810..a1052bf26 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/frameless.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/frameless.mdx @@ -25,3 +25,7 @@ Wails 为拖动窗口提供了一个简单的解决方案:任何具有“data- ``` + +:::info 全屏 +如果您允许应用程序全屏显示,则此拖动功能将被禁用。 +::: diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/templates.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/templates.mdx index 961227f8e..fbf47c06d 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/templates.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/templates.mdx @@ -89,3 +89,4 @@ Renaming package-lock.json -> package-lock.tmpl.json... - 确保`template.json`完整,尤其是`helpurl` - 将文件推送到 GitHub - 在[社区模板](/docs/community/templates)页面上创建 PR +- 在[模板公告](https://github.com/wailsapp/wails/discussions/825)讨论板上发布模板 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/windows.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/windows.mdx index 6a9068c37..48d65ec32 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/windows.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/guides/windows.mdx @@ -9,10 +9,10 @@ 通过在构建时使用`-webview2`标志,您可以决定在未检测到合适的运行时的时候(包括安装的运行时是否太旧)应用程序将执行的操作。四个选项是: -1. 下载 -2. 内嵌 -3. 浏览器 -4. 错误 +1. Download(下载) +2. Embed(内嵌) +3. Browser(浏览器) +4. Error(错误) ### 下载 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/howdoesitwork.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/howdoesitwork.mdx index 47e22cb84..69494863b 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/howdoesitwork.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/howdoesitwork.mdx @@ -98,7 +98,9 @@ var assets embed.FS 由于可用于生产的二进制文件使用包含在`embed.FS`中的文件,因此应用程序不需要附带任何外部文件。 当使用`wails dev`命令在”dev“模式下,资源从磁盘加载,任何更改都会导致“实时重新加载”。资源的位置需要使用`-assetdir`传递给`wails dev`命令,并且很可能与嵌入路径相同。 -希望将来我们可以从`embed.FS`本身计算出来。更多细节可以在[应用程序开发指南](/docs/guides/application-development)中找到。 +希望将来我们可以从`embed.FS`本身计算出来。 + +更多细节可以在[应用程序开发指南](/docs/guides/application-development)中找到。 #### 应用程序生命周期回调 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/options.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/options.mdx index 3c27b5577..ea00656b5 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/options.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/options.mdx @@ -243,7 +243,7 @@ func main() { 类型:bool -将此设置为 true 将使 webview 背景透明,其中没有其他颜色呈现。通常与[窗口半透明](#窗口半透明)结合使用 以制作外观现代的应用程序。 +当 alpha 值为 0 时,设置为 true 将使 WebView 背景透明。这意味着如果你使用`rgba(0,0,0,0)`,主窗口将显示。通常与[窗口半透明](#窗口半透明)结合使用以制作冰霜效果的应用程序。 ### 窗口半透明 @@ -251,7 +251,7 @@ func main() { 类型:bool -将此设置为 true 将使窗口半透明。通常与[网页透明](#网页透明) 结合使用以制作外观现代的应用程序。 +将此设置为 true 将使窗口半透明。通常与[网页透明](#网页透明) 结合使用以制作冰霜效果的应用程序。 ### 禁用窗口图标 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/runtime/dialog.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/runtime/dialog.mdx index 78f082e8d..9264196f1 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/runtime/dialog.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/runtime/dialog.mdx @@ -5,8 +5,6 @@ sidebar_position: 5 # 对话框 -TODO: 待同步 - ## 概述 运行时的这一部分提供对原生对话框的调用,例如文件选择器和消息框。上下文 @@ -17,44 +15,44 @@ JS 运行时当前不支持 Dialog。 ### 打开选择目录对话框 +打开一个对话框,提示用户选择目录。可以使用 [打开选择文件对话框参数选项](#打开选择文件对话框参数选项)进行自定义。 + Go 方法签名: `OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error)` 返回值: 所选目录(如果用户取消则为空白)或错误 -打开一个对话框,提示用户选择目录。可以使用 [打开选择文件对话框参数选项](#打开选择文件对话框参数选项)进行自定义。 - ### 打开选择文件对话框 +打开一个对话框,提示用户选择文件。可以使用[打开选择文件对话框参数选项](#打开选择文件对话框参数选项)进行自定义。 + Go 方法签名: `OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error)` 返回值: 所选文件(如果用户取消则为空白)或错误 -打开一个对话框,提示用户选择文件。可以使用[打开选择文件对话框参数选项](#打开选择文件对话框参数选项)进行自定义。 - ### 打开选择多个文件对话框 +打开一个对话框,提示用户选择多个文件。可以使用[打开选择文件对话框参数选项](#打开选择文件对话框参数选项)进行自定义。 + Go 方法签名: `OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error)` 返回值: 选定的文件(如果用户取消则为零)或错误 -打开一个对话框,提示用户选择多个文件。可以使用[打开选择文件对话框参数选项](#打开选择文件对话框参数选项)进行自定义。 - ### 保存文件对话框 +打开一个对话框,提示用户选择文件名以进行保存。可以使用[保存文件对话框参数选项](#保存文件对话框参数选项)自定义。 + Go 方法签名: `SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error)` 返回值: 所选文件(如果用户取消则为空白)或错误 -打开一个对话框,提示用户选择文件名以进行保存。可以使用[保存文件对话框参数选项](#保存文件对话框参数选项)自定义。 - ### 消息对话框 +使用消息对话框显示消息。可以使用[消息对话框参数选项](#消息对话框参数选项)进行自定义。 + Go 方法签名: `MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error)` 返回值: 所选按钮的文本或错误 -使用消息对话框显示消息。可以使用[消息对话框参数选项](#消息对话框参数选项)进行自定义。 - ## 参数选项 ### 打开选择文件对话框参数选项 @@ -65,15 +63,28 @@ type OpenDialogOptions struct { DefaultFilename string Title string Filters []FileFilter - AllowFiles bool // Mac Only - AllowDirectories bool // Mac Only - ShowHiddenFiles bool // Mac Only - CanCreateDirectories bool // Mac Only - ResolvesAliases bool // Mac Only - TreatPackagesAsDirectories bool // Mac Only + AllowFiles bool + AllowDirectories bool + ShowHiddenFiles bool + CanCreateDirectories bool + ResolvesAliases bool + TreatPackagesAsDirectories bool } ``` +| 字段 | 描述 | Win | Mac | +| -------------------------- | --------------------------------- | --- | --- | +| DefaultDirectory | 对话框打开时显示的目录 | ✅ | ✅ | +| DefaultFilename | 默认文件名 | ✅ | ✅ | +| Title | 对话框的标题 | ✅ | ✅ | +| [Filters](#文件过滤) | 文件过滤器列表 | ✅ | ✅ | +| AllowFiles | 允许选择文件 | | ✅ | +| AllowDirectories | 允许选择目录 | | ✅ | +| ShowHiddenFiles | 显示系统隐藏的文件 | | ✅ | +| CanCreateDirectories | 允许用户创建目录 | | ✅ | +| ResolvesAliases | 如果为 true,则返回文件而不是别名 | | ✅ | +| TreatPackagesAsDirectories | 允许导航到包 | | ✅ | + ### 保存文件对话框参数选项 ```go @@ -82,12 +93,22 @@ type SaveDialogOptions struct { DefaultFilename string Title string Filters []FileFilter - ShowHiddenFiles bool // Mac Only - CanCreateDirectories bool // Mac Only - TreatPackagesAsDirectories bool // Mac Only + ShowHiddenFiles bool + CanCreateDirectories bool + TreatPackagesAsDirectories bool } ``` +| 字段 | 描述 | Win | Mac | +| -------------------------- | ---------------------- | --- | --- | +| DefaultDirectory | 对话框打开时显示的目录 | ✅ | ✅ | +| DefaultFilename | 默认文件名 | ✅ | ✅ | +| Title | 对话框的标题 | ✅ | ✅ | +| [Filters](#文件过滤) | 文件过滤器列表 | ✅ | ✅ | +| ShowHiddenFiles | 显示系统隐藏的文件 | | ✅ | +| CanCreateDirectories | 允许用户创建目录 | | ✅ | +| TreatPackagesAsDirectories | 允许导航到包 | | ✅ | + ### 消息对话框参数选项 ```go @@ -96,30 +117,96 @@ type MessageDialogOptions struct { Title string Message string Buttons []string - DefaultButton string // Mac Only - CancelButton string // Mac Only - Icon string // Mac Only + DefaultButton string + CancelButton string } ``` -import Tabs from "@theme/Tabs"; -import TabItem from "@theme/TabItem"; +| 字段 | 描述 | Win | Mac | +| ------------- | ---------------------------------------------------- | --- | --- | +| Type | 消息对话框的类型,例如问题、信息... | ✅ | ✅ | +| Title | 对话框的标题 | ✅ | ✅ | +| Message | 向用户显示的消息 | ✅ | ✅ | +| Buttons | 按钮标题列表 | | ✅ | +| DefaultButton | 带有此文本的按钮应被视为默认按钮。 Bound to `return` | | ✅ | +| CancelButton | 带有此文本的按钮应被视为取消。Bound to `escape` | | ✅ | - - - Windows - 具有标准对话框类型并且按钮不可定制。返回的值将是以下之一:“确定”、“取消”、“中止”、“重试”、“忽略”、“是”、“否”、“再试一次”或“继续” - - “DefaultButton”和“CancelButton”都应与“Buttons”中的值匹配。 - 即将推出... - +#### Windows + +Windows 具有标准对话框类型,其中的按钮不可自定义。 +返回的值将是以下之一:"Ok", "Cancel", "Abort", "Retry", "Ignore", "Yes", "No", "Try Again" or "Continue" + +#### Mac + +Mac 上的消息对话框最多可以指定 4 个按钮。如果没有`DefaultButton`或`CancelButton`给出,第一个按钮被认为是默认的并绑定到`return`键。 + +对于以下代码: + +```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”: + +```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", +}) +``` + +第二个按钮显示为默认值。当 `return` 被按下时,则返回数值“two”。 + +
+ +
+
+ +如果我们现在指定`CancelButton`为“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", +}) +``` + +带有“three”的按钮显示在对话框的底部。当`escape`被按下时,则返回值“three”: + +
+ +
+
+
+
#### 对话框类型 @@ -140,3 +227,41 @@ type FileFilter struct { Pattern string // semi-colon separated list of extensions, EG: "*.jpg;*.png" } ``` + +#### Windows + +Windows 允许您在对话框中使用多个文件过滤器。每个 FileFilter 将在对话框中显示为一个单独的条目: + +
+ +
+
+
+
+ +#### Mac + +Mac 对话框只有一组模式来过滤文件的概念。如果提供了多个 FileFilters,Wails 将使用所有定义的模式。 + +示例: + +```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", + }, + }, + }) +``` + +这将导致使用`*.png,*.jpg,*.mov,*.mp4`作为过滤器打开文件对话框。