mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
add sensitive input status code support
This commit is contained in:
parent
a15738f391
commit
861046e162
8 changed files with 231 additions and 18 deletions
71
src/app/browser/window/tab/item/page/input/sensitive.rs
Normal file
71
src/app/browser/window/tab/item/page/input/sensitive.rs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
mod form;
|
||||
mod widget;
|
||||
|
||||
use form::Form;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{uuid_string_random, Uri, UriHideFlags},
|
||||
prelude::{ActionExt, ToVariant, WidgetExt},
|
||||
Box,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Sensitive {
|
||||
// Components
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Sensitive {
|
||||
// Construct
|
||||
pub fn new_arc(
|
||||
action_page_open: Arc<SimpleAction>,
|
||||
base: Uri,
|
||||
title: Option<&str>,
|
||||
max_length: Option<i32>,
|
||||
) -> Arc<Self> {
|
||||
// Init local actions
|
||||
let action_send = Arc::new(SimpleAction::new(&uuid_string_random(), None));
|
||||
|
||||
// Init components
|
||||
let form = Form::new_arc(
|
||||
action_send.clone(),
|
||||
title,
|
||||
match max_length {
|
||||
Some(value) => {
|
||||
Some(value - base.to_string_partial(UriHideFlags::QUERY).len() as i32)
|
||||
}
|
||||
None => None,
|
||||
},
|
||||
);
|
||||
|
||||
// Init widget
|
||||
let widget = Widget::new_arc(form.gobject());
|
||||
|
||||
// Init events
|
||||
action_send.connect_activate({
|
||||
let form = form.clone();
|
||||
move |_, _| {
|
||||
action_page_open.activate(Some(
|
||||
&format!(
|
||||
"{}?{}",
|
||||
base.to_string_partial(UriHideFlags::QUERY),
|
||||
Uri::escape_string(form.text().as_str(), None, false),
|
||||
)
|
||||
.to_variant(),
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
widget.gobject().connect_realize(move |_| form.focus());
|
||||
|
||||
// Return activated struct
|
||||
Arc::new(Self { widget })
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue