mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
implement tmp helpers
This commit is contained in:
parent
377f743cca
commit
bc6a9a0575
@ -11,6 +11,7 @@ use window::Window;
|
|||||||
use adw::ApplicationWindow;
|
use adw::ApplicationWindow;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{Cancellable, File, SimpleAction},
|
gio::{Cancellable, File, SimpleAction},
|
||||||
|
glib::Variant,
|
||||||
prelude::{ActionExt, GtkWindowExt},
|
prelude::{ActionExt, GtkWindowExt},
|
||||||
FileLauncher,
|
FileLauncher,
|
||||||
};
|
};
|
||||||
@ -120,14 +121,7 @@ impl Browser {
|
|||||||
|
|
||||||
action_update.connect_activate({
|
action_update.connect_activate({
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |_, id| {
|
move |_, this| window.update(string_from_variant(this).as_str())
|
||||||
window.update(
|
|
||||||
id.expect("Page ID required for update action")
|
|
||||||
.get::<String>()
|
|
||||||
.expect("Parameter does not match `String`")
|
|
||||||
.as_str(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
action_page_new.connect_activate({
|
action_page_new.connect_activate({
|
||||||
@ -174,19 +168,7 @@ impl Browser {
|
|||||||
|
|
||||||
action_page_reload.connect_activate({
|
action_page_reload.connect_activate({
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |this, _| {
|
move |this, _| window.tab_page_navigation_reload(page_position_from_action_state(this))
|
||||||
let page_position = this
|
|
||||||
.state()
|
|
||||||
.expect("Page position required for reload action")
|
|
||||||
.get::<i32>()
|
|
||||||
.expect("Parameter does not match `i32`");
|
|
||||||
|
|
||||||
if page_position > -1 {
|
|
||||||
window.tab_page_navigation_reload(Some(page_position));
|
|
||||||
} else {
|
|
||||||
window.tab_page_navigation_reload(None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
action_page_pin.connect_activate({
|
action_page_pin.connect_activate({
|
||||||
@ -290,3 +272,28 @@ pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
|||||||
// Success
|
// Success
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extract formatted page position from C-based
|
||||||
|
/// [action state](https://docs.gtk.org/gio/property.SimpleAction.state.html)
|
||||||
|
fn page_position_from_action_state(action: &SimpleAction) -> Option<i32> {
|
||||||
|
let page_position = action
|
||||||
|
.state()
|
||||||
|
.expect("Page position required for reload action")
|
||||||
|
.get::<i32>()
|
||||||
|
.expect("Parameter does not match `i32`");
|
||||||
|
|
||||||
|
if page_position > -1 {
|
||||||
|
Some(page_position)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} // @TODO move outside
|
||||||
|
|
||||||
|
/// Extract `String` from C-based
|
||||||
|
/// [Variant](https://docs.gtk.org/glib/struct.Variant.html)
|
||||||
|
fn string_from_variant(variant: Option<&Variant>) -> String {
|
||||||
|
variant
|
||||||
|
.expect("Variant required for this action")
|
||||||
|
.get::<String>()
|
||||||
|
.expect("Parameter does not match `String`")
|
||||||
|
} // @TODO move outside
|
||||||
|
Loading…
x
Reference in New Issue
Block a user