add title & enabled getters

This commit is contained in:
amrbashir 2022-05-06 17:18:34 +02:00
parent 0fbc8cf4f4
commit bac4dbd1ab
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33
2 changed files with 32 additions and 0 deletions

View file

@ -40,10 +40,18 @@ impl Menu {
pub struct Submenu(platform_impl::Submenu); pub struct Submenu(platform_impl::Submenu);
impl Submenu { impl Submenu {
pub fn label(&self) -> String {
self.0.label()
}
pub fn set_label(&mut self, label: impl AsRef<str>) { pub fn set_label(&mut self, label: impl AsRef<str>) {
self.0.set_label(label) self.0.set_label(label)
} }
pub fn enabled(&self) -> bool {
self.0.enabled()
}
pub fn set_enabled(&mut self, enabled: bool) { pub fn set_enabled(&mut self, enabled: bool) {
self.0.set_enabled(enabled) self.0.set_enabled(enabled)
} }
@ -60,10 +68,18 @@ impl Submenu {
pub struct TextMenuItem(platform_impl::TextMenuItem); pub struct TextMenuItem(platform_impl::TextMenuItem);
impl TextMenuItem { impl TextMenuItem {
pub fn label(&self) -> String {
self.0.label()
}
pub fn set_label(&mut self, label: impl AsRef<str>) { pub fn set_label(&mut self, label: impl AsRef<str>) {
self.0.set_label(label) self.0.set_label(label)
} }
pub fn enabled(&self) -> bool {
self.0.enabled()
}
pub fn set_enabled(&mut self, enabled: bool) { pub fn set_enabled(&mut self, enabled: bool) {
self.0.set_enabled(enabled) self.0.set_enabled(enabled)
} }

View file

@ -105,6 +105,10 @@ fn add_entries_to_menu<M: IsA<gtk::MenuShell>>(gtk_menu: &M, entries: &Vec<Arc<M
pub struct Submenu(Arc<Mutex<MenuEntry>>); pub struct Submenu(Arc<Mutex<MenuEntry>>);
impl Submenu { impl Submenu {
pub fn label(&self) -> String {
self.0.lock().label.clone()
}
pub fn set_label(&mut self, label: impl AsRef<str>) { pub fn set_label(&mut self, label: impl AsRef<str>) {
let label = label.as_ref().to_string(); let label = label.as_ref().to_string();
let mut entry = self.0.lock(); let mut entry = self.0.lock();
@ -114,6 +118,10 @@ impl Submenu {
entry.label = label; entry.label = label;
} }
pub fn enabled(&self) -> bool {
self.0.lock().enabled
}
pub fn set_enabled(&mut self, enabled: bool) { pub fn set_enabled(&mut self, enabled: bool) {
let mut entry = self.0.lock(); let mut entry = self.0.lock();
entry.enabled = true; entry.enabled = true;
@ -155,6 +163,10 @@ impl Submenu {
pub struct TextMenuItem(Arc<Mutex<MenuEntry>>); pub struct TextMenuItem(Arc<Mutex<MenuEntry>>);
impl TextMenuItem { impl TextMenuItem {
pub fn label(&self) -> String {
self.0.lock().label.clone()
}
pub fn set_label(&mut self, label: impl AsRef<str>) { pub fn set_label(&mut self, label: impl AsRef<str>) {
let label = label.as_ref().to_string(); let label = label.as_ref().to_string();
let mut entry = self.0.lock(); let mut entry = self.0.lock();
@ -164,6 +176,10 @@ impl TextMenuItem {
entry.label = label; entry.label = label;
} }
pub fn enabled(&self) -> bool {
self.0.lock().enabled
}
pub fn set_enabled(&mut self, enabled: bool) { pub fn set_enabled(&mut self, enabled: bool) {
let mut entry = self.0.lock(); let mut entry = self.0.lock();
for item in entry.item_gtk_items.as_ref().unwrap().lock().iter() { for item in entry.item_gtk_items.as_ref().unwrap().lock().iter() {