From 1b56162235959b0323fcf8edcde223abb985c5c8 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sat, 14 Oct 2023 23:14:28 -0300 Subject: [PATCH 01/22] init dialog guide --- src/content/docs/features/dialog.mdx | 184 ++++++++++++++++++++++++++- 1 file changed, 180 insertions(+), 4 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 12f5c8493b..1396d342aa 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -5,10 +5,186 @@ description: Native system dialogs for opening and saving files along with messa import Stub from '@components/Stub.astro'; import PluginLinks from '@components/PluginLinks.astro'; +import { Tabs, TabItem } from '@astrojs/starlight/components'; +import CommandTabs from '@components/CommandTabs.astro'; - - Based on - https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/dialog - +Native system dialogs for opening and saving files along with message dialogs + +## Setup + +Install the dialog plugin to get started. + + + + + 1. Use your project's package manager to add the dependency: + + + + 2. Modify `lib.rs` to initialize the plugin: + + ```rust + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + // Initialize the plugin + .plugin(tauri_plugin_dialog::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + + + + 1. Run `cargo add tauri-plugin-dialog` to add the plugin to the project's dependencies in `Cargo.toml`. + + 2. Modify `lib.rs` to initialize the plugin: + + ```rust + // lib.rs + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + // Initialize the plugin + .plugin(tauri_plugin_dialog::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + 3. If you'd like create dialogs in JavaScript, install the npm package as well: + + + + + + + +## Usage + +Here's how you can use the dialog plugin: + +- [Dialog to open a file or directory](#open) +- [Dialog to save a file](#save) +- [Show a message dialog](#message) +- [Confirmation dialogue Yes No](#ask) +- [Action dialog Ok Cancel](#confirm) + +{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} + +The dialog plugin is available in both JavaScript and Rust. + +### Open + + + +```js +import { open } from '@tauri-apps/plugin-dialog'; + +// Open a dialog +const file = await open(); +console.log(file); +// Prints file data to the console +``` + + + + +{/* TODO: */} + + + + + + + +#### File + + + + + +Select a single file: +```js +// Open a dialog +const file = await open({ + multiple: false, + directory: false, +}); +console.log(file); +// Prints file data to the console +``` + +Select Multiple Files + +```js +const files = await open({ + multiple: true, + directory: false, +}); +selectedFiles.forEach((file) => { + console.log(file); +}); +``` + + + + + +{/* TODO: */} + + + + + + + +#### Directory + + + + + +Select a directory: + +```js +const dir = await open({ + multiple: false, + directory: true, +}); +console.log(dir); +``` + +Select multiple directories + +```js +const directories = await open({ + multiple: true, + directory: true, +}); +directories.forEach((path) => { + console.log(path); +}); +``` + + + + + +{/* TODO: */} + + + + + + From 9f31c1fbccbb6ecd6db95335c0b33b7b75844e15 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 15 Oct 2023 00:24:15 -0300 Subject: [PATCH 02/22] Stubs --- src/content/docs/features/dialog.mdx | 127 +++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 19 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 1396d342aa..e9a19c38d1 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -38,7 +38,6 @@ Install the dialog plugin to get started. .expect("error while running tauri application"); } ``` - @@ -66,8 +65,7 @@ Install the dialog plugin to get started. pnpm="pnpm add @tauri-apps/plugin-dialog" /> - - + ## Usage @@ -84,10 +82,13 @@ Here's how you can use the dialog plugin: The dialog plugin is available in both JavaScript and Rust. +{/* OPEN */} + ### Open + ```js import { open } from '@tauri-apps/plugin-dialog'; @@ -105,35 +106,37 @@ console.log(file); - -#### File +{/* OPEN > FILE */} + +### File Select a single file: + ```js -// Open a dialog +/// Open a dialog const file = await open({ - multiple: false, - directory: false, + multiple: false, + directory: false, }); console.log(file); -// Prints file data to the console +/// Prints file data to the console ``` Select Multiple Files ```js const files = await open({ - multiple: true, - directory: false, + multiple: true, + directory: false, }); selectedFiles.forEach((file) => { - console.log(file); + console.log(file); }); ``` @@ -149,7 +152,9 @@ selectedFiles.forEach((file) => { -#### Directory +{/* OPEN > DIRECTORY */} + +### Directory @@ -159,21 +164,21 @@ Select a directory: ```js const dir = await open({ - multiple: false, - directory: true, + multiple: false, + directory: true, }); console.log(dir); ``` -Select multiple directories +Select multiple directories: ```js const directories = await open({ - multiple: true, - directory: true, + multiple: true, + directory: true, }); directories.forEach((path) => { - console.log(path); + console.log(path); }); ``` @@ -188,3 +193,87 @@ directories.forEach((path) => { + +{/* SAVE */} + +### Save + + + + +{/* TODO: */} + + + + + + +{/* TODO: */} + + + + + + +{/* MESSAGE */} + +### Message + + + + +{/* TODO: */} + + + + + + +{/* TODO: */} + + + + + + +{/* ASK */} + +### Ask + + + + +{/* TODO: */} + + + + + + +{/* TODO: */} + + + + + + +{/* CONFIRM */} + +### Confirm + + + + +{/* TODO: */} + + + + + + +{/* TODO: */} + + + + + From 8476c73d1cc6deb5f6b8d2331006b749a2b08a34 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 15 Oct 2023 00:44:55 -0300 Subject: [PATCH 03/22] create basic js guides --- src/content/docs/features/dialog.mdx | 69 ++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index e9a19c38d1..9085063e44 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -10,7 +10,7 @@ import CommandTabs from '@components/CommandTabs.astro'; -Native system dialogs for opening and saving files along with message dialogs +Native system dialogs for opening and saving files along with message dialogs. ## Setup @@ -75,8 +75,8 @@ Here's how you can use the dialog plugin: - [Dialog to open a file or directory](#open) - [Dialog to save a file](#save) - [Show a message dialog](#message) -- [Confirmation dialogue Yes No](#ask) -- [Action dialog Ok Cancel](#confirm) +- [Confirmation dialogue ](#ask) +- [Action dialog](#confirm) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} @@ -101,7 +101,7 @@ console.log(file); -{/* TODO: */} +{/* TODO RUST: */} @@ -128,7 +128,7 @@ console.log(file); /// Prints file data to the console ``` -Select Multiple Files +Select Multiple Files: ```js const files = await open({ @@ -144,7 +144,7 @@ selectedFiles.forEach((file) => { -{/* TODO: */} +{/* TODO RUST: */} @@ -186,7 +186,7 @@ directories.forEach((path) => { -{/* TODO: */} +{/* TODO RUST: */} @@ -201,14 +201,28 @@ directories.forEach((path) => { -{/* TODO: */} +```js +import { save } from '@tauri-apps/plugin-dialog'; + +// Prompt to save a Image with extension .png or .jpeg +const path = await save({ + filters: [ + { + name: 'Image', + extensions: ['png', 'jpeg'], + }, + ], +}); +console.log(path); +// Prints the path chosen +``` -{/* TODO: */} +{/* TODO RUST: */} @@ -222,14 +236,19 @@ directories.forEach((path) => { -{/* TODO: */} +```js +import { message } from '@tauri-apps/plugin-dialog'; + +// Shows message +await message('File not found', { title: 'Tauri', type: 'error' }); +``` -{/* TODO: */} +{/* TODO RUST: */} @@ -243,14 +262,25 @@ directories.forEach((path) => { -{/* TODO: */} +```js +import { ask } from '@tauri-apps/plugin-dialog'; + +// Create a Yes/No dialog +const yes = await ask('This action cannot be reverted. Are you sure?', { + title: 'Tauri', + type: 'warning', +}); + +console.log(yes); +// Prints boolean to the console +``` -{/* TODO: */} +{/* TODO RUST: */} @@ -264,7 +294,18 @@ directories.forEach((path) => { -{/* TODO: */} +```js +import { confirm } from '@tauri-apps/plugin-dialog'; + +// Creates a confirmation Yes/No dialog +const confirmed = await confirm( + 'This action cannot be reverted. Are you sure?', + { title: 'Tauri', type: 'warning' } +); + +console.log(confirmed); +// Prints boolean to the console +``` From ec866e89d4c1128209f4ede5ce51a1b4552f3856 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 16 Oct 2023 01:18:00 -0300 Subject: [PATCH 04/22] fix: typo --- src/content/docs/features/dialog.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 9085063e44..736e0a3986 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -75,7 +75,7 @@ Here's how you can use the dialog plugin: - [Dialog to open a file or directory](#open) - [Dialog to save a file](#save) - [Show a message dialog](#message) -- [Confirmation dialogue ](#ask) +- [Confirmation dialog](#ask) - [Action dialog](#confirm) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} From c537e4d4975bb717f77674cc8fdb3027557bac5b Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 16 Oct 2023 01:41:35 -0300 Subject: [PATCH 05/22] improvements based on v1 docs --- src/content/docs/features/dialog.mdx | 227 +++++++++++++-------------- 1 file changed, 113 insertions(+), 114 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 736e0a3986..6923f6b4d9 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -72,20 +72,109 @@ Install the dialog plugin to get started. Here's how you can use the dialog plugin: -- [Dialog to open a file or directory](#open) -- [Dialog to save a file](#save) -- [Show a message dialog](#message) -- [Confirmation dialog](#ask) -- [Action dialog](#confirm) +- [Show a question dialog with `Yes` and `No` buttons](#ask) +- [Show a question dialog with `Ok` and `Cancel` buttons](#confirm) +- [Show a message dialog with an `Ok` button](#message) +- [Open a file/directory selection dialog](#open) +- [Open a file/directory save dialog](#save) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} The dialog plugin is available in both JavaScript and Rust. +{/* MESSAGE */} + +### Message + +Show a question dialog with `Yes` and `No` buttons + + + + +```js +import { message } from '@tauri-apps/plugin-dialog'; + +// Shows message +await message('File not found', { title: 'Tauri', type: 'error' }); +``` + + + + + +{/* TODO RUST: */} + + + + +{/* ASK */} + +### Ask + +Show a question dialog with `Ok` and `Cancel` buttons + + + + +```js +import { ask } from '@tauri-apps/plugin-dialog'; + +// Create a Yes/No dialog +const yes = await ask('This action cannot be reverted. Are you sure?', { + title: 'Tauri', + type: 'warning', +}); + +console.log(yes); +// Prints boolean to the console +``` + + + + + +{/* TODO RUST: */} + + + + +{/* CONFIRM */} + +### Confirm + +Shows a question dialog with Ok and Cancel buttons. + + + + +```js +import { confirm } from '@tauri-apps/plugin-dialog'; + +// Creates a confirmation Yes/No dialog +const confirmed = await confirm( + 'This action cannot be reverted. Are you sure?', + { title: 'Tauri', type: 'warning' } +); + +console.log(confirmed); +// Prints boolean to the console +``` + + + + + +{/* TODO RUST: */} + + + + {/* OPEN */} ### Open +Open a file/directory selection dialog. + @@ -101,42 +190,43 @@ console.log(file); -{/* TODO RUST: */} - +{/* TODO RUST: */} {/* OPEN > FILE */} -### File +#### File - +Select single file: -Select a single file: + ```js -/// Open a dialog +// Open a dialog const file = await open({ multiple: false, directory: false, }); console.log(file); -/// Prints file data to the console +// Prints file data to the console ``` -Select Multiple Files: +Select multiple files: ```js +// Open a dialog const files = await open({ multiple: true, directory: false, }); selectedFiles.forEach((file) => { console.log(file); + // Prints each file data to the console }); ``` @@ -144,9 +234,8 @@ selectedFiles.forEach((file) => { -{/* TODO RUST: */} - +{/* TODO RUST: */} @@ -154,31 +243,35 @@ selectedFiles.forEach((file) => { {/* OPEN > DIRECTORY */} -### Directory +#### Directory -Select a directory: +Select directory: ```js +// Open a dialog const dir = await open({ multiple: false, directory: true, }); console.log(dir); +// Prints directory path ``` Select multiple directories: ```js +// Open a dialog const directories = await open({ multiple: true, directory: true, }); directories.forEach((path) => { console.log(path); + // Prints each directory path }); ``` @@ -186,9 +279,8 @@ directories.forEach((path) => { -{/* TODO RUST: */} - +{/* TODO RUST: */} @@ -204,7 +296,7 @@ directories.forEach((path) => { ```js import { save } from '@tauri-apps/plugin-dialog'; -// Prompt to save a Image with extension .png or .jpeg +// Prompt to save a 'Image' with extension .png or .jpeg const path = await save({ filters: [ { @@ -214,107 +306,14 @@ const path = await save({ ], }); console.log(path); -// Prints the path chosen -``` - - - - - - -{/* TODO RUST: */} - - - - - - -{/* MESSAGE */} - -### Message - - - - -```js -import { message } from '@tauri-apps/plugin-dialog'; - -// Shows message -await message('File not found', { title: 'Tauri', type: 'error' }); +// Prints the chosen path ``` - - -{/* TODO RUST: */} - - - - - - -{/* ASK */} - -### Ask - - - - -```js -import { ask } from '@tauri-apps/plugin-dialog'; - -// Create a Yes/No dialog -const yes = await ask('This action cannot be reverted. Are you sure?', { - title: 'Tauri', - type: 'warning', -}); - -console.log(yes); -// Prints boolean to the console -``` - - - - - {/* TODO RUST: */} - - - - - -{/* CONFIRM */} - -### Confirm - - - - -```js -import { confirm } from '@tauri-apps/plugin-dialog'; - -// Creates a confirmation Yes/No dialog -const confirmed = await confirm( - 'This action cannot be reverted. Are you sure?', - { title: 'Tauri', type: 'warning' } -); - -console.log(confirmed); -// Prints boolean to the console -``` - - - - - - -{/* TODO: */} - - - From 4c4c007a2928ff97368f137cfff7728795b4696c Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 16 Oct 2023 12:02:33 -0300 Subject: [PATCH 06/22] fix: typo --- src/content/docs/features/notification.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/features/notification.mdx b/src/content/docs/features/notification.mdx index 2d211f8414..91aa436a9f 100644 --- a/src/content/docs/features/notification.mdx +++ b/src/content/docs/features/notification.mdx @@ -77,7 +77,7 @@ Install the notifications plugin to get started. Here are a few examples of how to use the notification plugin: -- [Sent notification to users](#send-notification) +- [Send notification to users](#send-notification) - [Add an action to a notification](#actions) - [Add an attachment to a notification](#attachments) - [Send a notification in a specific channel](#channels) From 35a02bf976c872b829c8873374615b8a0b4b6d6d Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 16 Oct 2023 17:00:48 -0300 Subject: [PATCH 07/22] reorder based on summary (a-z) --- src/content/docs/features/dialog.mdx | 50 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 6923f6b4d9..0a7bd4a395 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -82,31 +82,6 @@ Here's how you can use the dialog plugin: The dialog plugin is available in both JavaScript and Rust. -{/* MESSAGE */} - -### Message - -Show a question dialog with `Yes` and `No` buttons - - - - -```js -import { message } from '@tauri-apps/plugin-dialog'; - -// Shows message -await message('File not found', { title: 'Tauri', type: 'error' }); -``` - - - - - -{/* TODO RUST: */} - - - - {/* ASK */} ### Ask @@ -169,6 +144,31 @@ console.log(confirmed); +{/* MESSAGE */} + +### Message + +Show a question dialog with `Yes` and `No` buttons + + + + +```js +import { message } from '@tauri-apps/plugin-dialog'; + +// Shows message +await message('File not found', { title: 'Tauri', type: 'error' }); +``` + + + + + +{/* TODO RUST: */} + + + + {/* OPEN */} ### Open From 67beeb61ce9e9de7aaa71da041319c2818d7a80d Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 5 Nov 2023 17:55:06 -0300 Subject: [PATCH 08/22] Update dialog.mdx --- src/content/docs/features/dialog.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 0a7bd4a395..69b5723bd5 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -86,7 +86,7 @@ The dialog plugin is available in both JavaScript and Rust. ### Ask -Show a question dialog with `Ok` and `Cancel` buttons +Shows a question dialog with `Yes` and `No` buttons @@ -117,7 +117,7 @@ console.log(yes); ### Confirm -Shows a question dialog with Ok and Cancel buttons. +Shows a question dialog with `Ok` and `Cancel` buttons. @@ -125,7 +125,7 @@ Shows a question dialog with Ok and Cancel buttons. ```js import { confirm } from '@tauri-apps/plugin-dialog'; -// Creates a confirmation Yes/No dialog +// Creates a confirmation Ok/Cancel dialog const confirmed = await confirm( 'This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' } @@ -148,7 +148,7 @@ console.log(confirmed); ### Message -Show a question dialog with `Yes` and `No` buttons +Shows a message dialog with an `Ok` button. From 16508dba6eaaddbcbdfa1d16bd95883f2cf978fd Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 5 Nov 2023 18:26:50 -0300 Subject: [PATCH 09/22] update headings --- src/content/docs/features/dialog.mdx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 69b5723bd5..297dc6e86e 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -72,11 +72,11 @@ Install the dialog plugin to get started. Here's how you can use the dialog plugin: -- [Show a question dialog with `Yes` and `No` buttons](#ask) -- [Show a question dialog with `Ok` and `Cancel` buttons](#confirm) -- [Show a message dialog with an `Ok` button](#message) -- [Open a file/directory selection dialog](#open) -- [Open a file/directory save dialog](#save) +- [Show a question dialog with `Yes` and `No` buttons](#create-yesno-dialog) +- [Show a question dialog with `Ok` and `Cancel` buttons](#create-okcancel-dialog) +- [Show a message dialog with `Ok` button](#create-message-dialog) +- [Open a file/directory selection dialog](#open-a-file-selector-dialog) +- [Open a file/directory save dialog](#open-a-save-dialog) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} @@ -84,7 +84,7 @@ The dialog plugin is available in both JavaScript and Rust. {/* ASK */} -### Ask +### Create Yes/No Dialog Shows a question dialog with `Yes` and `No` buttons @@ -115,7 +115,7 @@ console.log(yes); {/* CONFIRM */} -### Confirm +### Create Ok/Cancel Dialog Shows a question dialog with `Ok` and `Cancel` buttons. @@ -146,7 +146,7 @@ console.log(confirmed); {/* MESSAGE */} -### Message +### Create Message Dialog Shows a message dialog with an `Ok` button. @@ -171,7 +171,7 @@ await message('File not found', { title: 'Tauri', type: 'error' }); {/* OPEN */} -### Open +### Open a File Selector Dialog Open a file/directory selection dialog. @@ -288,7 +288,7 @@ directories.forEach((path) => { {/* SAVE */} -### Save +### Open a Save Dialog From eff678121e8463ac1f5661fb502bd16f25c33cea Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 5 Nov 2023 18:30:14 -0300 Subject: [PATCH 10/22] Save to file/directory --- src/content/docs/features/dialog.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 297dc6e86e..c2be313ec3 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -76,7 +76,7 @@ Here's how you can use the dialog plugin: - [Show a question dialog with `Ok` and `Cancel` buttons](#create-okcancel-dialog) - [Show a message dialog with `Ok` button](#create-message-dialog) - [Open a file/directory selection dialog](#open-a-file-selector-dialog) -- [Open a file/directory save dialog](#open-a-save-dialog) +- [Save to file/directory dialog](#open-a-save-dialog) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} From 39d9eaa13da6a69345545b87b363154e161a3f29 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Sun, 5 Nov 2023 23:35:40 -0300 Subject: [PATCH 11/22] simplify and match TOC --- src/content/docs/features/dialog.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index c2be313ec3..a784be96e9 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -72,11 +72,11 @@ Install the dialog plugin to get started. Here's how you can use the dialog plugin: -- [Show a question dialog with `Yes` and `No` buttons](#create-yesno-dialog) -- [Show a question dialog with `Ok` and `Cancel` buttons](#create-okcancel-dialog) -- [Show a message dialog with `Ok` button](#create-message-dialog) -- [Open a file/directory selection dialog](#open-a-file-selector-dialog) -- [Save to file/directory dialog](#open-a-save-dialog) +- [Create Yes/No Dialog](#create-yesno-dialog) +- [Create Ok/Cancel Dialog](#create-okcancel-dialog) +- [Create Message Dialog](#create-message-dialog) +- [Open a File Selector Dialog](#open-a-file-selector-dialog) +- [Save to File Dialog](#save-to-file-dialog) {/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} @@ -288,7 +288,7 @@ directories.forEach((path) => { {/* SAVE */} -### Open a Save Dialog +### Save to File Dialog From 39c1cb7c4feb5d1e787c98ec2958ab96fbfdcea7 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 6 Nov 2023 18:21:41 -0300 Subject: [PATCH 12/22] fix: variable names --- src/content/docs/features/dialog.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index a784be96e9..d967bd3e63 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -95,12 +95,12 @@ Shows a question dialog with `Yes` and `No` buttons import { ask } from '@tauri-apps/plugin-dialog'; // Create a Yes/No dialog -const yes = await ask('This action cannot be reverted. Are you sure?', { +const answer = await ask('This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning', }); -console.log(yes); +console.log(answer); // Prints boolean to the console ``` @@ -126,12 +126,12 @@ Shows a question dialog with `Ok` and `Cancel` buttons. import { confirm } from '@tauri-apps/plugin-dialog'; // Creates a confirmation Ok/Cancel dialog -const confirmed = await confirm( +const confirmation = await confirm( 'This action cannot be reverted. Are you sure?', { title: 'Tauri', type: 'warning' } ); -console.log(confirmed); +console.log(confirmation); // Prints boolean to the console ``` @@ -224,7 +224,7 @@ const files = await open({ multiple: true, directory: false, }); -selectedFiles.forEach((file) => { +files.forEach((file) => { console.log(file); // Prints each file data to the console }); From d81e3898454d0e8e2a00985e81de12f86b809e5f Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 6 Nov 2023 22:10:26 -0300 Subject: [PATCH 13/22] reduce duplicated code --- src/content/docs/features/dialog.mdx | 92 ++-------------------------- 1 file changed, 5 insertions(+), 87 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index d967bd3e63..aa7baaf377 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -178,35 +178,13 @@ Open a file/directory selection dialog. -```js -import { open } from '@tauri-apps/plugin-dialog'; - -// Open a dialog -const file = await open(); -console.log(file); -// Prints file data to the console -``` - - - - - -{/* TODO RUST: */} - - - - -{/* OPEN > FILE */} +The `multiple` option controls whether the dialog allows multiple selection or not, while the `directory`, whether is a directory selection or not. -#### File - - - -Select single file: - - +See all [Open Dialog Options](/2/reference/js/dialog/#opendialogoptions) at the JavaScript API reference. ```js +import { open } from '@tauri-apps/plugin-dialog'; + // Open a dialog const file = await open({ multiple: false, @@ -216,74 +194,14 @@ console.log(file); // Prints file data to the console ``` -Select multiple files: - -```js -// Open a dialog -const files = await open({ - multiple: true, - directory: false, -}); -files.forEach((file) => { - console.log(file); - // Prints each file data to the console -}); -``` - - +{/* https://docs.rs/tauri-plugin-dialog/ */} {/* TODO RUST: */} - - - -{/* OPEN > DIRECTORY */} - -#### Directory - - - - - -Select directory: - -```js -// Open a dialog -const dir = await open({ - multiple: false, - directory: true, -}); -console.log(dir); -// Prints directory path -``` - -Select multiple directories: - -```js -// Open a dialog -const directories = await open({ - multiple: true, - directory: true, -}); -directories.forEach((path) => { - console.log(path); - // Prints each directory path -}); -``` - - - - - - -{/* TODO RUST: */} - - - {/* SAVE */} From b8d2898d761f948edea9009c4491b32e83819084 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Mon, 6 Nov 2023 22:11:27 -0300 Subject: [PATCH 14/22] improve "Save to" --- src/content/docs/features/dialog.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index aa7baaf377..d905d136e7 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -208,17 +208,19 @@ console.log(file); ### Save to File Dialog +Open a file/directory save dialog. + ```js import { save } from '@tauri-apps/plugin-dialog'; -// Prompt to save a 'Image' with extension .png or .jpeg +// Prompt to save a 'My Filter Label' with extension .png or .jpeg const path = await save({ filters: [ { - name: 'Image', + name: 'My Filter Label', extensions: ['png', 'jpeg'], }, ], From 4a0a669879e8793b12ff2b2255e6c6276e25498c Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Tue, 7 Nov 2023 00:05:42 -0300 Subject: [PATCH 15/22] specify return info --- src/content/docs/features/dialog.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index d905d136e7..576a8a3071 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -191,7 +191,7 @@ const file = await open({ directory: false, }); console.log(file); -// Prints file data to the console +// Prints file path and name to the console ``` From 83050845bf9ea4c14fd07e428eebcf831212b04e Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Fri, 10 Nov 2023 15:34:30 -0300 Subject: [PATCH 16/22] draft rust guide --- src/content/docs/features/dialog.mdx | 88 ++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 12 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 576a8a3071..4bc92ab97e 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -3,7 +3,6 @@ title: Dialog description: Native system dialogs for opening and saving files along with message dialogs. --- -import Stub from '@components/Stub.astro'; import PluginLinks from '@components/PluginLinks.astro'; import { Tabs, TabItem } from '@astrojs/starlight/components'; import CommandTabs from '@components/CommandTabs.astro'; @@ -107,8 +106,30 @@ console.log(answer); - -{/* TODO RUST: */} +```rust +use tauri_plugin_dialog::DialogExt; +let answer = app.dialog() + .message("Tauri is Awesome") + .title("Tauri is Awesome") + .ok_button_label("Absolutely") + .cancel_button_label("Totally") + .blocking_show(); +``` + +or instead: + +```rust +use tauri_plugin_dialog::DialogExt; +app.dialog() + .message("Tauri is Awesome") + .title("Tauri is Awesome") + .ok_button_label("Absolutely") + .cancel_button_label("Totally") + .show(|result| match result { + true => // do something, + false => // do something, + }); +``` @@ -138,8 +159,7 @@ console.log(confirmation); - -{/* TODO RUST: */} +{/* Same as Ask since in Rust there's no distiction between ask and confirm, both are constructed */} @@ -163,8 +183,27 @@ await message('File not found', { title: 'Tauri', type: 'error' }); - -{/* TODO RUST: */} +```rust +use tauri_plugin_dialog::DialogExt; +app.dialog() + .message("Tauri is Awesome") + .title("My Message") + .blocking_show(); +``` + +or instead: + +{/* TODO: Check what is the "result" supposed to be as the only return is true? or is it to check if "ok" was clicked and no closed/exited */} +```rust +use tauri_plugin_dialog::DialogExt; +app.dialog() + .message("Tauri is Awesome") + .title("My Message") + .show(|result| match result { + true => // do something, + false => // do something, + }); +``` @@ -197,9 +236,22 @@ console.log(file); - +```rust + let file_path = app.dialog().file().blocking_pick_file(); + // do something with the optional file path here + // the file path is `None` if the user closed the dialog +``` + +or, alternatively: + +```rust + app.dialog().file().pick_file(|file_path| { + // do something with the optional file path here + // the file path is `None` if the user closed the dialog + }) +``` {/* https://docs.rs/tauri-plugin-dialog/ */} -{/* TODO RUST: */} + @@ -215,7 +267,6 @@ Open a file/directory save dialog. ```js import { save } from '@tauri-apps/plugin-dialog'; - // Prompt to save a 'My Filter Label' with extension .png or .jpeg const path = await save({ filters: [ @@ -232,8 +283,21 @@ console.log(path); - -{/* TODO RUST: */} +```rust +use tauri_plugin_dialog::DialogExt; + let file_path = app.dialog().file().blocking_save_file(); + // do something with the optional file path here + // the file path is `None` if the user closed the dialog +``` + +or, alternatively: +```rust +use tauri_plugin_dialog::DialogExt; + app.dialog().file().save_file(|file_path| { + // do something with the optional file path here + // the file path is `None` if the user closed the dialog + }); +``` From 73f892f4c31b285ec6a39e94ed7b44ff259e93ca Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Thu, 16 Nov 2023 22:28:23 -0300 Subject: [PATCH 17/22] Update `dialog.mdx` --- src/content/docs/features/dialog.mdx | 76 ++++++++++++++++------------ 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 4bc92ab97e..66adbc854c 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -69,7 +69,7 @@ Install the dialog plugin to get started. ## Usage -Here's how you can use the dialog plugin: +The dialog plugin is available in both JavaScript and Rust. Here's how you can use it: - [Create Yes/No Dialog](#create-yesno-dialog) - [Create Ok/Cancel Dialog](#create-okcancel-dialog) @@ -77,15 +77,11 @@ Here's how you can use the dialog plugin: - [Open a File Selector Dialog](#open-a-file-selector-dialog) - [Save to File Dialog](#save-to-file-dialog) -{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} - -The dialog plugin is available in both JavaScript and Rust. - {/* ASK */} ### Create Yes/No Dialog -Shows a question dialog with `Yes` and `No` buttons +Shows a question dialog with `Yes` and `No` buttons. @@ -108,6 +104,7 @@ console.log(answer); ```rust use tauri_plugin_dialog::DialogExt; + let answer = app.dialog() .message("Tauri is Awesome") .title("Tauri is Awesome") @@ -116,10 +113,11 @@ let answer = app.dialog() .blocking_show(); ``` -or instead: +If you need a non blocking operation you can use `show()` instead: ```rust use tauri_plugin_dialog::DialogExt; + app.dialog() .message("Tauri is Awesome") .title("Tauri is Awesome") @@ -127,7 +125,7 @@ app.dialog() .cancel_button_label("Totally") .show(|result| match result { true => // do something, - false => // do something, + false =>// do else, }); ``` @@ -184,21 +182,24 @@ await message('File not found', { title: 'Tauri', type: 'error' }); ```rust -use tauri_plugin_dialog::DialogExt; +use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; + app.dialog() - .message("Tauri is Awesome") - .title("My Message") - .blocking_show(); + .message("File not found") + .kind(MessageDialogKind::Error) + .title("Warning") + .blocking_show(); ``` -or instead: +If you need a non blocking operation you can use `show()` instead: -{/* TODO: Check what is the "result" supposed to be as the only return is true? or is it to check if "ok" was clicked and no closed/exited */} ```rust -use tauri_plugin_dialog::DialogExt; +use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; + app.dialog() .message("Tauri is Awesome") - .title("My Message") + .kind(MessageDialogKind::Error) + .title("Warning") .show(|result| match result { true => // do something, false => // do something, @@ -237,21 +238,21 @@ console.log(file); ```rust - let file_path = app.dialog().file().blocking_pick_file(); - // do something with the optional file path here - // the file path is `None` if the user closed the dialog +use tauri_plugin_dialog::DialogExt; + +let file_path = app.dialog().file().blocking_pick_file(); +// return a file_path `Option`, or `None` if the user closes the dialog ``` -or, alternatively: +If you need a non blocking operation you can use `show()` instead: ```rust - app.dialog().file().pick_file(|file_path| { - // do something with the optional file path here - // the file path is `None` if the user closed the dialog - }) -``` -{/* https://docs.rs/tauri-plugin-dialog/ */} +use tauri_plugin_dialog::DialogExt; +app.dialog().file().pick_file(|file_path| { + // return a file_path `Option`, or `None` if the user closes the dialog + }) +``` @@ -267,11 +268,11 @@ Open a file/directory save dialog. ```js import { save } from '@tauri-apps/plugin-dialog'; -// Prompt to save a 'My Filter Label' with extension .png or .jpeg +// Prompt to save a 'My Filter' with extension .png or .jpeg const path = await save({ filters: [ { - name: 'My Filter Label', + name: 'My Filter', extensions: ['png', 'jpeg'], }, ], @@ -285,7 +286,12 @@ console.log(path); ```rust use tauri_plugin_dialog::DialogExt; - let file_path = app.dialog().file().blocking_save_file(); + +let file_path = app + .dialog() + .file() + .add_filter("My Filter", &["png", "jpeg"]) + .blocking_save_file(); // do something with the optional file path here // the file path is `None` if the user closed the dialog ``` @@ -294,10 +300,14 @@ or, alternatively: ```rust use tauri_plugin_dialog::DialogExt; - app.dialog().file().save_file(|file_path| { - // do something with the optional file path here - // the file path is `None` if the user closed the dialog - }); + +app.dialog() + .file() + .add_filter("My Filter", &["png", "jpeg"]) + .pick_file(|result| { + println!("{:?}", result); + }); ``` + From 25d93bd28dd791223c09db5ec22205366bf82e40 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Wed, 29 Nov 2023 20:19:21 -0300 Subject: [PATCH 18/22] refactor `dialog.mdx` --- src/content/docs/features/dialog.mdx | 209 ++++++++++++--------------- 1 file changed, 94 insertions(+), 115 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 66adbc854c..5b066e3ecf 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -71,21 +71,26 @@ Install the dialog plugin to get started. The dialog plugin is available in both JavaScript and Rust. Here's how you can use it: +in JavaScript: - [Create Yes/No Dialog](#create-yesno-dialog) - [Create Ok/Cancel Dialog](#create-okcancel-dialog) - [Create Message Dialog](#create-message-dialog) - [Open a File Selector Dialog](#open-a-file-selector-dialog) - [Save to File Dialog](#save-to-file-dialog) -{/* ASK */} +in Rust: +- [Build an Ask Dialog](#build-an-ask-dialog) +- [Build a Message Dialog](#build-a-message-dialog) +- [Build a File Selector Dialog](#build-a-file-selector-dialog) + +*** +## JavaScript +{/* ASK */} ### Create Yes/No Dialog Shows a question dialog with `Yes` and `No` buttons. - - - ```js import { ask } from '@tauri-apps/plugin-dialog'; @@ -99,48 +104,12 @@ console.log(answer); // Prints boolean to the console ``` - - - -```rust -use tauri_plugin_dialog::DialogExt; - -let answer = app.dialog() - .message("Tauri is Awesome") - .title("Tauri is Awesome") - .ok_button_label("Absolutely") - .cancel_button_label("Totally") - .blocking_show(); -``` - -If you need a non blocking operation you can use `show()` instead: - -```rust -use tauri_plugin_dialog::DialogExt; - -app.dialog() - .message("Tauri is Awesome") - .title("Tauri is Awesome") - .ok_button_label("Absolutely") - .cancel_button_label("Totally") - .show(|result| match result { - true => // do something, - false =>// do else, - }); -``` - - - - {/* CONFIRM */} ### Create Ok/Cancel Dialog Shows a question dialog with `Ok` and `Cancel` buttons. - - - ```js import { confirm } from '@tauri-apps/plugin-dialog'; @@ -153,24 +122,12 @@ const confirmation = await confirm( console.log(confirmation); // Prints boolean to the console ``` - - - - -{/* Same as Ask since in Rust there's no distiction between ask and confirm, both are constructed */} - - - - {/* MESSAGE */} ### Create Message Dialog Shows a message dialog with an `Ok` button. - - - ```js import { message } from '@tauri-apps/plugin-dialog'; @@ -178,8 +135,87 @@ import { message } from '@tauri-apps/plugin-dialog'; await message('File not found', { title: 'Tauri', type: 'error' }); ``` - - +{/* OPEN */} + +### Open a File Selector Dialog + +Open a file/directory selection dialog. + +The `multiple` option controls whether the dialog allows multiple selection or not, while the `directory`, whether is a directory selection or not. + +See all [Open Dialog Options](/2/reference/js/dialog/#opendialogoptions) at the JavaScript API reference. + +```js +import { open } from '@tauri-apps/plugin-dialog'; + +// Open a dialog +const file = await open({ + multiple: false, + directory: false, +}); +console.log(file); +// Prints file path and name to the console +``` + +{/* SAVE */} + +### Save to File Dialog + +Open a file/directory save dialog. + + +```js +import { save } from '@tauri-apps/plugin-dialog'; +// Prompt to save a 'My Filter' with extension .png or .jpeg +const path = await save({ + filters: [ + { + name: 'My Filter', + extensions: ['png', 'jpeg'], + }, + ], +}); +console.log(path); +// Prints the chosen path +``` + +*** +## Rust + +### Build an Ask Dialog + +Shows a question dialog with `Absolutely` and `Totally` buttons. + +```rust +use tauri_plugin_dialog::DialogExt; + +let answer = app.dialog() + .message("Tauri is Awesome") + .title("Tauri is Awesome") + .ok_button_label("Absolutely") + .cancel_button_label("Totally") + .blocking_show(); +``` + +If you need a non blocking operation you can use `show()` instead: + +```rust +use tauri_plugin_dialog::DialogExt; + +app.dialog() + .message("Tauri is Awesome") + .title("Tauri is Awesome") + .ok_button_label("Absolutely") + .cancel_button_label("Totally") + .show(|result| match result { + true => // do something, + false =>// do something, + }); +``` + +### Build a Message Dialog + +Shows a message dialog with an `Ok` button. ```rust use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; @@ -206,37 +242,11 @@ app.dialog() }); ``` - - - -{/* OPEN */} - -### Open a File Selector Dialog -Open a file/directory selection dialog. +### Build a File Selector Dialog - - - -The `multiple` option controls whether the dialog allows multiple selection or not, while the `directory`, whether is a directory selection or not. - -See all [Open Dialog Options](/2/reference/js/dialog/#opendialogoptions) at the JavaScript API reference. - -```js -import { open } from '@tauri-apps/plugin-dialog'; - -// Open a dialog -const file = await open({ - multiple: false, - directory: false, -}); -console.log(file); -// Prints file path and name to the console -``` - - - +#### Pick files ```rust use tauri_plugin_dialog::DialogExt; @@ -254,35 +264,7 @@ app.dialog().file().pick_file(|file_path| { }) ``` - - - -{/* SAVE */} - -### Save to File Dialog - -Open a file/directory save dialog. - - - - -```js -import { save } from '@tauri-apps/plugin-dialog'; -// Prompt to save a 'My Filter' with extension .png or .jpeg -const path = await save({ - filters: [ - { - name: 'My Filter', - extensions: ['png', 'jpeg'], - }, - ], -}); -console.log(path); -// Prints the chosen path -``` - - - +#### Save files ```rust use tauri_plugin_dialog::DialogExt; @@ -307,7 +289,4 @@ app.dialog() .pick_file(|result| { println!("{:?}", result); }); -``` - - - +``` \ No newline at end of file From 1ec5a0471fca5a1714904d375afd8b12cb35543c Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Wed, 29 Nov 2023 20:39:34 -0300 Subject: [PATCH 19/22] Update dialog.mdx --- src/content/docs/features/dialog.mdx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 5b066e3ecf..9c3b4f2379 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -220,7 +220,7 @@ Shows a message dialog with an `Ok` button. ```rust use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; -app.dialog() +let ans = app.dialog() .message("File not found") .kind(MessageDialogKind::Error) .title("Warning") @@ -234,8 +234,8 @@ use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; app.dialog() .message("Tauri is Awesome") - .kind(MessageDialogKind::Error) - .title("Warning") + .kind(MessageDialogKind::Info) + .title("Information") .show(|result| match result { true => // do something, false => // do something, @@ -246,7 +246,7 @@ app.dialog() ### Build a File Selector Dialog -#### Pick files +#### Pick Files ```rust use tauri_plugin_dialog::DialogExt; @@ -264,7 +264,7 @@ app.dialog().file().pick_file(|file_path| { }) ``` -#### Save files +#### Save Files ```rust use tauri_plugin_dialog::DialogExt; @@ -286,7 +286,7 @@ use tauri_plugin_dialog::DialogExt; app.dialog() .file() .add_filter("My Filter", &["png", "jpeg"]) - .pick_file(|result| { - println!("{:?}", result); + .pick_file(|file_path| { + // return a file_path `Option`, or `None` if the user closes the dialog }); ``` \ No newline at end of file From d0b55121378ce118bdfdd87ee88dc2ca88232a4a Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Wed, 29 Nov 2023 20:52:28 -0300 Subject: [PATCH 20/22] add notes and api links to body --- src/content/docs/features/dialog.mdx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 9c3b4f2379..282daba1b7 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -86,6 +86,8 @@ in Rust: *** ## JavaScript +See all [Dialog Options](/2/reference/js/dialog/) at the JavaScript API reference. + {/* ASK */} ### Create Yes/No Dialog @@ -126,7 +128,7 @@ console.log(confirmation); ### Create Message Dialog -Shows a message dialog with an `Ok` button. +Shows a message dialog with an `Ok` button. Keep in mind that if the user closes the dialog it will return `false`. ```js import { message } from '@tauri-apps/plugin-dialog'; @@ -143,8 +145,6 @@ Open a file/directory selection dialog. The `multiple` option controls whether the dialog allows multiple selection or not, while the `directory`, whether is a directory selection or not. -See all [Open Dialog Options](/2/reference/js/dialog/#opendialogoptions) at the JavaScript API reference. - ```js import { open } from '@tauri-apps/plugin-dialog'; @@ -163,7 +163,6 @@ console.log(file); Open a file/directory save dialog. - ```js import { save } from '@tauri-apps/plugin-dialog'; // Prompt to save a 'My Filter' with extension .png or .jpeg @@ -182,6 +181,8 @@ console.log(path); *** ## Rust +Refer to the [Rust API reference](https://docs.rs/tauri-plugin-dialog/) to see all available options. + ### Build an Ask Dialog Shows a question dialog with `Absolutely` and `Totally` buttons. @@ -215,7 +216,7 @@ app.dialog() ### Build a Message Dialog -Shows a message dialog with an `Ok` button. +Shows a message dialog with an `Ok` button. Keep in mind that if the user closes the dialog it will return `false`. ```rust use tauri_plugin_dialog::{DialogExt, MessageDialogKind}; @@ -236,6 +237,7 @@ app.dialog() .message("Tauri is Awesome") .kind(MessageDialogKind::Info) .title("Information") + .ok_button_label("Absolutely") .show(|result| match result { true => // do something, false => // do something, From b2a5befaac37b2cfedbcede385929ec127f75958 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Thu, 30 Nov 2023 12:57:43 -0300 Subject: [PATCH 21/22] fix headings --- src/content/docs/features/dialog.mdx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index 282daba1b7..a1e34f0c57 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -1,6 +1,8 @@ --- title: Dialog description: Native system dialogs for opening and saving files along with message dialogs. +tableOfContents: + maxHeadingLevel: 4 --- import PluginLinks from '@components/PluginLinks.astro'; @@ -84,12 +86,12 @@ in Rust: - [Build a File Selector Dialog](#build-a-file-selector-dialog) *** -## JavaScript +### JavaScript See all [Dialog Options](/2/reference/js/dialog/) at the JavaScript API reference. {/* ASK */} -### Create Yes/No Dialog +#### Create Yes/No Dialog Shows a question dialog with `Yes` and `No` buttons. @@ -108,7 +110,7 @@ console.log(answer); {/* CONFIRM */} -### Create Ok/Cancel Dialog +#### Create Ok/Cancel Dialog Shows a question dialog with `Ok` and `Cancel` buttons. @@ -126,7 +128,7 @@ console.log(confirmation); ``` {/* MESSAGE */} -### Create Message Dialog +#### Create Message Dialog Shows a message dialog with an `Ok` button. Keep in mind that if the user closes the dialog it will return `false`. @@ -139,7 +141,7 @@ await message('File not found', { title: 'Tauri', type: 'error' }); {/* OPEN */} -### Open a File Selector Dialog +#### Open a File Selector Dialog Open a file/directory selection dialog. @@ -159,7 +161,7 @@ console.log(file); {/* SAVE */} -### Save to File Dialog +#### Save to File Dialog Open a file/directory save dialog. @@ -179,11 +181,11 @@ console.log(path); ``` *** -## Rust +### Rust Refer to the [Rust API reference](https://docs.rs/tauri-plugin-dialog/) to see all available options. -### Build an Ask Dialog +#### Build an Ask Dialog Shows a question dialog with `Absolutely` and `Totally` buttons. @@ -214,7 +216,7 @@ app.dialog() }); ``` -### Build a Message Dialog +#### Build a Message Dialog Shows a message dialog with an `Ok` button. Keep in mind that if the user closes the dialog it will return `false`. @@ -245,7 +247,7 @@ app.dialog() ``` -### Build a File Selector Dialog +#### Build a File Selector Dialog #### Pick Files From 014a5dad935b2499a6736086566595c69880ef84 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Thu, 30 Nov 2023 12:59:39 -0300 Subject: [PATCH 22/22] i18nReady --- src/content/docs/features/dialog.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content/docs/features/dialog.mdx b/src/content/docs/features/dialog.mdx index a1e34f0c57..631254512b 100644 --- a/src/content/docs/features/dialog.mdx +++ b/src/content/docs/features/dialog.mdx @@ -1,6 +1,7 @@ --- title: Dialog description: Native system dialogs for opening and saving files along with message dialogs. +i18nReady: true tableOfContents: maxHeadingLevel: 4 ---