refactor!: take id for text/check/icon on menu builders (#7621)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Amr Bashir 2023-08-16 17:55:36 +03:00 committed by GitHub
parent 6177150b6f
commit 5c95152c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 26 deletions

View File

@ -0,0 +1,5 @@
---
'tauri': 'patch:breaking'
---
Changed `MenuBuilder\SubmenuBuilder::text`, `MenuBuilder\SubmenuBuilder::check`, `MenuBuilder\SubmenuBuilder::icon` and `MenuBuilder\SubmenuBuilder::native_icon` to take an `id` as the first argument.

View File

@ -29,9 +29,9 @@ use crate::{menu::*, Icon, Manager, Runtime};
/// .copy() /// .copy()
/// .paste() /// .paste()
/// .separator() /// .separator()
/// .text("MenuItem 2") /// .text("item2", "MenuItem 2")
/// .check("CheckMenuItem 2") /// .check("checkitem2", "CheckMenuItem 2")
/// .icon("IconMenuItem 2", app.default_window_icon().cloned().unwrap()) /// .icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
/// .build()?; /// .build()?;
/// app.set_menu(menu); /// app.set_menu(menu);
/// Ok(()) /// Ok(())
@ -83,26 +83,26 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
} }
/// Add a [MenuItem] to the menu. /// Add a [MenuItem] to the menu.
pub fn text<S: AsRef<str>>(mut self, text: S) -> Self { pub fn text<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
self self
.items .items
.push(MenuItem::new(self.manager, text, true, None).kind()); .push(MenuItem::with_id(self.manager, id, text, true, None).kind());
self self
} }
/// Add a [CheckMenuItem] to the menu. /// Add a [CheckMenuItem] to the menu.
pub fn check<S: AsRef<str>>(mut self, text: S) -> Self { pub fn check<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
self self
.items .items
.push(CheckMenuItem::new(self.manager, text, true, true, None).kind()); .push(CheckMenuItem::with_id(self.manager, id, text, true, true, None).kind());
self self
} }
/// Add an [IconMenuItem] to the menu. /// Add an [IconMenuItem] to the menu.
pub fn icon<S: AsRef<str>>(mut self, text: S, icon: Icon) -> Self { pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Icon) -> Self {
self self
.items .items
.push(IconMenuItem::new(self.manager, text, true, Some(icon), None).kind()); .push(IconMenuItem::with_id(self.manager, id, text, true, Some(icon), None).kind());
self self
} }
@ -111,10 +111,15 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
/// ## Platform-specific: /// ## Platform-specific:
/// ///
/// - **Windows / Linux**: Unsupported. /// - **Windows / Linux**: Unsupported.
pub fn native_icon<S: AsRef<str>>(mut self, text: S, icon: NativeIcon) -> Self { pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
self mut self,
.items id: I,
.push(IconMenuItem::with_native_icon(self.manager, text, true, Some(icon), None).kind()); text: S,
icon: NativeIcon,
) -> Self {
self.items.push(
IconMenuItem::with_id_and_native_icon(self.manager, id, text, true, Some(icon), None).kind(),
);
self self
} }

View File

@ -31,9 +31,9 @@ use crate::{menu::*, Icon, Manager, Runtime};
/// .copy() /// .copy()
/// .paste() /// .paste()
/// .separator() /// .separator()
/// .text("MenuItem 2") /// .text("item2", "MenuItem 2")
/// .check("CheckMenuItem 2") /// .check("checkitem2", "CheckMenuItem 2")
/// .icon("IconMenuItem 2", app.default_window_icon().cloned().unwrap()) /// .icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
/// .build()?; /// .build()?;
/// menu.append(&submenu)?; /// menu.append(&submenu)?;
/// app.set_menu(menu); /// app.set_menu(menu);
@ -104,26 +104,26 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
} }
/// Add a [MenuItem] to the submenu. /// Add a [MenuItem] to the submenu.
pub fn text<S: AsRef<str>>(mut self, text: S) -> Self { pub fn text<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
self self
.items .items
.push(MenuItem::new(self.manager, text, true, None).kind()); .push(MenuItem::with_id(self.manager, id, text, true, None).kind());
self self
} }
/// Add a [CheckMenuItem] to the submenu. /// Add a [CheckMenuItem] to the submenu.
pub fn check<S: AsRef<str>>(mut self, text: S) -> Self { pub fn check<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
self self
.items .items
.push(CheckMenuItem::new(self.manager, text, true, true, None).kind()); .push(CheckMenuItem::with_id(self.manager, id, text, true, true, None).kind());
self self
} }
/// Add an [IconMenuItem] to the submenu. /// Add an [IconMenuItem] to the submenu.
pub fn icon<S: AsRef<str>>(mut self, text: S, icon: Icon) -> Self { pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Icon) -> Self {
self self
.items .items
.push(IconMenuItem::new(self.manager, text, true, Some(icon), None).kind()); .push(IconMenuItem::with_id(self.manager, id, text, true, Some(icon), None).kind());
self self
} }
@ -132,10 +132,15 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
/// ## Platform-specific: /// ## Platform-specific:
/// ///
/// - **Windows / Linux**: Unsupported. /// - **Windows / Linux**: Unsupported.
pub fn native_icon<S: AsRef<str>>(mut self, text: S, icon: NativeIcon) -> Self { pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
self mut self,
.items id: I,
.push(IconMenuItem::with_native_icon(self.manager, text, true, Some(icon), None).kind()); text: S,
icon: NativeIcon,
) -> Self {
self.items.push(
IconMenuItem::with_id_and_native_icon(self.manager, id, text, true, Some(icon), None).kind(),
);
self self
} }