diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index ac92d450..feafbb3a 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -8,7 +8,12 @@ use crate::Profile; use action::Action; use adw::{TabPage, TabView}; use anyhow::Result; -use gtk::{Box, Orientation, gio::Icon, glib::Propagation, prelude::ActionExt}; +use gtk::{ + Box, Orientation, + gio::Icon, + glib::Propagation, + prelude::{ActionExt, EditableExt, EntryExt, WidgetExt}, +}; pub use item::Item; use menu::Menu; use sourceview::prelude::IsA; @@ -76,8 +81,10 @@ impl Tab { if let Some(item) = index.borrow_mut().remove(tab_page) { // keep removed `Item` reference in the memory (to reopen from the main menu) // * skip item with blank request - if !item.page.navigation.request.is_empty() { - profile.history.close(&item.page.navigation.request.text()); + if !item.page.navigation.request.entry.text_length() > 0 { + profile + .history + .close(&item.page.navigation.request.entry.text()); } } // reassign global actions to active tab @@ -160,7 +167,7 @@ impl Tab { // Expect user input on tab appended has empty request entry // * this action initiated here because should be applied on tab appending event only if request.is_none() || request.is_some_and(|value| value.is_empty()) { - item.page.navigation.request.grab_focus(); + item.page.navigation.request.entry.grab_focus(); } // Relate with GTK `TabPage` with app `Item` @@ -273,7 +280,7 @@ impl Tab { pub fn reload(&self, page_position: Option) { if let Some(item) = self.item(page_position) { item.client - .handle(&item.page.navigation.request.text(), true, false); + .handle(&item.page.navigation.request.entry.text(), true, false); } } diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index ebf43651..d2e3bb03 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -11,7 +11,7 @@ use anyhow::Result; use client::Client; use gtk::{ Box, - prelude::{ActionExt, ActionMapExt, BoxExt}, + prelude::{ActionExt, ActionMapExt, BoxExt, EditableExt}, }; use page::Page; use sqlite::Transaction; @@ -85,7 +85,7 @@ impl Item { this.set_enabled(false); if let Some(uri) = page.navigation.request.home() { let request = uri.to_string(); - page.navigation.request.set_text(&request); + page.navigation.request.entry.set_text(&request); client.handle(&request, true, false); } } @@ -96,7 +96,7 @@ impl Item { let client = client.clone(); move |request, is_snap_history, is_redirect| { if let Some(request) = request { - page.navigation.request.set_text(&request); + page.navigation.request.entry.set_text(&request); client.handle(&request, is_snap_history, is_redirect); } } @@ -110,7 +110,7 @@ impl Item { action.reload.connect_activate({ let page = page.clone(); let client = client.clone(); - move |_, _| client.handle(&page.navigation.request.text(), true, false) + move |_, _| client.handle(&page.navigation.request.entry.text(), true, false) }); action.reload.connect_enabled_notify({ @@ -145,7 +145,7 @@ impl Item { // Handle immediately on request if let Some(request) = request { - page.navigation.request.set_text(request); + page.navigation.request.entry.set_text(request); if is_load { client.handle(request, true, false) } diff --git a/src/app/browser/window/tab/item/client/driver/gemini.rs b/src/app/browser/window/tab/item/client/driver/gemini.rs index 3300ef4b..68b4ff7b 100644 --- a/src/app/browser/window/tab/item/client/driver/gemini.rs +++ b/src/app/browser/window/tab/item/client/driver/gemini.rs @@ -4,6 +4,7 @@ use ggemini::{ client::{Client, Request, Response}, gio::{file_output_stream, memory_input_stream}, }; +use gtk::prelude::EditableExt; use gtk::{ gdk::Texture, gdk_pixbuf::Pixbuf, @@ -569,7 +570,7 @@ fn handle( } else { let t = target.to_string(); if matches!(redirect, Redirect::Permanent { .. }) { - page.navigation.request.set_text(&t); + page.navigation.request.entry.set_text(&t); } redirects.replace(total); { diff --git a/src/app/browser/window/tab/item/client/driver/nex.rs b/src/app/browser/window/tab/item/client/driver/nex.rs index 2e130cdb..61585f7a 100644 --- a/src/app/browser/window/tab/item/client/driver/nex.rs +++ b/src/app/browser/window/tab/item/client/driver/nex.rs @@ -4,7 +4,7 @@ use super::{Feature, Page}; use crate::tool::{Format, uri_to_title}; use gtk::gio::{MemoryInputStream, SocketConnection}; use gtk::prelude::{ - Cast, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt, + Cast, EditableExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt, }; use gtk::{ gdk::Texture, @@ -59,7 +59,7 @@ impl Nex { .request .info .replace(i.into_permanent_redirect()); - self.page.navigation.request.set_text(&r); + self.page.navigation.request.entry.set_text(&r); self.page.item_action.load.activate(Some(&r), false, true); return; // prevents operation cancelled message on redirect } diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index cd923040..f848d70d 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -8,7 +8,7 @@ use super::{Action as ItemAction, Profile, TabAction, WindowAction}; use adw::TabPage; use anyhow::Result; use content::Content; -use gtk::prelude::WidgetExt; +use gtk::prelude::{EditableExt, EntryExt, WidgetExt}; use input::Input; use navigation::Navigation; use search::Search; @@ -98,10 +98,10 @@ impl Page { pub fn snap_history(&self) { self.item_action .history - .add(self.navigation.request.text(), true); + .add(self.navigation.request.entry.text(), true); self.profile .history - .open(self.navigation.request.text(), Some(self.title())) + .open(self.navigation.request.entry.text(), Some(self.title())) } /// Cleanup session for `Self` @@ -136,7 +136,7 @@ impl Page { // Make initial page history snap self.profile .history - .open(self.navigation.request.text(), Some(self.title())); + .open(self.navigation.request.entry.text(), Some(self.title())); } Ok(()) } @@ -178,6 +178,7 @@ impl Page { pub fn set_progress(&self, progress_fraction: f64) { self.navigation .request + .entry .set_progress_fraction(progress_fraction); self.tab_page.set_loading(progress_fraction > 0.0) } diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 2e06f519..cc18553b 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -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 { diff --git a/src/app/browser/window/tab/item/page/navigation/bookmark.rs b/src/app/browser/window/tab/item/page/navigation/bookmark.rs index 6e47ee91..63bcbe34 100644 --- a/src/app/browser/window/tab/item/page/navigation/bookmark.rs +++ b/src/app/browser/window/tab/item/page/navigation/bookmark.rs @@ -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(); 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 c6b34ce9..e9c67291 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -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>, profile: Rc, proxy_resolver: Rc>>, @@ -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: >k::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