Skip to content

Commit

Permalink
refactor!: take id for text/check/icon on menu builders (#7621)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
amrbashir and lucasfernog authored Aug 16, 2023
1 parent 6177150 commit 5c95152
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changes/submenu-and-menu-builders-item-and-id.md
Original file line number Diff line number Diff line change
@@ -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.
31 changes: 18 additions & 13 deletions core/tauri/src/menu/builders/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use crate::{menu::*, Icon, Manager, Runtime};
/// .copy()
/// .paste()
/// .separator()
/// .text("MenuItem 2")
/// .check("CheckMenuItem 2")
/// .icon("IconMenuItem 2", app.default_window_icon().cloned().unwrap())
/// .text("item2", "MenuItem 2")
/// .check("checkitem2", "CheckMenuItem 2")
/// .icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
/// .build()?;
/// app.set_menu(menu);
/// Ok(())
Expand Down Expand Up @@ -83,26 +83,26 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
}

/// 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
.items
.push(MenuItem::new(self.manager, text, true, None).kind());
.push(MenuItem::with_id(self.manager, id, text, true, None).kind());
self
}

/// 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
.items
.push(CheckMenuItem::new(self.manager, text, true, true, None).kind());
.push(CheckMenuItem::with_id(self.manager, id, text, true, true, None).kind());
self
}

/// 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
.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
}

Expand All @@ -111,10 +111,15 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
/// ## Platform-specific:
///
/// - **Windows / Linux**: Unsupported.
pub fn native_icon<S: AsRef<str>>(mut self, text: S, icon: NativeIcon) -> Self {
self
.items
.push(IconMenuItem::with_native_icon(self.manager, text, true, Some(icon), None).kind());
pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
mut self,
id: I,
text: S,
icon: NativeIcon,
) -> Self {
self.items.push(
IconMenuItem::with_id_and_native_icon(self.manager, id, text, true, Some(icon), None).kind(),
);
self
}

Expand Down
31 changes: 18 additions & 13 deletions core/tauri/src/menu/builders/submenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use crate::{menu::*, Icon, Manager, Runtime};
/// .copy()
/// .paste()
/// .separator()
/// .text("MenuItem 2")
/// .check("CheckMenuItem 2")
/// .icon("IconMenuItem 2", app.default_window_icon().cloned().unwrap())
/// .text("item2", "MenuItem 2")
/// .check("checkitem2", "CheckMenuItem 2")
/// .icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
/// .build()?;
/// menu.append(&submenu)?;
/// app.set_menu(menu);
Expand Down Expand Up @@ -104,26 +104,26 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
}

/// 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
.items
.push(MenuItem::new(self.manager, text, true, None).kind());
.push(MenuItem::with_id(self.manager, id, text, true, None).kind());
self
}

/// 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
.items
.push(CheckMenuItem::new(self.manager, text, true, true, None).kind());
.push(CheckMenuItem::with_id(self.manager, id, text, true, true, None).kind());
self
}

/// 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
.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
}

Expand All @@ -132,10 +132,15 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
/// ## Platform-specific:
///
/// - **Windows / Linux**: Unsupported.
pub fn native_icon<S: AsRef<str>>(mut self, text: S, icon: NativeIcon) -> Self {
self
.items
.push(IconMenuItem::with_native_icon(self.manager, text, true, Some(icon), None).kind());
pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
mut self,
id: I,
text: S,
icon: NativeIcon,
) -> Self {
self.items.push(
IconMenuItem::with_id_and_native_icon(self.manager, id, text, true, Some(icon), None).kind(),
);
self
}

Expand Down

0 comments on commit 5c95152

Please sign in to comment.