fix global actions update on setup menu

This commit is contained in:
yggverse 2025-01-30 23:50:20 +02:00
parent bd2d85120e
commit 9eaf599892

View file

@ -57,6 +57,26 @@ impl Tab {
} }
// Init events // Init events
tab_view.connect_setup_menu({
let index = index.clone();
let window_action = window_action.clone();
move |tab_view, tab_page| {
// by documentation:
// * `tab_page` == `Some` - popover open
// * `tab_page` == `None` - popover closed
update_actions(
tab_view,
match tab_page {
Some(this) => Some(this.clone()),
None => tab_view.selected_page(),
}
.as_ref(),
&index,
&window_action,
);
}
});
tab_view.connect_close_page({ tab_view.connect_close_page({
let index = index.clone(); let index = index.clone();
let profile = profile.clone(); let profile = profile.clone();
@ -83,12 +103,16 @@ impl Tab {
let window_action = window_action.clone(); let window_action = window_action.clone();
let index = index.clone(); let index = index.clone();
move |tab_view| { move |tab_view| {
if let Some(tab_page) = tab_view.selected_page() {
tab_page.set_needs_attention(false);
}
update_actions( update_actions(
tab_view, tab_view,
tab_view.selected_page().as_ref(), match tab_view.selected_page() {
Some(this) => {
this.set_needs_attention(false);
Some(this.clone())
}
None => None,
}
.as_ref(),
&index, &index,
&window_action, &window_action,
) )
@ -392,8 +416,7 @@ fn update_actions(
index: &Rc<RefCell<HashMap<TabPage, Rc<Item>>>>, index: &Rc<RefCell<HashMap<TabPage, Rc<Item>>>>,
window_action: &Rc<WindowAction>, window_action: &Rc<WindowAction>,
) { ) {
match tab_page { if let Some(tab_page) = tab_page {
Some(tab_page) => {
if let Some(item) = index.borrow().get(tab_page) { if let Some(item) = index.borrow().get(tab_page) {
window_action window_action
.home .home
@ -413,9 +436,9 @@ fn update_actions(
.set_enabled(item.action.history.forward.is_enabled()); .set_enabled(item.action.history.forward.is_enabled());
window_action.change_state(Some(tab_view.page_position(tab_page))); window_action.change_state(Some(tab_view.page_position(tab_page)));
} // @TODO incorrect index init implementation, tabs refactory wanted return;
}
} }
None => {
// Reset to defaults // Reset to defaults
window_action.home.simple_action.set_enabled(false); window_action.home.simple_action.set_enabled(false);
window_action.reload.simple_action.set_enabled(false); window_action.reload.simple_action.set_enabled(false);
@ -427,8 +450,6 @@ fn update_actions(
window_action.change_state(None); window_action.change_state(None);
} }
}
}
/// Create new [TabPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabPage.html) /// Create new [TabPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabPage.html)
/// in [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) /// in [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html)