Skip to content

Commit 5c95152

Browse files
refactor!: take id for text/check/icon on menu builders (#7621)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 6177150 commit 5c95152

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:breaking'
3+
---
4+
5+
Changed `MenuBuilder\SubmenuBuilder::text`, `MenuBuilder\SubmenuBuilder::check`, `MenuBuilder\SubmenuBuilder::icon` and `MenuBuilder\SubmenuBuilder::native_icon` to take an `id` as the first argument.

core/tauri/src/menu/builders/menu.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use crate::{menu::*, Icon, Manager, Runtime};
2929
/// .copy()
3030
/// .paste()
3131
/// .separator()
32-
/// .text("MenuItem 2")
33-
/// .check("CheckMenuItem 2")
34-
/// .icon("IconMenuItem 2", app.default_window_icon().cloned().unwrap())
32+
/// .text("item2", "MenuItem 2")
33+
/// .check("checkitem2", "CheckMenuItem 2")
34+
/// .icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
3535
/// .build()?;
3636
/// app.set_menu(menu);
3737
/// Ok(())
@@ -83,26 +83,26 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
8383
}
8484

8585
/// Add a [MenuItem] to the menu.
86-
pub fn text<S: AsRef<str>>(mut self, text: S) -> Self {
86+
pub fn text<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
8787
self
8888
.items
89-
.push(MenuItem::new(self.manager, text, true, None).kind());
89+
.push(MenuItem::with_id(self.manager, id, text, true, None).kind());
9090
self
9191
}
9292

9393
/// Add a [CheckMenuItem] to the menu.
94-
pub fn check<S: AsRef<str>>(mut self, text: S) -> Self {
94+
pub fn check<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
9595
self
9696
.items
97-
.push(CheckMenuItem::new(self.manager, text, true, true, None).kind());
97+
.push(CheckMenuItem::with_id(self.manager, id, text, true, true, None).kind());
9898
self
9999
}
100100

101101
/// Add an [IconMenuItem] to the menu.
102-
pub fn icon<S: AsRef<str>>(mut self, text: S, icon: Icon) -> Self {
102+
pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Icon) -> Self {
103103
self
104104
.items
105-
.push(IconMenuItem::new(self.manager, text, true, Some(icon), None).kind());
105+
.push(IconMenuItem::with_id(self.manager, id, text, true, Some(icon), None).kind());
106106
self
107107
}
108108

@@ -111,10 +111,15 @@ impl<'m, R: Runtime, M: Manager<R>> MenuBuilder<'m, R, M> {
111111
/// ## Platform-specific:
112112
///
113113
/// - **Windows / Linux**: Unsupported.
114-
pub fn native_icon<S: AsRef<str>>(mut self, text: S, icon: NativeIcon) -> Self {
115-
self
116-
.items
117-
.push(IconMenuItem::with_native_icon(self.manager, text, true, Some(icon), None).kind());
114+
pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
115+
mut self,
116+
id: I,
117+
text: S,
118+
icon: NativeIcon,
119+
) -> Self {
120+
self.items.push(
121+
IconMenuItem::with_id_and_native_icon(self.manager, id, text, true, Some(icon), None).kind(),
122+
);
118123
self
119124
}
120125

core/tauri/src/menu/builders/submenu.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ use crate::{menu::*, Icon, Manager, Runtime};
3131
/// .copy()
3232
/// .paste()
3333
/// .separator()
34-
/// .text("MenuItem 2")
35-
/// .check("CheckMenuItem 2")
36-
/// .icon("IconMenuItem 2", app.default_window_icon().cloned().unwrap())
34+
/// .text("item2", "MenuItem 2")
35+
/// .check("checkitem2", "CheckMenuItem 2")
36+
/// .icon("iconitem2", "IconMenuItem 2", app.default_window_icon().cloned().unwrap())
3737
/// .build()?;
3838
/// menu.append(&submenu)?;
3939
/// app.set_menu(menu);
@@ -104,26 +104,26 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
104104
}
105105

106106
/// Add a [MenuItem] to the submenu.
107-
pub fn text<S: AsRef<str>>(mut self, text: S) -> Self {
107+
pub fn text<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
108108
self
109109
.items
110-
.push(MenuItem::new(self.manager, text, true, None).kind());
110+
.push(MenuItem::with_id(self.manager, id, text, true, None).kind());
111111
self
112112
}
113113

114114
/// Add a [CheckMenuItem] to the submenu.
115-
pub fn check<S: AsRef<str>>(mut self, text: S) -> Self {
115+
pub fn check<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S) -> Self {
116116
self
117117
.items
118-
.push(CheckMenuItem::new(self.manager, text, true, true, None).kind());
118+
.push(CheckMenuItem::with_id(self.manager, id, text, true, true, None).kind());
119119
self
120120
}
121121

122122
/// Add an [IconMenuItem] to the submenu.
123-
pub fn icon<S: AsRef<str>>(mut self, text: S, icon: Icon) -> Self {
123+
pub fn icon<I: Into<MenuId>, S: AsRef<str>>(mut self, id: I, text: S, icon: Icon) -> Self {
124124
self
125125
.items
126-
.push(IconMenuItem::new(self.manager, text, true, Some(icon), None).kind());
126+
.push(IconMenuItem::with_id(self.manager, id, text, true, Some(icon), None).kind());
127127
self
128128
}
129129

@@ -132,10 +132,15 @@ impl<'m, R: Runtime, M: Manager<R>> SubmenuBuilder<'m, R, M> {
132132
/// ## Platform-specific:
133133
///
134134
/// - **Windows / Linux**: Unsupported.
135-
pub fn native_icon<S: AsRef<str>>(mut self, text: S, icon: NativeIcon) -> Self {
136-
self
137-
.items
138-
.push(IconMenuItem::with_native_icon(self.manager, text, true, Some(icon), None).kind());
135+
pub fn native_icon<I: Into<MenuId>, S: AsRef<str>>(
136+
mut self,
137+
id: I,
138+
text: S,
139+
icon: NativeIcon,
140+
) -> Self {
141+
self.items.push(
142+
IconMenuItem::with_id_and_native_icon(self.manager, id, text, true, Some(icon), None).kind(),
143+
);
139144
self
140145
}
141146

0 commit comments

Comments
 (0)