Skip to content

Commit

Permalink
make navigation entries private
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Jan 27, 2025
1 parent 3d1a072 commit 51e3f54
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/app/browser/window/header/bar/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{BrowserAction, Profile, WindowAction};
use gtk::{
gio::{self},
glib::{gformat, GString, Uri},
prelude::{ActionExt, EditableExt, ToVariant},
prelude::{ActionExt, ToVariant},
Align, MenuButton,
};
use indexmap::IndexMap;
Expand Down Expand Up @@ -210,7 +210,7 @@ impl Menu for MenuButton {
// Recently closed history
main_history_tab.remove_all();
for item in profile.history.memory.tab.recent() {
let item_request = item.page.navigation.request.text(); // @TODO restore entire `Item`
let item_request = item.page.navigation.request(); // @TODO restore entire `Item`
let menu_item = gio::MenuItem::new(Some(&ellipsize(&item_request, LABEL_MAX_LENGTH)), None);
menu_item.set_action_and_target_value(Some(&format!(
"{}.{}",
Expand Down
4 changes: 2 additions & 2 deletions src/app/browser/window/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use error::Error;
use gtk::{
gio::Icon,
glib::{DateTime, Propagation},
prelude::{ActionExt, EditableExt},
prelude::ActionExt,
};
pub use item::Item;
use menu::Menu;
Expand Down Expand Up @@ -235,7 +235,7 @@ impl Tab {
if let Some(item) = self.item(tab_page_position) {
if let Some(home) = item.page.navigation.home() {
let home = home.to_string();
item.page.navigation.request.set_text(&home);
item.page.navigation.set_request(&home);
item.client.handle(&home, true);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/browser/window/tab/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Profile;
use action::Action;
use adw::TabView;
use client::Client;
use gtk::prelude::{ActionMapExt, Cast, EditableExt};
use gtk::prelude::{ActionMapExt, Cast};
use page::Page;
use sqlite::Transaction;
use std::rc::Rc;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl Item {
this.set_enabled(false);
if let Some(uri) = page.navigation.home() {
let request = uri.to_string();
page.navigation.request.set_text(&request);
page.navigation.set_request(&request);
client.handle(&request, true);
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Item {
let client = client.clone();
move |request, is_history| {
if let Some(text) = request {
page.navigation.request.set_text(&text);
page.navigation.set_request(&text);
client.handle(&text, is_history);
}
}
Expand All @@ -122,13 +122,13 @@ impl Item {
let page = page.clone();
let client = client.clone();
move |_, _| {
client.handle(&page.navigation.request.text(), false);
client.handle(&page.navigation.request(), false);
}
});

// Handle immediately on request
if let Some(text) = request {
page.navigation.request.set_text(text);
page.navigation.set_request(text);
if is_load {
client.handle(text, true);
}
Expand Down
10 changes: 3 additions & 7 deletions src/app/browser/window/tab/item/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use feature::Feature;
use gtk::{
gio::Cancellable,
glib::{Uri, UriFlags},
prelude::{ActionExt, CancellableExt, EntryExt},
prelude::{ActionExt, CancellableExt},
};
use std::{cell::Cell, rc::Rc};
use subject::Subject;
Expand Down Expand Up @@ -58,11 +58,7 @@ impl Client {
self.subject.page.search.unset();
self.subject.page.input.unset();
self.subject.tab_page.set_title("Loading..");
self.subject
.page
.navigation
.request
.set_progress_fraction(0.1);
self.subject.page.navigation.set_progress_fraction(0.1);

self.subject.tab_page.set_loading(true);

Expand All @@ -86,7 +82,7 @@ impl Client {
"Scheme `{scheme}` yet not supported"
)));
subject.tab_page.set_title(&status.title());
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
}
},
Expand Down
47 changes: 19 additions & 28 deletions src/app/browser/window/tab/item/client/driver/gemini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ use gtk::{
gdk_pixbuf::Pixbuf,
gio::{Cancellable, SocketClientEvent},
glib::{Priority, Uri},
prelude::{EntryExt, SocketClientExt},
};
use gtk::{
glib::Bytes,
prelude::{EditableExt, FileExt},
prelude::SocketClientExt,
};
use gtk::{glib::Bytes, prelude::FileExt};
use std::{cell::Cell, path::MAIN_SEPARATOR, rc::Rc, time::Duration};

/// Multi-protocol client API for `Page` object
Expand Down Expand Up @@ -59,7 +56,6 @@ impl Gemini {
subject
.page
.navigation
.request
.set_progress_fraction(progress_fraction);
}
});
Expand Down Expand Up @@ -129,11 +125,7 @@ impl Gemini {
}
});
self.subject.tab_page.set_title("Titan input");
self.subject
.page
.navigation
.request
.set_progress_fraction(0.0);
self.subject.page.navigation.set_progress_fraction(0.0);
self.subject.tab_page.set_loading(false);
}
_ => panic!(), // unexpected
Expand Down Expand Up @@ -201,7 +193,7 @@ fn handle(
Some(1024),
);
}
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&title);
redirects.replace(0); // reset
Expand Down Expand Up @@ -273,7 +265,7 @@ fn handle(
}
},
);
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -296,7 +288,7 @@ fn handle(
Some(title) => title.into(), // @TODO
None => uri_to_title(&uri),
});
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.page.window_action
.find
Expand All @@ -307,7 +299,7 @@ fn handle(
Err(e) => {
let status = subject.page.content.to_status_failure();
status.set_description(Some(&e.to_string()));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand Down Expand Up @@ -351,7 +343,7 @@ fn handle(
subject.tab_page.set_title(&status.title());
}
}
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
redirects.replace(0); // reset
},
Expand All @@ -360,7 +352,7 @@ fn handle(
Err(e) => {
let status = subject.page.content.to_status_failure();
status.set_description(Some(&e.to_string()));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -374,7 +366,7 @@ fn handle(
.content
.to_status_mime(mime, Some((&subject.page.item_action, &uri)));
status.set_description(Some(&format!("Content type `{mime}` yet not supported")));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -383,7 +375,7 @@ fn handle(
None => {
let status = subject.page.content.to_status_failure();
status.set_description(Some("MIME type not found"));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand Down Expand Up @@ -421,7 +413,7 @@ fn handle(
if total > 5 {
let status = subject.page.content.to_status_failure();
status.set_description(Some("Redirection limit reached"));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -432,16 +424,15 @@ fn handle(
|| uri.host() != target.host() {
let status = subject.page.content.to_status_failure();
status.set_description(Some("External redirects not allowed by protocol specification"));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
// Valid
} else {
if matches!(response.meta.status, Status::PermanentRedirect) {
subject.page.navigation
.request
.set_text(&uri.to_string());
.set_request(&uri.to_string());
}
redirects.replace(total);
subject.page.item_action.load.activate(Some(&target.to_string()), false);
Expand All @@ -450,7 +441,7 @@ fn handle(
Err(e) => {
let status = subject.page.content.to_status_failure();
status.set_description(Some(&e.to_string()));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -459,7 +450,7 @@ fn handle(
None => {
let status = subject.page.content.to_status_failure();
status.set_description(Some("Redirection target not found"));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -478,15 +469,15 @@ fn handle(
None => response.meta.status.to_string(),
}));

subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
}
error => {
let status = subject.page.content.to_status_failure();
status.set_description(Some(&error.to_string()));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand All @@ -496,7 +487,7 @@ fn handle(
Err(e) => {
let status = subject.page.content.to_status_failure();
status.set_description(Some(&e.to_string()));
subject.page.navigation.request.set_progress_fraction(0.0);
subject.page.navigation.set_progress_fraction(0.0);
subject.tab_page.set_loading(false);
subject.tab_page.set_title(&status.title());
redirects.replace(0); // reset
Expand Down
26 changes: 18 additions & 8 deletions src/app/browser/window/tab/item/page/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{ItemAction, Profile, TabAction, WindowAction};
use bookmark::Bookmark;
use gtk::{
glib::{GString, Uri},
prelude::{BoxExt, EditableExt, WidgetExt},
prelude::{BoxExt, EditableExt, EntryExt, WidgetExt},
Box, Button, Entry, Orientation,
};
use history::History;
Expand All @@ -23,10 +23,10 @@ const MARGIN: i32 = 6;
const SPACING: i32 = 6;

pub struct Navigation {
pub home: Button,
pub reload: Button,
pub bookmark: Button,
pub request: Entry,
//home: Button,
//reload: Button,
//bookmark: Button,
request: Entry,
pub g_box: Box,
}

Expand Down Expand Up @@ -62,10 +62,10 @@ impl Navigation {
g_box.append(&bookmark);

Self {
home,
//home,
request,
reload,
bookmark,
//reload,
//bookmark,
g_box,
}
}
Expand Down Expand Up @@ -135,6 +135,16 @@ impl Navigation {
self.request.grab_focus()
}

// Setters

pub fn set_request(&self, value: &str) {
self.request.set_text(value);
}

pub fn set_progress_fraction(&self, fraction: f64) {
self.request.set_progress_fraction(fraction);
}

pub fn to_download(&self) {
self.request.to_download();
}
Expand Down

0 comments on commit 51e3f54

Please sign in to comment.