mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-13 15:32:01 +00:00
remove extra event listener loop
This commit is contained in:
parent
e91930a9d9
commit
e0e21b4926
@ -11,7 +11,7 @@ use gtk::{
|
||||
Box, Label, Orientation, TextView,
|
||||
gio::SimpleAction,
|
||||
glib::{Uri, UriHideFlags, uuid_string_random},
|
||||
prelude::{ActionExt, BoxExt, DisplayExt, WidgetExt},
|
||||
prelude::{ActionExt, BoxExt, DisplayExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
@ -38,12 +38,11 @@ impl Response for Box {
|
||||
size_limit: Option<usize>,
|
||||
) -> Self {
|
||||
// Init local actions
|
||||
let action_update = SimpleAction::new(&uuid_string_random(), None);
|
||||
let action_send = SimpleAction::new(&uuid_string_random(), None);
|
||||
|
||||
// Init components
|
||||
let control = Rc::new(Control::build(action_send.clone()));
|
||||
let form = TextView::form(action_update.clone());
|
||||
let text_view = TextView::form();
|
||||
let title = Label::title(title);
|
||||
|
||||
// Init main widget
|
||||
@ -57,21 +56,21 @@ impl Response for Box {
|
||||
.build();
|
||||
|
||||
g_box.append(&title);
|
||||
g_box.append(&form);
|
||||
g_box.append(&text_view);
|
||||
g_box.append(&control.g_box);
|
||||
|
||||
// Init events
|
||||
action_update.connect_activate({
|
||||
text_view.buffer().connect_changed({
|
||||
let base = base.clone();
|
||||
let control = control.clone();
|
||||
let form = form.clone();
|
||||
move |_, _| {
|
||||
let text_view = text_view.clone();
|
||||
move |_| {
|
||||
control.update(
|
||||
form.text().is_empty(),
|
||||
text_view.text().is_empty(),
|
||||
size_limit.map(|limit| {
|
||||
limit as isize
|
||||
- ((base.to_string_partial(UriHideFlags::QUERY).len()
|
||||
+ Uri::escape_string(&form.text(), None, false).len())
|
||||
+ Uri::escape_string(&text_view.text(), None, false).len())
|
||||
as isize)
|
||||
}),
|
||||
)
|
||||
@ -79,20 +78,20 @@ impl Response for Box {
|
||||
});
|
||||
|
||||
action_send.connect_activate({
|
||||
let form = form.clone();
|
||||
let text_view = text_view.clone();
|
||||
move |_, _| {
|
||||
item_action.load.activate(
|
||||
Some(&format!(
|
||||
"{}?{}",
|
||||
base.to_string_partial(UriHideFlags::QUERY),
|
||||
Uri::escape_string(&form.text(), None, false),
|
||||
Uri::escape_string(&text_view.text(), None, false),
|
||||
)),
|
||||
false,
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
form.add_controller({
|
||||
text_view.add_controller({
|
||||
const SHORTCUT: &str = "<Primary>Return"; // @TODO optional
|
||||
|
||||
/*control
|
||||
|
@ -1,8 +1,7 @@
|
||||
use gtk::{
|
||||
TextView, WrapMode,
|
||||
gio::SimpleAction,
|
||||
glib::GString,
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
prelude::{TextBufferExt, TextViewExt, WidgetExt},
|
||||
};
|
||||
use libspelling::{Checker, TextBufferAdapter};
|
||||
use sourceview::Buffer;
|
||||
@ -10,7 +9,7 @@ use sourceview::Buffer;
|
||||
const MARGIN: i32 = 8;
|
||||
|
||||
pub trait Form {
|
||||
fn form(action_update: SimpleAction) -> Self;
|
||||
fn form() -> Self;
|
||||
fn text(&self) -> GString;
|
||||
}
|
||||
|
||||
@ -18,7 +17,7 @@ impl Form for TextView {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
fn form(action_update: SimpleAction) -> Self {
|
||||
fn form() -> Self {
|
||||
// Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer
|
||||
let buffer = Buffer::builder().build();
|
||||
|
||||
@ -44,10 +43,6 @@ impl Form for TextView {
|
||||
text_view.set_size_request(-1, 38); // @TODO [#635](https://gitlab.gnome.org/GNOME/pygobject/-/issues/635)
|
||||
|
||||
// Init events
|
||||
text_view.buffer().connect_changed(move |_| {
|
||||
action_update.activate(None);
|
||||
});
|
||||
|
||||
text_view.connect_realize(|this| {
|
||||
this.grab_focus();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user