use common helper for duplicated function

This commit is contained in:
yggverse 2025-02-13 18:31:34 +02:00
parent 6806f1876c
commit f2cdc7bc52
3 changed files with 20 additions and 36 deletions

View file

@ -1,5 +1,5 @@
use super::Page;
use gtk::glib::{GString, Uri};
use gtk::glib::Uri;
use std::rc::Rc;
pub enum Text {
@ -18,24 +18,9 @@ impl Text {
page.search.set(Some(widget.text_view));
page.set_title(&match widget.meta.title {
Some(title) => title.into(), // @TODO
None => uri_to_title(uri),
None => crate::tool::uri_to_title(uri),
});
page.set_progress(0.0);
page.window_action.find.simple_action.set_enabled(true);
}
}
/// Helper function, extract readable title from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
/// * useful as common placeholder when page title could not be detected
/// * this feature may be improved and moved outside @TODO already duplicated!
fn uri_to_title(uri: &Uri) -> GString {
let path = uri.path();
if path.split('/').last().unwrap_or_default().is_empty() {
match uri.host() {
Some(host) => host,
None => "Untitled".into(),
}
} else {
path
}
}