mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-12 15:02:17 +00:00
remove private level for the entry with extra methods
This commit is contained in:
parent
6e4eec54f0
commit
e7e216aaea
@ -8,7 +8,12 @@ use crate::Profile;
|
|||||||
use action::Action;
|
use action::Action;
|
||||||
use adw::{TabPage, TabView};
|
use adw::{TabPage, TabView};
|
||||||
use anyhow::Result;
|
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;
|
pub use item::Item;
|
||||||
use menu::Menu;
|
use menu::Menu;
|
||||||
use sourceview::prelude::IsA;
|
use sourceview::prelude::IsA;
|
||||||
@ -76,8 +81,10 @@ impl Tab {
|
|||||||
if let Some(item) = index.borrow_mut().remove(tab_page) {
|
if let Some(item) = index.borrow_mut().remove(tab_page) {
|
||||||
// keep removed `Item` reference in the memory (to reopen from the main menu)
|
// keep removed `Item` reference in the memory (to reopen from the main menu)
|
||||||
// * skip item with blank request
|
// * skip item with blank request
|
||||||
if !item.page.navigation.request.is_empty() {
|
if !item.page.navigation.request.entry.text_length() > 0 {
|
||||||
profile.history.close(&item.page.navigation.request.text());
|
profile
|
||||||
|
.history
|
||||||
|
.close(&item.page.navigation.request.entry.text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// reassign global actions to active tab
|
// reassign global actions to active tab
|
||||||
@ -160,7 +167,7 @@ impl Tab {
|
|||||||
// Expect user input on tab appended has empty request entry
|
// Expect user input on tab appended has empty request entry
|
||||||
// * this action initiated here because should be applied on tab appending event only
|
// * 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()) {
|
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`
|
// Relate with GTK `TabPage` with app `Item`
|
||||||
@ -273,7 +280,7 @@ impl Tab {
|
|||||||
pub fn reload(&self, page_position: Option<i32>) {
|
pub fn reload(&self, page_position: Option<i32>) {
|
||||||
if let Some(item) = self.item(page_position) {
|
if let Some(item) = self.item(page_position) {
|
||||||
item.client
|
item.client
|
||||||
.handle(&item.page.navigation.request.text(), true, false);
|
.handle(&item.page.navigation.request.entry.text(), true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use anyhow::Result;
|
|||||||
use client::Client;
|
use client::Client;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
Box,
|
Box,
|
||||||
prelude::{ActionExt, ActionMapExt, BoxExt},
|
prelude::{ActionExt, ActionMapExt, BoxExt, EditableExt},
|
||||||
};
|
};
|
||||||
use page::Page;
|
use page::Page;
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
@ -85,7 +85,7 @@ impl Item {
|
|||||||
this.set_enabled(false);
|
this.set_enabled(false);
|
||||||
if let Some(uri) = page.navigation.request.home() {
|
if let Some(uri) = page.navigation.request.home() {
|
||||||
let request = uri.to_string();
|
let request = uri.to_string();
|
||||||
page.navigation.request.set_text(&request);
|
page.navigation.request.entry.set_text(&request);
|
||||||
client.handle(&request, true, false);
|
client.handle(&request, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ impl Item {
|
|||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
move |request, is_snap_history, is_redirect| {
|
move |request, is_snap_history, is_redirect| {
|
||||||
if let Some(request) = request {
|
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);
|
client.handle(&request, is_snap_history, is_redirect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ impl Item {
|
|||||||
action.reload.connect_activate({
|
action.reload.connect_activate({
|
||||||
let page = page.clone();
|
let page = page.clone();
|
||||||
let client = client.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({
|
action.reload.connect_enabled_notify({
|
||||||
@ -145,7 +145,7 @@ impl Item {
|
|||||||
|
|
||||||
// Handle immediately on request
|
// Handle immediately on request
|
||||||
if let Some(request) = request {
|
if let Some(request) = request {
|
||||||
page.navigation.request.set_text(request);
|
page.navigation.request.entry.set_text(request);
|
||||||
if is_load {
|
if is_load {
|
||||||
client.handle(request, true, false)
|
client.handle(request, true, false)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ use ggemini::{
|
|||||||
client::{Client, Request, Response},
|
client::{Client, Request, Response},
|
||||||
gio::{file_output_stream, memory_input_stream},
|
gio::{file_output_stream, memory_input_stream},
|
||||||
};
|
};
|
||||||
|
use gtk::prelude::EditableExt;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk::Texture,
|
gdk::Texture,
|
||||||
gdk_pixbuf::Pixbuf,
|
gdk_pixbuf::Pixbuf,
|
||||||
@ -569,7 +570,7 @@ fn handle(
|
|||||||
} else {
|
} else {
|
||||||
let t = target.to_string();
|
let t = target.to_string();
|
||||||
if matches!(redirect, Redirect::Permanent { .. }) {
|
if matches!(redirect, Redirect::Permanent { .. }) {
|
||||||
page.navigation.request.set_text(&t);
|
page.navigation.request.entry.set_text(&t);
|
||||||
}
|
}
|
||||||
redirects.replace(total);
|
redirects.replace(total);
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ use super::{Feature, Page};
|
|||||||
use crate::tool::{Format, uri_to_title};
|
use crate::tool::{Format, uri_to_title};
|
||||||
use gtk::gio::{MemoryInputStream, SocketConnection};
|
use gtk::gio::{MemoryInputStream, SocketConnection};
|
||||||
use gtk::prelude::{
|
use gtk::prelude::{
|
||||||
Cast, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt,
|
Cast, EditableExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt,
|
||||||
};
|
};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk::Texture,
|
gdk::Texture,
|
||||||
@ -59,7 +59,7 @@ impl Nex {
|
|||||||
.request
|
.request
|
||||||
.info
|
.info
|
||||||
.replace(i.into_permanent_redirect());
|
.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);
|
self.page.item_action.load.activate(Some(&r), false, true);
|
||||||
return; // prevents operation cancelled message on redirect
|
return; // prevents operation cancelled message on redirect
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use super::{Action as ItemAction, Profile, TabAction, WindowAction};
|
|||||||
use adw::TabPage;
|
use adw::TabPage;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use content::Content;
|
use content::Content;
|
||||||
use gtk::prelude::WidgetExt;
|
use gtk::prelude::{EditableExt, EntryExt, WidgetExt};
|
||||||
use input::Input;
|
use input::Input;
|
||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
use search::Search;
|
use search::Search;
|
||||||
@ -98,10 +98,10 @@ impl Page {
|
|||||||
pub fn snap_history(&self) {
|
pub fn snap_history(&self) {
|
||||||
self.item_action
|
self.item_action
|
||||||
.history
|
.history
|
||||||
.add(self.navigation.request.text(), true);
|
.add(self.navigation.request.entry.text(), true);
|
||||||
self.profile
|
self.profile
|
||||||
.history
|
.history
|
||||||
.open(self.navigation.request.text(), Some(self.title()))
|
.open(self.navigation.request.entry.text(), Some(self.title()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cleanup session for `Self`
|
/// Cleanup session for `Self`
|
||||||
@ -136,7 +136,7 @@ impl Page {
|
|||||||
// Make initial page history snap
|
// Make initial page history snap
|
||||||
self.profile
|
self.profile
|
||||||
.history
|
.history
|
||||||
.open(self.navigation.request.text(), Some(self.title()));
|
.open(self.navigation.request.entry.text(), Some(self.title()));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -178,6 +178,7 @@ impl Page {
|
|||||||
pub fn set_progress(&self, progress_fraction: f64) {
|
pub fn set_progress(&self, progress_fraction: f64) {
|
||||||
self.navigation
|
self.navigation
|
||||||
.request
|
.request
|
||||||
|
.entry
|
||||||
.set_progress_fraction(progress_fraction);
|
.set_progress_fraction(progress_fraction);
|
||||||
self.tab_page.set_loading(progress_fraction > 0.0)
|
self.tab_page.set_loading(progress_fraction > 0.0)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ impl Navigation {
|
|||||||
g_box.append(&home);
|
g_box.append(&home);
|
||||||
g_box.append(&history);
|
g_box.append(&history);
|
||||||
g_box.append(&reload);
|
g_box.append(&reload);
|
||||||
request.append_to(&g_box); // private member
|
g_box.append(&request.entry);
|
||||||
g_box.append(&bookmark.button);
|
g_box.append(&bookmark.button);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{Profile, Request, WindowAction};
|
use super::{Profile, Request, WindowAction};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
Button,
|
Button,
|
||||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
prelude::{ActionExt, ButtonExt, EditableExt, WidgetExt},
|
||||||
};
|
};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -23,12 +23,11 @@ impl Bookmark {
|
|||||||
action.bookmark.simple_action.name()
|
action.bookmark.simple_action.name()
|
||||||
))
|
))
|
||||||
.build();
|
.build();
|
||||||
update(profile, &button, &request.text());
|
update(profile, &button, &request.entry.text());
|
||||||
request.on_change({
|
request.entry.connect_changed({
|
||||||
let b = button.clone();
|
let b = button.clone();
|
||||||
let p = profile.clone();
|
let p = profile.clone();
|
||||||
let r = request.clone();
|
move |e| update(&p, &b, &e.text())
|
||||||
move || update(&p, &b, &r.text())
|
|
||||||
});
|
});
|
||||||
Self {
|
Self {
|
||||||
profile: profile.clone(),
|
profile: profile.clone(),
|
||||||
@ -40,7 +39,7 @@ impl Bookmark {
|
|||||||
pub fn toggle(&self, title: Option<&str>) {
|
pub fn toggle(&self, title: Option<&str>) {
|
||||||
let button = self.button.clone();
|
let button = self.button.clone();
|
||||||
let profile = self.profile.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());
|
let title = title.map(|t| t.to_string());
|
||||||
button.set_sensitive(false); // lock
|
button.set_sensitive(false); // lock
|
||||||
let has_bookmark = profile.bookmark.toggle(&query, title.as_deref()).unwrap();
|
let has_bookmark = profile.bookmark.toggle(&query, title.as_deref()).unwrap();
|
||||||
|
@ -27,8 +27,7 @@ const PREFIX_DOWNLOAD: &str = "download:";
|
|||||||
const PREFIX_SOURCE: &str = "source:";
|
const PREFIX_SOURCE: &str = "source:";
|
||||||
|
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
/// * keep it private to properly update some local dependencies on change (e.g. proxy resolver)
|
pub entry: Entry,
|
||||||
entry: Entry,
|
|
||||||
pub info: Rc<RefCell<Info>>,
|
pub info: Rc<RefCell<Info>>,
|
||||||
profile: Rc<Profile>,
|
profile: Rc<Profile>,
|
||||||
proxy_resolver: Rc<RefCell<Option<ProxyResolver>>>,
|
proxy_resolver: Rc<RefCell<Option<ProxyResolver>>>,
|
||||||
@ -179,7 +178,7 @@ impl Request {
|
|||||||
&& state.contains(StateFlags::ACTIVE | StateFlags::FOCUS_WITHIN)
|
&& state.contains(StateFlags::ACTIVE | StateFlags::FOCUS_WITHIN)
|
||||||
&& this.selection_bounds().is_none()
|
&& this.selection_bounds().is_none()
|
||||||
{
|
{
|
||||||
this.select_region(0, -1);
|
this.select_region(0, -1)
|
||||||
}
|
}
|
||||||
// Update last focus state
|
// Update last focus state
|
||||||
has_focus.replace(state.contains(StateFlags::FOCUS_WITHIN));
|
has_focus.replace(state.contains(StateFlags::FOCUS_WITHIN));
|
||||||
@ -291,27 +290,6 @@ impl Request {
|
|||||||
self.entry.text().starts_with("file://")
|
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)
|
/// Get [ProxyResolver](https://docs.gtk.org/gio/iface.ProxyResolver.html)
|
||||||
/// which is constructed for every `Request` entry change
|
/// which is constructed for every `Request` entry change
|
||||||
/// * useful on build new [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html)
|
/// * useful on build new [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html)
|
||||||
@ -320,15 +298,6 @@ impl Request {
|
|||||||
self.proxy_resolver.borrow().clone()
|
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
|
// Tools
|
||||||
|
|
||||||
/// Get request value with formatted `download` prefix
|
/// Get request value with formatted `download` prefix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user