Split code into method
This commit is contained in:
parent
d926d449b3
commit
3d85922fcc
1 changed files with 30 additions and 26 deletions
|
|
@ -77,8 +77,25 @@ impl StatusMenu {
|
||||||
let menu = item.menu().unwrap(); // XXX unwrap?
|
let menu = item.menu().unwrap(); // XXX unwrap?
|
||||||
let layout = menu.get_layout(0, -1, &[]).await?.1;
|
let layout = menu.get_layout(0, -1, &[]).await?.1;
|
||||||
|
|
||||||
menu.connect_layout_updated(clone!(@weak obj => move |_revision, parent| {
|
menu.connect_layout_updated(clone!(@weak obj => move |revision, parent| {
|
||||||
let mut menus = obj.inner().menus.borrow_mut();
|
obj.layout_updated(revision, parent);
|
||||||
|
}));
|
||||||
|
|
||||||
|
obj.inner().item.set(item);
|
||||||
|
obj.inner().dbus_menu.set(menu);
|
||||||
|
|
||||||
|
println!("{:#?}", layout);
|
||||||
|
obj.populate_menu(&obj.inner().vbox, &layout);
|
||||||
|
|
||||||
|
Ok(obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inner(&self) -> &StatusMenuInner {
|
||||||
|
StatusMenuInner::from_instance(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layout_updated(&self, _revision: u32, parent: i32) {
|
||||||
|
let mut menus = self.inner().menus.borrow_mut();
|
||||||
|
|
||||||
if let Some(Menu { box_, children }) = menus.remove(&parent) {
|
if let Some(Menu { box_, children }) = menus.remove(&parent) {
|
||||||
let mut next_child = box_.first_child();
|
let mut next_child = box_.first_child();
|
||||||
|
|
@ -96,26 +113,13 @@ impl StatusMenu {
|
||||||
}
|
}
|
||||||
remove_child_menus(&mut menus, children);
|
remove_child_menus(&mut menus, children);
|
||||||
|
|
||||||
glib::MainContext::default().spawn_local(clone!(@weak obj => async move {
|
glib::MainContext::default().spawn_local(clone!(@weak self as self_ => async move {
|
||||||
match obj.inner().dbus_menu.get_layout(parent, -1, &[]).await {
|
match self_.inner().dbus_menu.get_layout(parent, -1, &[]).await {
|
||||||
Ok((_, layout)) => obj.populate_menu(&box_, &layout),
|
Ok((_, layout)) => self_.populate_menu(&box_, &layout),
|
||||||
Err(err) => eprintln!("Failed to call 'GetLayout': {}", err),
|
Err(err) => eprintln!("Failed to call 'GetLayout': {}", err),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
obj.inner().item.set(item);
|
|
||||||
obj.inner().dbus_menu.set(menu);
|
|
||||||
|
|
||||||
println!("{:#?}", layout);
|
|
||||||
obj.populate_menu(&obj.inner().vbox, &layout);
|
|
||||||
|
|
||||||
Ok(obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inner(&self) -> &StatusMenuInner {
|
|
||||||
StatusMenuInner::from_instance(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn populate_menu(&self, box_: >k4::Box, layout: &Layout) {
|
fn populate_menu(&self, box_: >k4::Box, layout: &Layout) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue