add home context menu, fix action state update

This commit is contained in:
yggverse 2024-11-04 22:46:26 +02:00
parent dd1a4e6f3c
commit a55f4724bc

View File

@ -57,6 +57,15 @@ impl Tab {
Some(&gformat!("win.{}", action_page_reload.name())), Some(&gformat!("win.{}", action_page_reload.name())),
); // @TODO resolve namespace outside ); // @TODO resolve namespace outside
let navigation = Menu::new();
navigation.append(
Some("Home"),
Some(&gformat!("win.{}", action_page_home.name())),
);
menu.append_section(None, &navigation);
let close = Menu::new(); let close = Menu::new();
close.append( close.append(
@ -78,31 +87,22 @@ impl Tab {
// Setup actions for context menu // Setup actions for context menu
widget.gobject().connect_setup_menu({ widget.gobject().connect_setup_menu({
let action_page_close = action_page_close.clone();
let action_page_home = action_page_home.clone();
let action_page_reload = action_page_reload.clone(); let action_page_reload = action_page_reload.clone();
move |tab_view, tab_page| { move |tab_view, tab_page| {
// Enable actions by default // Get state
action_page_reload.set_enabled(true); let state = match tab_page {
// Menu opened: setup selected page
Some(this) => tab_view.page_position(this).to_variant(),
// Menu closed: reset to defaults
None => (-1).to_variant(),
};
match tab_page { // Update actions
// Menu opened: action_page_close.change_state(&state);
// setup actions to operate with page selected only action_page_home.change_state(&state);
Some(this) => { action_page_reload.change_state(&state);
// Set state
let state = tab_view.page_position(this).to_variant();
// Update related actions
action_page_reload.change_state(&state);
}
// Menu closed:
// return actions to default values
None => {
// Set state
let state = &(-1).to_variant();
// Update related actions
action_page_reload.change_state(&state);
}
}
} }
}); });