mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
fix active page reset
This commit is contained in:
parent
b443d1c58e
commit
710093b161
@ -52,7 +52,7 @@ impl App {
|
||||
let action_page_home = 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_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);
|
||||
|
||||
// Init GTK
|
||||
|
@ -27,6 +27,9 @@ impl Action {
|
||||
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(
|
||||
group: &str,
|
||||
is_enabled: bool,
|
||||
|
@ -181,7 +181,11 @@ impl Browser {
|
||||
.get::<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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -92,7 +92,8 @@ impl Window {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -72,23 +72,21 @@ impl Tab {
|
||||
// Menu opened:
|
||||
// setup actions to operate with page selected only
|
||||
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:
|
||||
// return actions to default values
|
||||
None => match tab_view.selected_page() {
|
||||
Some(selected) => {
|
||||
// Get position of page selected
|
||||
let position = tab_view.page_position(&selected).to_variant();
|
||||
None => {
|
||||
// Set state
|
||||
let state = &(-1).to_variant();
|
||||
|
||||
// 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) {
|
||||
if let Some(id) = self.widget.gobject().nth_page(page_position).keyword() {
|
||||
/// Reload page at `i32` position or selected page on `None` given
|
||||
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) {
|
||||
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) {
|
||||
match self.index.borrow().get(id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user