diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index c18c4a06..6d39fbbf 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -13,7 +13,10 @@ use widget::Widget; use crate::app::browser::action::Action as BrowserAction; use crate::app::browser::window::action::Action as WindowAction; use adw::TabView; -use gtk::glib::{GString, Propagation}; +use gtk::{ + glib::{GString, Propagation}, + prelude::WidgetExt, +}; use sqlite::Transaction; use std::{cell::RefCell, collections::HashMap, rc::Rc}; @@ -104,7 +107,7 @@ impl Tab { if let Some(id) = page.keyword() { if let Some(item) = index.borrow().get(&id) { item.set_page_navigation_request_text(value.as_str()); - item.page_reload(); + item.page().reload(); } } } @@ -139,7 +142,13 @@ impl Tab { // Register dynamically created tab components in the HashMap index self.index.borrow_mut().insert(item.id(), item.clone()); - item.page_navigation_request_grab_focus(); // @TODO + item.page() + .navigation() + .request() + .widget() + .gobject() + .grab_focus(); + item } @@ -162,7 +171,7 @@ impl Tab { if let Some(page) = self.widget.page(page_position) { if let Some(id) = page.keyword() { if let Some(item) = self.index.borrow().get(&id) { - item.page_home(); + item.page().home(); } } } @@ -172,7 +181,7 @@ impl Tab { if let Some(page) = self.widget.page(page_position) { if let Some(id) = page.keyword() { if let Some(item) = self.index.borrow().get(&id) { - item.page_history_back(); + item.page().history_back(); } } } @@ -182,7 +191,7 @@ impl Tab { if let Some(page) = self.widget.page(page_position) { if let Some(id) = page.keyword() { if let Some(item) = self.index.borrow().get(&id) { - item.page_history_forward(); + item.page().history_forward(); } } } @@ -193,7 +202,7 @@ impl Tab { if let Some(page) = self.widget.page(page_position) { if let Some(id) = page.keyword() { if let Some(item) = self.index.borrow().get(&id) { - item.page_reload(); + item.page().reload(); } } } diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 838f8e2c..30b2f40c 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -10,7 +10,10 @@ use crate::app::browser::action::Action as BrowserAction; use crate::app::browser::window::action::Action as WindowAction; use crate::app::browser::window::tab::action::Action as TabAction; use adw::{TabPage, TabView}; -use gtk::glib::{uuid_string_random, GString}; +use gtk::{ + glib::{uuid_string_random, GString}, + prelude::EditableExt, +}; use sqlite::Transaction; use std::rc::Rc; @@ -63,26 +66,6 @@ impl Item { } // Actions - pub fn page_home(&self) { - self.page.home() - } - - pub fn page_history_back(&self) { - self.page.history_back() - } - - pub fn page_history_forward(&self) { - self.page.history_forward() - } - - pub fn page_reload(&self) { - self.page.reload() - } - - pub fn page_navigation_request_grab_focus(&self) { - self.page.navigation_request_grab_focus() - } - pub fn update(&self) { // Update child components self.page.update(); @@ -188,14 +171,24 @@ impl Item { // Setters pub fn set_page_navigation_request_text(&self, value: &str) { - self.page.set_navigation_request_text(value); + self.page + .navigation() + .request() + .widget() + .gobject() + .set_text(value); } // Getters + pub fn id(&self) -> GString { self.id.clone() } + pub fn page(&self) -> &Rc { + &self.page + } + pub fn page_is_loading(&self) -> bool { self.page.is_loading() } diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 6993302a..4d291cac 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -26,7 +26,8 @@ use gtk::{ RegexMatchFlags, Uri, UriFlags, UriHideFlags, }, prelude::{ - ActionExt, CancellableExt, IOStreamExt, OutputStreamExt, SocketClientExt, StaticVariantType, + ActionExt, CancellableExt, EditableExt, IOStreamExt, OutputStreamExt, SocketClientExt, + StaticVariantType, }, Box, }; @@ -79,7 +80,7 @@ impl Page { let widget = Widget::new_rc( &id, action_page_open.clone(), - navigation.gobject(), + navigation.widget().gobject(), content.gobject(), input.gobject(), ); @@ -114,7 +115,7 @@ impl Page { let this = this.clone(); move |_, request| { // Set request value from action parameter - this.navigation.set_request_text( + this.navigation().request().widget().gobject().set_text( &request .expect("Parameter required for this action") .get::() @@ -135,7 +136,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.open().activate(Some(&url)); } @@ -144,9 +145,13 @@ 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.set_request_text(&request); + self.navigation + .request() + .widget() + .gobject() + .set_text(&request); // Load page (without history record) self.load(false); @@ -156,9 +161,13 @@ 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.set_request_text(&request); + self.navigation + .request() + .widget() + .gobject() + .set_text(&request); // Load page (without history record) self.load(false); @@ -213,7 +222,10 @@ impl Page { // Update navigation on redirect `is_foreground` if redirect.is_foreground() { self.navigation - .set_request_text(redirect.request().as_str()); + .request() + .widget() + .gobject() + .set_text(redirect.request().as_str()); } // Return value from redirection holder @@ -223,18 +235,18 @@ impl Page { self.meta.unset_redirect_count(); // Return value from navigation entry - self.navigation.request_text() + self.navigation.request().widget().gobject().text() }; // Add history record if history { - match self.navigation.history_current() { + match self.navigation.history().current() { Some(current) => { if current != request { - self.navigation.history_add(request.clone()); + self.navigation.history().add(request.clone(), true); } } - None => self.navigation.history_add(request.clone()), + None => self.navigation.history().add(request.clone(), true), } } @@ -284,7 +296,11 @@ impl Page { match Uri::parse(&request, UriFlags::NONE) { Ok(_) => { // Update navigation entry - self.navigation.set_request_text(&request); + self.navigation + .request() + .widget() + .gobject() + .set_text(&request); // Load page (without history record) self.load(false); @@ -301,7 +317,11 @@ impl Page { ); // Update navigation entry - self.navigation.set_request_text(&request); + self.navigation + .request() + .widget() + .gobject() + .set_text(&request); // Load page (without history record) self.load(false); @@ -385,16 +405,6 @@ impl Page { Ok(()) } - pub fn navigation_request_grab_focus(&self) { - self.navigation.request_grab_focus(); - } - - // Setters - - pub fn set_navigation_request_text(&self, value: &str) { - self.navigation.set_request_text(value); - } - // Getters pub fn progress_fraction(&self) -> Option { @@ -426,6 +436,15 @@ impl Page { self.meta.title() } + /* + pub fn meta(&self) -> &Rc { + &self.meta + } */ + + pub fn navigation(&self) -> &Rc { + &self.navigation + } + pub fn gobject(&self) -> &Box { self.widget.gobject() } diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 03fc3f14..b386b99e 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -16,7 +16,7 @@ use widget::Widget; use crate::app::browser::action::Action as BrowserAction; use crate::app::browser::window::action::Action as WindowAction; -use gtk::{gio::SimpleAction, glib::GString, prelude::WidgetExt, Box}; +use gtk::{gio::SimpleAction, prelude::EditableExt}; use sqlite::Transaction; use std::rc::Rc; @@ -63,30 +63,12 @@ impl Navigation { } // Actions - pub fn request_grab_focus(&self) { - self.request.gobject().grab_focus(); - } - - pub fn history_add(&self, request: GString) { - self.history.add(request, true); - } - - pub fn history_back(&self, follow_to_index: bool) -> Option { - self.history.back(follow_to_index) - } - - pub fn history_current(&self) -> Option { - self.history.current() - } - - pub fn history_forward(&self, follow_to_index: bool) -> Option { - self.history.forward(follow_to_index) - } pub fn update(&self, progress_fraction: Option) { self.home.update(self.request.uri()); self.history.update(); - self.reload.update(!self.request.text().is_empty()); + self.reload + .update(!self.request.widget().gobject().text().is_empty()); self.request.update(progress_fraction); self.bookmark.update(); } @@ -150,22 +132,32 @@ impl Navigation { Ok(()) } - // Setters - pub fn set_request_text(&self, value: &str) { - self.request.set_text(value); - } - // Getters - pub fn gobject(&self) -> &Box { - self.widget.gobject() + + pub fn home(&self) -> &Rc { + &self.home } - pub fn home_url(&self) -> Option { - self.home.url() + pub fn history(&self) -> &Rc { + &self.history } - pub fn request_text(&self) -> GString { - self.request.text() + /* + pub fn reload(&self) -> &Rc { + &self.reload + } */ + + pub fn request(&self) -> &Rc { + &self.request + } + + /* + pub fn bookmark(&self) -> &Rc { + &self.bookmark + } */ + + pub fn widget(&self) -> &Rc { + &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index 6b95af0f..b6ce4232 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -7,7 +7,8 @@ use widget::Widget; use crate::app::browser::action::Action as BrowserAction; use gtk::{ gio::SimpleAction, - glib::{GString, Uri, UriFlags}, + glib::{Uri, UriFlags}, + prelude::EditableExt, Entry, }; use sqlite::Transaction; @@ -94,22 +95,17 @@ impl Request { Ok(()) } - // Setters - pub fn set_text(&self, value: &str) { - self.widget.set_text(value); - } - // Getters pub fn gobject(&self) -> &Entry { self.widget.gobject() } - pub fn text(&self) -> GString { - self.widget.text() + pub fn widget(&self) -> &Rc { + &self.widget } pub fn uri(&self) -> Option { - match Uri::parse(&self.widget.text(), UriFlags::NONE) { + match Uri::parse(&self.widget.gobject().text(), UriFlags::NONE) { Ok(uri) => Some(uri), _ => None, } diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget.rs b/src/app/browser/window/tab/item/page/navigation/request/widget.rs index 8d53fafb..6735eb67 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget.rs @@ -5,7 +5,7 @@ use database::Database; use crate::app::browser::action::Action as BrowserAction; use gtk::{ gio::SimpleAction, - glib::{timeout_add_local, ControlFlow, GString, SourceId}, + glib::{timeout_add_local, ControlFlow, SourceId}, prelude::{ActionExt, EditableExt, EntryExt, ToVariant, WidgetExt}, Entry, StateFlags, }; @@ -202,19 +202,11 @@ impl Widget { } } - // Setters - pub fn set_text(&self, value: &str) { - self.gobject.set_text(value); - } - // Getters + pub fn gobject(&self) -> &Entry { &self.gobject } - - pub fn text(&self) -> GString { - self.gobject.text() - } } // Tools