remove private level for the entry with extra methods

This commit is contained in:
yggverse 2025-07-29 19:59:05 +03:00
parent 6e4eec54f0
commit e7e216aaea
8 changed files with 34 additions and 57 deletions

View file

@ -53,7 +53,7 @@ impl Navigation {
g_box.append(&home);
g_box.append(&history);
g_box.append(&reload);
request.append_to(&g_box); // private member
g_box.append(&request.entry);
g_box.append(&bookmark.button);
Self {

View file

@ -1,7 +1,7 @@
use super::{Profile, Request, WindowAction};
use gtk::{
Button,
prelude::{ActionExt, ButtonExt, WidgetExt},
prelude::{ActionExt, ButtonExt, EditableExt, WidgetExt},
};
use std::rc::Rc;
@ -23,12 +23,11 @@ impl Bookmark {
action.bookmark.simple_action.name()
))
.build();
update(profile, &button, &request.text());
request.on_change({
update(profile, &button, &request.entry.text());
request.entry.connect_changed({
let b = button.clone();
let p = profile.clone();
let r = request.clone();
move || update(&p, &b, &r.text())
move |e| update(&p, &b, &e.text())
});
Self {
profile: profile.clone(),
@ -40,7 +39,7 @@ impl Bookmark {
pub fn toggle(&self, title: Option<&str>) {
let button = self.button.clone();
let profile = self.profile.clone();
let query = self.request.text();
let query = self.request.entry.text();
let title = title.map(|t| t.to_string());
button.set_sensitive(false); // lock
let has_bookmark = profile.bookmark.toggle(&query, title.as_deref()).unwrap();

View file

@ -27,8 +27,7 @@ const PREFIX_DOWNLOAD: &str = "download:";
const PREFIX_SOURCE: &str = "source:";
pub struct Request {
/// * keep it private to properly update some local dependencies on change (e.g. proxy resolver)
entry: Entry,
pub entry: Entry,
pub info: Rc<RefCell<Info>>,
profile: Rc<Profile>,
proxy_resolver: Rc<RefCell<Option<ProxyResolver>>>,
@ -179,7 +178,7 @@ impl Request {
&& state.contains(StateFlags::ACTIVE | StateFlags::FOCUS_WITHIN)
&& this.selection_bounds().is_none()
{
this.select_region(0, -1);
this.select_region(0, -1)
}
// Update last focus state
has_focus.replace(state.contains(StateFlags::FOCUS_WITHIN));
@ -291,27 +290,6 @@ impl Request {
self.entry.text().starts_with("file://")
}
pub fn is_empty(&self) -> bool {
self.entry.text_length() > 0
}
pub fn grab_focus(&self) -> bool {
self.entry.grab_focus()
}
pub fn set_progress_fraction(&self, value: f64) {
self.entry.set_progress_fraction(value);
}
pub fn set_text(&self, value: &str) {
self.entry.set_text(value);
self.refresh()
}
pub fn text(&self) -> GString {
self.entry.text()
}
/// Get [ProxyResolver](https://docs.gtk.org/gio/iface.ProxyResolver.html)
/// which is constructed for every `Request` entry change
/// * useful on build new [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html)
@ -320,15 +298,6 @@ impl Request {
self.proxy_resolver.borrow().clone()
}
pub fn append_to(&self, parent: &gtk::Box) {
use gtk::prelude::BoxExt;
parent.append(&self.entry)
}
pub fn on_change(&self, callback: impl Fn() + 'static) {
self.entry.connect_changed(move |_| callback());
}
// Tools
/// Get request value with formatted `download` prefix