fix blank menu item labels

This commit is contained in:
yggverse 2025-02-03 20:21:18 +02:00
parent 7fc25fe4f5
commit 8533e9daab

View file

@ -1,7 +1,7 @@
use super::{BrowserAction, Profile, WindowAction}; use super::{BrowserAction, Profile, WindowAction};
use gtk::{ use gtk::{
gio::{self}, gio::{self},
glib::{gformat, GString, Uri}, glib::{GString, Uri},
prelude::{ActionExt, ToVariant}, prelude::{ActionExt, ToVariant},
Align, MenuButton, Align, MenuButton,
}; };
@ -272,12 +272,8 @@ fn ellipsize(value: &str, limit: usize) -> String {
/// as [MenuItem](https://docs.gtk.org/gio/class.MenuItem.html) label /// as [MenuItem](https://docs.gtk.org/gio/class.MenuItem.html) label
fn uri_to_label(uri: &Uri, is_parent: bool) -> GString { fn uri_to_label(uri: &Uri, is_parent: bool) -> GString {
let path = uri.path(); let path = uri.path();
// Show hostname for index pages (or entire URL on possible unwrap failure) if path == "/" || path.is_empty() || is_parent {
if path == "/" {
uri.host().unwrap_or(uri.to_str()) uri.host().unwrap_or(uri.to_str())
// Parental item names have some format exception
} else if is_parent {
gformat!("{}{}", uri.host().unwrap_or(uri.to_str()), uri.path())
} else { } else {
path path
} }