From af6af1cf3531c40ce82d6ebc74f722dcc1383461 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 29 Jan 2024 11:09:05 -0700 Subject: [PATCH] Improvements to breadcrumbs, say Home instead of folder name --- i18n/en/cosmic_files.ftl | 1 + src/main.rs | 23 +++++++---------------- src/tab.rs | 32 ++++++++++++++++++++++++-------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 07441db..3477827 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -1,6 +1,7 @@ empty-folder = Empty folder empty-folder-hidden = Empty folder (has hidden items) filesystem = Filesystem +home = Home trash = Trash # List view diff --git a/src/main.rs b/src/main.rs index 975a247..25858e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -321,9 +321,15 @@ impl Application for App { let app_themes = vec![fl!("match-desktop"), fl!("dark"), fl!("light")]; let mut nav_model = segmented_button::ModelBuilder::default(); + if let Some(dir) = dirs::home_dir() { + nav_model = nav_model.insert(move |b| { + b.text(fl!("home")) + .icon(widget::icon::icon(tab::folder_icon_symbolic(&dir, 16)).size(16)) + .data(Location::Path(dir.clone())) + }); + } //TODO: Sort by name? for dir_opt in &[ - dirs::home_dir(), dirs::document_dir(), dirs::download_dir(), dirs::audio_dir(), @@ -669,21 +675,6 @@ impl Application for App { ] } - fn header_center(&self) -> Vec> { - let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing; - - let entity = self.tab_model.active(); - let tab = match self.tab_model.data::(entity) { - Some(some) => some, - None => return Vec::new(), - }; - - vec![tab - .breadcrumbs_view(&self.core) - .map(move |message| Message::TabMessage(Some(entity), message)) - .into()] - } - fn header_end(&self) -> Vec> { vec![ //TODO: use defined space diff --git a/src/tab.rs b/src/tab.rs index 723e0ac..72027a0 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -4,7 +4,11 @@ use cosmic::{ iced::{ alignment::{Horizontal, Vertical}, keyboard::Modifiers, - Alignment, Length, Point, + //TODO: export in cosmic::widget + widget::horizontal_rule, + Alignment, + Length, + Point, }, theme, widget, Element, }; @@ -626,9 +630,11 @@ impl Tab { widget::icon::icon(folder_icon_symbolic(&ancestor, 16)) .size(16), ); + row = row.push(widget::text(fl!("home"))); found_home = true; + } else { + row = row.push(widget::text(name.to_string_lossy().to_string())); } - row = row.push(widget::text(name.to_string_lossy().to_string())); } None => { row = row.push( @@ -641,14 +647,19 @@ impl Tab { } if !children.is_empty() { - children.push(widget::text("/").into()); + children.push( + widget::icon::from_name("go-next-symbolic") + .size(16) + .icon() + .into(), + ); } children.push( widget::button(row) .padding(space_xxxs) .on_press(Message::Location(Location::Path(ancestor))) - .style(theme::Button::Text) + .style(theme::Button::Link) .into(), ); @@ -676,8 +687,8 @@ impl Tab { } children.push(widget::horizontal_space(Length::Fill).into()); - widget::container(widget::row::with_children(children).align_items(Alignment::Center)) - .style(theme::Container::Primary) + widget::row::with_children(children) + .align_items(Alignment::Center) .into() } @@ -765,6 +776,8 @@ impl Tab { let mut children: Vec> = Vec::new(); + children.push(self.breadcrumbs_view(core)); + children.push( widget::row::with_children(vec![ widget::text::heading(fl!("name")) @@ -784,8 +797,7 @@ impl Tab { .into(), ); - //TODO: export in cosmic::widget - children.push(cosmic::iced::widget::horizontal_rule(1).into()); + children.push(horizontal_rule(1).into()); if let Some(ref items) = self.items_opt { let mut count = 0; @@ -797,6 +809,10 @@ impl Tab { continue; } + if count > 0 { + children.push(horizontal_rule(1).into()); + } + let modified_text = match &item.metadata { ItemMetadata::Path(metadata, _children) => match metadata.modified() { Ok(time) => chrono::DateTime::::from(time)