fix active page reset

This commit is contained in:
yggverse 2024-11-04 17:38:40 +02:00
parent b443d1c58e
commit 710093b161
5 changed files with 37 additions and 19 deletions

View File

@ -52,7 +52,7 @@ impl App {
let action_page_home = Action::new("win", false, None); let action_page_home = Action::new("win", false, None);
let action_page_history_back = Action::new("win", false, None); let action_page_history_back = Action::new("win", false, None);
let action_page_history_forward = Action::new("win", false, None); let action_page_history_forward = Action::new("win", false, None);
let action_page_reload = Action::new_stateful("win", true, None, &0.to_variant()); // @TODO let action_page_reload = Action::new_stateful("win", true, None, &(-1).to_variant());
let action_page_pin = Action::new("win", true, None); let action_page_pin = Action::new("win", true, None);
// Init GTK // Init GTK

View File

@ -27,6 +27,9 @@ impl Action {
Self { group, simple } Self { group, simple }
} }
/// Stateful constructors useful for actions that require custom values
/// but could not receive it directly with action argument
/// e.g. [MenuModel](https://docs.gtk.org/gio/class.MenuModel.html)
pub fn new_stateful( pub fn new_stateful(
group: &str, group: &str,
is_enabled: bool, is_enabled: bool,

View File

@ -181,7 +181,11 @@ impl Browser {
.get::<i32>() .get::<i32>()
.expect("Parameter does not match `i32`"); .expect("Parameter does not match `i32`");
window.tab_page_navigation_reload(page_position); if page_position > -1 {
window.tab_page_navigation_reload(Some(page_position));
} else {
window.tab_page_navigation_reload(None);
}
} }
}); });

View File

@ -92,7 +92,8 @@ impl Window {
self.tab.page_navigation_history_forward(); self.tab.page_navigation_history_forward();
} }
pub fn tab_page_navigation_reload(&self, page_position: i32) { /// Reload page at `i32` position or selected page on `None` given
pub fn tab_page_navigation_reload(&self, page_position: Option<i32>) {
self.tab.page_navigation_reload(page_position); self.tab.page_navigation_reload(page_position);
} }

View File

@ -72,23 +72,21 @@ impl Tab {
// Menu opened: // Menu opened:
// setup actions to operate with page selected only // setup actions to operate with page selected only
Some(this) => { Some(this) => {
let position = tab_view.page_position(this).to_variant(); // Set state
let state = tab_view.page_position(this).to_variant();
action_page_reload.change_state(&position); // Update related actions
action_page_reload.change_state(&state);
} }
// Menu closed: // Menu closed:
// return actions to default values // return actions to default values
None => match tab_view.selected_page() { None => {
Some(selected) => { // Set state
// Get position of page selected let state = &(-1).to_variant();
let position = tab_view.page_position(&selected).to_variant();
// Update related actions // Update related actions
action_page_reload.change_state(&position); action_page_reload.change_state(&state);
} }
// No selected page found, disable related actions
None => action_page_reload.set_enabled(false),
},
} }
} }
}); });
@ -242,13 +240,25 @@ impl Tab {
} }
} }
pub fn page_navigation_reload(&self, page_position: i32) { /// Reload page at `i32` position or selected page on `None` given
if let Some(id) = self.widget.gobject().nth_page(page_position).keyword() { pub fn page_navigation_reload(&self, page_position: Option<i32>) {
match page_position {
Some(value) => {
if let Some(id) = self.widget.gobject().nth_page(value).keyword() {
if let Some(item) = self.index.borrow().get(&id) { if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_reload(); item.page_navigation_reload();
} }
} }
} }
None => {
if let Some(id) = self.widget.current_page_keyword() {
if let Some(item) = self.index.borrow().get(&id) {
item.page_navigation_reload();
}
}
}
}
}
pub fn update(&self, id: &str) { pub fn update(&self, id: &str) {
match self.index.borrow().get(id) { match self.index.borrow().get(id) {