remove extra getters

This commit is contained in:
yggverse 2024-11-28 00:53:06 +02:00
parent 649d8f92f6
commit 3ce272cd70
7 changed files with 48 additions and 112 deletions

View File

@ -137,12 +137,7 @@ impl Tab {
.borrow_mut()
.insert(item.id.clone(), item.clone());
item.page
.navigation
.request()
.widget()
.gobject()
.grab_focus();
item.page.navigation.request.widget.entry.grab_focus();
item
}

View File

@ -66,7 +66,7 @@ impl Item {
// Init events
if let Some(text) = request {
page.navigation.request().widget().gobject().set_text(&text);
page.navigation.request.widget.entry.set_text(&text);
if is_load {
page.load(true);
@ -79,7 +79,7 @@ impl Item {
let parent = tab_view.clone().upcast::<gtk::Widget>();
move || {
// Request should match valid URI for all drivers supported
if let Some(uri) = page.navigation.request().uri() {
if let Some(uri) = page.navigation.request.uri() {
// Rout by scheme
if uri.scheme().to_lowercase() == "gemini" {
return identity::new_gemini(profile.clone(), actions.1.clone(), uri)
@ -96,7 +96,7 @@ impl Item {
let page = page.clone();
move |request, is_history| {
if let Some(text) = request {
page.navigation.request().widget().gobject().set_text(&text);
page.navigation.request.widget.entry.set_text(&text);
}
page.load(is_history);
}

View File

@ -69,7 +69,7 @@ impl Page {
let widget = Rc::new(Widget::new(
&id,
navigation.widget().gobject(),
&navigation.widget.gobject,
content.gobject(),
input.gobject(),
));
@ -102,7 +102,7 @@ impl Page {
let result = match self
.profile
.bookmark
.toggle(self.navigation.request().widget().gobject().text().as_str())
.toggle(self.navigation.request.widget.entry.text().as_str())
{
Ok(result) => Ok(result),
Err(_) => Err(Error::Bookmark), // @TODO
@ -114,7 +114,7 @@ impl Page {
/// Navigate home URL (parsed from current navigation entry)
/// * this method create new history record in memory as defined in `action_page_open` action
pub fn home(&self) {
if let Some(url) = self.navigation.home().url() {
if let Some(url) = self.navigation.home.url() {
// Update with history record
self.tab_action.load().activate(Some(&url), true);
}
@ -123,13 +123,9 @@ impl Page {
/// Navigate back in history
/// * this method does not create new history record in memory
pub fn history_back(&self) {
if let Some(request) = self.navigation.history().back(true) {
if let Some(request) = self.navigation.history.back(true) {
// Update navigation entry
self.navigation
.request()
.widget()
.gobject()
.set_text(&request);
self.navigation.request.widget.entry.set_text(&request);
// Load page (without history record)
self.load(false);
@ -139,13 +135,9 @@ impl Page {
/// Navigate forward in history
/// * this method does not create new history record in memory
pub fn history_forward(&self) {
if let Some(request) = self.navigation.history().forward(true) {
if let Some(request) = self.navigation.history.forward(true) {
// Update navigation entry
self.navigation
.request()
.widget()
.gobject()
.set_text(&request);
self.navigation.request.widget.entry.set_text(&request);
// Load page (without history record)
self.load(false);
@ -200,9 +192,9 @@ impl Page {
// Update navigation on redirect `is_foreground`
if redirect.is_foreground() {
self.navigation
.request()
.widget()
.gobject()
.request
.widget
.entry
.set_text(redirect.request().as_str());
}
@ -213,7 +205,7 @@ impl Page {
self.meta.unset_redirect_count();
// Return value from navigation entry
self.navigation.request().widget().gobject().text()
self.navigation.request.widget.entry.text()
};
// Update
@ -267,11 +259,7 @@ impl Page {
match Uri::parse(&request, UriFlags::NONE) {
Ok(_) => {
// Update navigation entry
self.navigation
.request()
.widget()
.gobject()
.set_text(&request);
self.navigation.request.widget.entry.set_text(&request);
// Load page (without history record)
self.load(false);
@ -288,11 +276,7 @@ impl Page {
);
// Update navigation entry
self.navigation
.request()
.widget()
.gobject()
.set_text(&request);
self.navigation.request.widget.entry.set_text(&request);
// Load page (without history record)
self.load(false);
@ -422,7 +406,7 @@ impl Page {
.profile
.identity
.gemini
.match_priority(&self.navigation.request().widget().gobject().text())
.match_priority(&self.navigation.request.widget.entry.text())
{
Some(identity) => {
match gemini::client::Certificate::from_pem(&identity.pem, &identity.scope) {
@ -929,14 +913,14 @@ fn is_external_uri(subject: &Uri, base: &Uri) -> bool {
/// Make new history record for given `navigation` object
/// * applies on shared conditions match only
fn snap_history(navigation: Rc<Navigation>) {
let request = navigation.request().widget().gobject().text();
let request = navigation.request.widget.entry.text();
// Apply additional filters
if match navigation.history().current() {
if match navigation.history.current() {
Some(current) => current != request,
None => true,
} {
// Add new record match conditions
navigation.history().add(request, true)
navigation.history.add(request, true)
}
}

View File

@ -24,14 +24,14 @@ use sqlite::Transaction;
use std::rc::Rc;
pub struct Navigation {
bookmark: Rc<Bookmark>,
history: Rc<History>,
home: Rc<Home>,
identity: Rc<Identity>,
profile: Rc<Profile>,
reload: Rc<Reload>,
request: Rc<Request>,
widget: Rc<Widget>,
pub bookmark: Rc<Bookmark>,
pub history: Rc<History>,
pub home: Rc<Home>,
pub identity: Rc<Identity>,
pub profile: Rc<Profile>,
pub reload: Rc<Reload>,
pub request: Rc<Request>,
pub widget: Rc<Widget>,
}
impl Navigation {
@ -53,7 +53,7 @@ impl Navigation {
home.widget().gobject(),
history.widget().gobject(),
reload.widget().gobject(),
request.widget().gobject(),
&request.widget.entry, // @TODO remove extra getters from other components
bookmark.widget().gobject(),
));
@ -73,7 +73,7 @@ impl Navigation {
// Actions
pub fn update(&self, progress_fraction: Option<f64>) {
let request_text = self.request.widget().gobject().text();
let request_text = self.request.widget.entry.text();
self.identity.update(
self.profile
@ -151,34 +151,6 @@ impl Navigation {
Ok(())
}
// Getters
pub fn home(&self) -> &Rc<Home> {
&self.home
}
pub fn history(&self) -> &Rc<History> {
&self.history
}
/*
pub fn reload(&self) -> &Rc<Reload> {
&self.reload
} */
pub fn request(&self) -> &Rc<Request> {
&self.request
}
/*
pub fn bookmark(&self) -> &Rc<Bookmark> {
&self.bookmark
} */
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
}
// Tools

View File

@ -13,7 +13,7 @@ use std::rc::Rc;
// Main
pub struct Request {
widget: Rc<Widget>,
pub widget: Rc<Widget>,
}
impl Request {
@ -90,12 +90,8 @@ impl Request {
// Getters
pub fn widget(&self) -> &Rc<Widget> {
&self.widget
}
pub fn uri(&self) -> Option<Uri> {
match Uri::parse(&self.widget.gobject().text(), UriFlags::NONE) {
match Uri::parse(&self.widget.entry.text(), UriFlags::NONE) {
Ok(uri) => Some(uri),
_ => None,
}

View File

@ -21,7 +21,7 @@ struct Progress {
}
pub struct Widget {
gobject: Entry,
pub entry: Entry,
progress: Rc<Progress>,
}
@ -35,21 +35,21 @@ impl Widget {
});
// Init widget
let gobject = Entry::builder()
let entry = Entry::builder()
.placeholder_text(PLACEHOLDER_TEXT)
.hexpand(true)
.build();
// Connect events
gobject.connect_changed(move |_| {
entry.connect_changed(move |_| {
action.0.update().activate(None);
});
gobject.connect_activate(move |this| {
entry.connect_activate(move |this| {
action.1.load().activate(Some(&this.text()), true);
});
gobject.connect_state_flags_changed({
entry.connect_state_flags_changed({
// Define last focus state container
let has_focus = RefCell::new(false);
move |this, state| {
@ -71,7 +71,7 @@ impl Widget {
});
// Return activated `Self`
Self { gobject, progress }
Self { entry, progress }
}
// Actions
@ -113,7 +113,7 @@ impl Widget {
Ok(records) => {
for record in records {
if let Some(text) = record.text {
self.gobject.set_text(&text);
self.entry.set_text(&text);
}
// Delegate restore action to the item childs
@ -132,7 +132,7 @@ impl Widget {
app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> {
// Keep value in memory until operation complete
let text = self.gobject.text();
let text = self.entry.text();
match database::insert(
transaction,
@ -167,16 +167,16 @@ impl Widget {
Duration::from_millis(PROGRESS_ANIMATION_TIME),
{
// Clone async pointers dependency
let gobject = self.gobject.clone();
let entry = self.entry.clone();
let progress = self.progress.clone();
// Frame
move || {
// Animate
if *progress.fraction.borrow() > gobject.progress_fraction() {
gobject.set_progress_fraction(
if *progress.fraction.borrow() > entry.progress_fraction() {
entry.set_progress_fraction(
// Currently, here is no outrange validation, seems that wrapper make this work @TODO
gobject.progress_fraction() + PROGRESS_ANIMATION_STEP,
entry.progress_fraction() + PROGRESS_ANIMATION_STEP,
);
return ControlFlow::Continue;
}
@ -185,8 +185,8 @@ impl Widget {
// Reset on 100% (to hide progress bar)
// or, just await for new value request
if gobject.progress_fraction() == 1.0 {
gobject.set_progress_fraction(0.0);
if entry.progress_fraction() == 1.0 {
entry.set_progress_fraction(0.0);
}
// Stop iteration
@ -198,12 +198,6 @@ impl Widget {
}
}
}
// Getters
pub fn gobject(&self) -> &Entry {
&self.gobject
}
}
// Tools

View File

@ -7,7 +7,7 @@ const MARGIN: i32 = 6;
const SPACING: i32 = 6;
pub struct Widget {
gobject: Box,
pub gobject: Box,
}
impl Widget {
@ -37,9 +37,4 @@ impl Widget {
Self { gobject }
}
// Getters
pub fn gobject(&self) -> &Box {
&self.gobject
}
}