mirror of
https://github.com/italicsjenga/muda.git
synced 2024-12-23 12:01:31 +11:00
feat: add Menu/Submenu::remove_at
(#93)
This commit is contained in:
parent
8c2019eba0
commit
043026c30d
5
.changes/remove_at.md
Normal file
5
.changes/remove_at.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"muda": "patch"
|
||||
---
|
||||
|
||||
Add `Menu/Submenu::remove_at` to remove an item at specified index.
|
|
@ -132,6 +132,18 @@ impl Submenu {
|
|||
self.inner.borrow_mut().remove(item)
|
||||
}
|
||||
|
||||
/// Remove the menu item at the specified position from this submenu.
|
||||
pub fn remove_at(&self, position: usize) -> Option<MenuItemKind> {
|
||||
let mut items = self.items();
|
||||
if items.len() > position {
|
||||
let item = items.remove(position);
|
||||
let _ = self.remove(item.as_ref());
|
||||
Some(item)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a list of menu items that has been added to this submenu.
|
||||
pub fn items(&self) -> Vec<MenuItemKind> {
|
||||
self.inner.borrow().items()
|
||||
|
@ -159,8 +171,6 @@ impl Submenu {
|
|||
self.inner.borrow_mut().set_enabled(enabled)
|
||||
}
|
||||
|
||||
// TODO: in a minor release, rename the following two functions to be `set_as_*`
|
||||
|
||||
/// Set this submenu as the Window menu for the application on macOS.
|
||||
///
|
||||
/// This will cause macOS to automatically add window-switching items and
|
||||
|
|
12
src/menu.rs
12
src/menu.rs
|
@ -144,6 +144,18 @@ impl Menu {
|
|||
self.inner.borrow_mut().remove(item)
|
||||
}
|
||||
|
||||
/// Remove the menu item at the specified position from this menu.
|
||||
pub fn remove_at(&self, position: usize) -> Option<MenuItemKind> {
|
||||
let mut items = self.items();
|
||||
if items.len() > position {
|
||||
let item = items.remove(position);
|
||||
let _ = self.remove(item.as_ref());
|
||||
Some(item)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a list of menu items that has been added to this menu.
|
||||
pub fn items(&self) -> Vec<MenuItemKind> {
|
||||
self.inner.borrow().items()
|
||||
|
|
Loading…
Reference in a new issue