From 60009324c86a15cd1822a3b6ab838f56f6d90fd3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 23 Sep 2024 11:59:05 -0600 Subject: [PATCH] Add previous, next, and open to preview --- src/app.rs | 8 ++-- src/dialog.rs | 6 +-- src/tab.rs | 107 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 85 insertions(+), 36 deletions(-) diff --git a/src/app.rs b/src/app.rs index 7b59d81..70e17e0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -157,7 +157,7 @@ impl Action { Action::MoveToTrash => Message::MoveToTrash(entity_opt), Action::NewFile => Message::NewItem(entity_opt, false), Action::NewFolder => Message::NewItem(entity_opt, true), - Action::Open => Message::TabMessage(entity_opt, tab::Message::Open), + Action::Open => Message::TabMessage(entity_opt, tab::Message::Open(None)), Action::OpenInNewTab => Message::OpenInNewTab(entity_opt), Action::OpenInNewWindow => Message::OpenInNewWindow(entity_opt), Action::OpenItemLocation => Message::OpenItemLocation(entity_opt), @@ -969,14 +969,14 @@ impl App { let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); match kind { PreviewKind::Custom(PreviewItem(item)) => { - children.push(item.property_view(IconSizes::default())); + children.push(item.preview_view(IconSizes::default())); } PreviewKind::Location(location) => { if let Some(tab) = self.tab_model.data::(entity) { if let Some(items) = tab.items_opt() { for item in items.iter() { if item.location_opt.as_ref() == Some(location) { - children.push(item.property_view(tab.config.icon_sizes)); + children.push(item.preview_view(tab.config.icon_sizes)); // Only show one property view to avoid issues like hangs when generating // preview images on thousands of files break; @@ -990,7 +990,7 @@ impl App { if let Some(items) = tab.items_opt() { for item in items.iter() { if item.selected { - children.push(item.property_view(tab.config.icon_sizes)); + children.push(item.preview_view(tab.config.icon_sizes)); // Only show one property view to avoid issues like hangs when generating // preview images on thousands of files break; diff --git a/src/dialog.rs b/src/dialog.rs index bd46e42..a9faf74 100644 --- a/src/dialog.rs +++ b/src/dialog.rs @@ -393,13 +393,13 @@ impl App { let mut children = Vec::with_capacity(1); match kind { PreviewKind::Custom(PreviewItem(item)) => { - children.push(item.property_view(IconSizes::default())); + children.push(item.preview_view(IconSizes::default())); } PreviewKind::Location(location) => { if let Some(items) = self.tab.items_opt() { for item in items.iter() { if item.location_opt.as_ref() == Some(location) { - children.push(item.property_view(self.tab.config.icon_sizes)); + children.push(item.preview_view(self.tab.config.icon_sizes)); // Only show one property view to avoid issues like hangs when generating // preview images on thousands of files break; @@ -411,7 +411,7 @@ impl App { if let Some(items) = self.tab.items_opt() { for item in items.iter() { if item.selected { - children.push(item.property_view(self.tab.config.icon_sizes)); + children.push(item.preview_view(self.tab.config.icon_sizes)); // Only show one property view to avoid issues like hangs when generating // preview images on thousands of files break; diff --git a/src/tab.rs b/src/tab.rs index 36742b7..d2cf4a9 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -845,7 +845,7 @@ pub enum Message { ItemUp, Location(Location), LocationUp, - Open, + Open(Option), RightClick(Option), MiddleClick(usize), Scroll(Viewport), @@ -1025,10 +1025,40 @@ impl Item { column.into() } - pub fn property_view(&self, sizes: IconSizes) -> Element<'static, app::Message> { - let cosmic_theme::Spacing { space_xxxs, .. } = theme::active().cosmic().spacing; + pub fn preview_view(&self, sizes: IconSizes) -> Element<'static, app::Message> { + let cosmic_theme::Spacing { + space_xxxs, + space_xxs, + space_m, + .. + } = theme::active().cosmic().spacing; - let mut column = widget::column().spacing(space_xxxs); + let mut column = widget::column().spacing(space_m); + + let mut row = widget::row::with_capacity(3).spacing(space_xxs); + row = row.push( + widget::button::icon(widget::icon::from_name("go-previous-symbolic")) + .on_press(app::Message::TabMessage(None, Message::ItemLeft)), + ); + row = row.push( + widget::button::icon(widget::icon::from_name("go-next-symbolic")) + .on_press(app::Message::TabMessage(None, Message::ItemRight)), + ); + /* + match self + .thumbnail_opt + .as_ref() + .unwrap_or(&ItemThumbnail::NotImage) + { + ItemThumbnail::NotImage => {} + _ => { + row = row.push(widget::button::icon(widget::icon::from_name( + "window-maximize-symbolic", + ))); + } + } + */ + column = column.push(row); column = column.push(widget::row::with_children(vec![ widget::horizontal_space(Length::Fill).into(), @@ -1036,37 +1066,38 @@ impl Item { widget::horizontal_space(Length::Fill).into(), ])); - column = column.push(widget::text::heading(self.name.clone())); - - column = column.push(widget::text(format!("Type: {}", self.mime))); - + let mut details = widget::column().spacing(space_xxxs); + details = details.push(widget::text::heading(self.name.clone())); + details = details.push(widget::text(format!("Type: {}", self.mime))); //TODO: translate! //TODO: correct display of folder size? match &self.metadata { ItemMetadata::Path { metadata, children } => { if metadata.is_dir() { - column = column.push(widget::text(format!("Items: {}", children))); + details = details.push(widget::text(format!("Items: {}", children))); } else { - column = column.push(widget::text(format!( + details = details.push(widget::text(format!( "Size: {}", format_size(metadata.len()) ))); } if let Ok(time) = metadata.created() { - column = column.push(widget::text(format!("Created: {}", format_time(time)))); + details = details.push(widget::text(format!("Created: {}", format_time(time)))); } if let Ok(time) = metadata.modified() { - column = column.push(widget::text(format!("Modified: {}", format_time(time)))); + details = + details.push(widget::text(format!("Modified: {}", format_time(time)))); } if let Ok(time) = metadata.accessed() { - column = column.push(widget::text(format!("Accessed: {}", format_time(time)))); + details = + details.push(widget::text(format!("Accessed: {}", format_time(time)))); } #[cfg(not(target_os = "windows"))] { - column = column.push( + details = details.push( widget::Row::new() .push(widget::text(format!("{}:", fl!("owner")))) .push(widget::text(format_permissions_owner( @@ -1080,7 +1111,7 @@ impl Item { .spacing(10), ); - column = column.push( + details = details.push( widget::Row::new() .push(widget::text(format!("{}:", fl!("group")))) .push(widget::text(format_permissions_owner( @@ -1094,7 +1125,7 @@ impl Item { .spacing(10), ); - column = column.push( + details = details.push( widget::Row::new() .push(widget::text(format!("{}", fl!("other")))) .push(widget::text(format!( @@ -1109,6 +1140,13 @@ impl Item { //TODO: other metadata types } } + column = column.push(details); + + if let Some(path) = self.path_opt() { + column = column.push(widget::button::standard(fl!("open")).on_press( + app::Message::TabMessage(None, Message::Open(Some(path.to_path_buf()))), + )); + } column.into() } @@ -2031,21 +2069,32 @@ impl Tab { } } } - Message::Open => { - if let Some(ref mut items) = self.items_opt { - for item in items.iter() { - if item.selected { - if let Some(location) = &item.location_opt { - if item.metadata.is_dir() { - //TODO: allow opening multiple tabs? - cd = Some(location.clone()); - } else { - if let Location::Path(path) = location { - commands.push(Command::OpenFile(path.clone())); + Message::Open(path_opt) => { + match path_opt { + Some(path) => { + if path.is_dir() { + cd = Some(Location::Path(path)); + } else { + commands.push(Command::OpenFile(path)); + } + } + None => { + if let Some(ref mut items) = self.items_opt { + for item in items.iter() { + if item.selected { + if let Some(location) = &item.location_opt { + if item.metadata.is_dir() { + //TODO: allow opening multiple tabs? + cd = Some(location.clone()); + } else { + if let Location::Path(path) = location { + commands.push(Command::OpenFile(path.clone())); + } + } + } else { + //TODO: open properties? } } - } else { - //TODO: open properties? } } }