From c3a28b3752d23c92f4e3d199eac29fac4fad58d0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 11 Jul 2024 15:32:21 -0600 Subject: [PATCH] Rename operations to edit history, improve formatting, add progress button --- src/app.rs | 62 +++++++++++++++++++++++++++++++++++------------------ src/menu.rs | 3 +-- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/app.rs b/src/app.rs index 64b5812..bf1a0dd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -68,6 +68,7 @@ pub enum Action { AddToSidebar, Copy, Cut, + EditHistory, EditLocation, HistoryNext, HistoryPrevious, @@ -84,7 +85,6 @@ pub enum Action { OpenInNewWindow, OpenTerminal, OpenWith, - Operations, Paste, Properties, Rename, @@ -115,6 +115,7 @@ impl Action { Action::AddToSidebar => Message::AddToSidebar(entity_opt), Action::Copy => Message::Copy(entity_opt), Action::Cut => Message::Cut(entity_opt), + Action::EditHistory => Message::ToggleContextPage(ContextPage::EditHistory), Action::EditLocation => Message::EditLocation(entity_opt), Action::HistoryNext => Message::TabMessage(entity_opt, tab::Message::GoNext), Action::HistoryPrevious => Message::TabMessage(entity_opt, tab::Message::GoPrevious), @@ -131,7 +132,6 @@ impl Action { Action::OpenInNewWindow => Message::OpenInNewWindow(entity_opt), Action::OpenTerminal => Message::OpenTerminal(entity_opt), Action::OpenWith => Message::ToggleContextPage(ContextPage::OpenWith), - Action::Operations => Message::ToggleContextPage(ContextPage::Operations), Action::Paste => Message::Paste(entity_opt), Action::Properties => Message::ToggleContextPage(ContextPage::Properties(None)), Action::Rename => Message::Rename(entity_opt), @@ -273,8 +273,8 @@ impl From for Message { #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ContextPage { About, + EditHistory, OpenWith, - Operations, Properties(Option), Settings, } @@ -283,8 +283,8 @@ impl ContextPage { fn title(&self) -> String { match self { Self::About => String::new(), + Self::EditHistory => fl!("edit-history"), Self::OpenWith => fl!("open-with"), - Self::Operations => fl!("operations"), Self::Properties(..) => fl!("properties"), Self::Settings => fl!("settings"), } @@ -652,7 +652,7 @@ impl App { widget::settings::view_column(children).into() } - fn operations(&self) -> Element { + fn edit_history(&self) -> Element { let mut children = Vec::new(); //TODO: get height from theme? @@ -662,7 +662,7 @@ impl App { let mut section = widget::settings::view_section(fl!("pending")); for (_id, (op, progress)) in self.pending_operations.iter().rev() { section = section.add(widget::column::with_children(vec![ - widget::text(format!("{:?}", op)).into(), + widget::text(op.pending_text()).into(), widget::progress_bar(0.0..=100.0, *progress) .height(progress_bar_height) .into(), @@ -675,7 +675,7 @@ impl App { let mut section = widget::settings::view_section(fl!("failed")); for (_id, (op, error)) in self.failed_operations.iter().rev() { section = section.add(widget::column::with_children(vec![ - widget::text(format!("{:?}", op)).into(), + widget::text(op.pending_text()).into(), widget::text(error).into(), ])); } @@ -685,11 +685,15 @@ impl App { if !self.complete_operations.is_empty() { let mut section = widget::settings::view_section(fl!("complete")); for (_id, op) in self.complete_operations.iter().rev() { - section = section.add(widget::text(format!("{:?}", op))); + section = section.add(widget::text(op.completed_text())); } children.push(section.into()); } + if children.is_empty() { + children.push(widget::text::body(fl!("no-history")).into()); + } + widget::settings::view_column(children).into() } @@ -2114,8 +2118,8 @@ impl Application for App { Some(match self.context_page { ContextPage::About => self.about(), + ContextPage::EditHistory => self.edit_history(), ContextPage::OpenWith => self.open_with(), - ContextPage::Operations => self.operations(), ContextPage::Properties(entity) => self.properties(entity), ContextPage::Settings => self.settings(), }) @@ -2354,19 +2358,35 @@ impl Application for App { } fn header_end(&self) -> Vec> { - vec![if self.search_active { - widget::text_input::search_input("", &self.search_input) - .width(Length::Fixed(240.0)) - .id(self.search_id.clone()) - .on_clear(Message::SearchClear) - .on_input(Message::SearchInput) - .on_submit(Message::SearchSubmit) - .into() + let mut elements = Vec::with_capacity(2); + + if !self.pending_operations.is_empty() { + elements.push( + widget::button::text(format!("{}", self.pending_operations.len())) + .on_press(Message::ToggleContextPage(ContextPage::EditHistory)) + .into(), + ); + } + + if self.search_active { + elements.push( + widget::text_input::search_input("", &self.search_input) + .width(Length::Fixed(240.0)) + .id(self.search_id.clone()) + .on_clear(Message::SearchClear) + .on_input(Message::SearchInput) + .on_submit(Message::SearchSubmit) + .into(), + ) } else { - widget::button::icon(widget::icon::from_name("system-search-symbolic")) - .on_press(Message::SearchActivate) - .into() - }] + elements.push( + widget::button::icon(widget::icon::from_name("system-search-symbolic")) + .on_press(Message::SearchActivate) + .into(), + ) + } + + elements } /// Creates a view after each update. diff --git a/src/menu.rs b/src/menu.rs index 33460c0..70163ac 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -214,8 +214,7 @@ pub fn menu_bar<'a>( menu::Item::Button(fl!("paste"), Action::Paste), menu::Item::Button(fl!("select-all"), Action::SelectAll), menu::Item::Divider, - //TODO: edit history - menu::Item::Button(fl!("operations"), Action::Operations), + menu::Item::Button(fl!("history"), Action::EditHistory), ], ), ),