Rename operations to edit history, improve formatting, add progress button

This commit is contained in:
Jeremy Soller 2024-07-11 15:32:21 -06:00
parent a4094bf75c
commit c3a28b3752
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
2 changed files with 42 additions and 23 deletions

View file

@ -68,6 +68,7 @@ pub enum Action {
AddToSidebar, AddToSidebar,
Copy, Copy,
Cut, Cut,
EditHistory,
EditLocation, EditLocation,
HistoryNext, HistoryNext,
HistoryPrevious, HistoryPrevious,
@ -84,7 +85,6 @@ pub enum Action {
OpenInNewWindow, OpenInNewWindow,
OpenTerminal, OpenTerminal,
OpenWith, OpenWith,
Operations,
Paste, Paste,
Properties, Properties,
Rename, Rename,
@ -115,6 +115,7 @@ impl Action {
Action::AddToSidebar => Message::AddToSidebar(entity_opt), Action::AddToSidebar => Message::AddToSidebar(entity_opt),
Action::Copy => Message::Copy(entity_opt), Action::Copy => Message::Copy(entity_opt),
Action::Cut => Message::Cut(entity_opt), Action::Cut => Message::Cut(entity_opt),
Action::EditHistory => Message::ToggleContextPage(ContextPage::EditHistory),
Action::EditLocation => Message::EditLocation(entity_opt), Action::EditLocation => Message::EditLocation(entity_opt),
Action::HistoryNext => Message::TabMessage(entity_opt, tab::Message::GoNext), Action::HistoryNext => Message::TabMessage(entity_opt, tab::Message::GoNext),
Action::HistoryPrevious => Message::TabMessage(entity_opt, tab::Message::GoPrevious), Action::HistoryPrevious => Message::TabMessage(entity_opt, tab::Message::GoPrevious),
@ -131,7 +132,6 @@ impl Action {
Action::OpenInNewWindow => Message::OpenInNewWindow(entity_opt), Action::OpenInNewWindow => Message::OpenInNewWindow(entity_opt),
Action::OpenTerminal => Message::OpenTerminal(entity_opt), Action::OpenTerminal => Message::OpenTerminal(entity_opt),
Action::OpenWith => Message::ToggleContextPage(ContextPage::OpenWith), Action::OpenWith => Message::ToggleContextPage(ContextPage::OpenWith),
Action::Operations => Message::ToggleContextPage(ContextPage::Operations),
Action::Paste => Message::Paste(entity_opt), Action::Paste => Message::Paste(entity_opt),
Action::Properties => Message::ToggleContextPage(ContextPage::Properties(None)), Action::Properties => Message::ToggleContextPage(ContextPage::Properties(None)),
Action::Rename => Message::Rename(entity_opt), Action::Rename => Message::Rename(entity_opt),
@ -273,8 +273,8 @@ impl From<widget::toaster::ToastMessage> for Message {
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ContextPage { pub enum ContextPage {
About, About,
EditHistory,
OpenWith, OpenWith,
Operations,
Properties(Option<ContextItem>), Properties(Option<ContextItem>),
Settings, Settings,
} }
@ -283,8 +283,8 @@ impl ContextPage {
fn title(&self) -> String { fn title(&self) -> String {
match self { match self {
Self::About => String::new(), Self::About => String::new(),
Self::EditHistory => fl!("edit-history"),
Self::OpenWith => fl!("open-with"), Self::OpenWith => fl!("open-with"),
Self::Operations => fl!("operations"),
Self::Properties(..) => fl!("properties"), Self::Properties(..) => fl!("properties"),
Self::Settings => fl!("settings"), Self::Settings => fl!("settings"),
} }
@ -652,7 +652,7 @@ impl App {
widget::settings::view_column(children).into() widget::settings::view_column(children).into()
} }
fn operations(&self) -> Element<Message> { fn edit_history(&self) -> Element<Message> {
let mut children = Vec::new(); let mut children = Vec::new();
//TODO: get height from theme? //TODO: get height from theme?
@ -662,7 +662,7 @@ impl App {
let mut section = widget::settings::view_section(fl!("pending")); let mut section = widget::settings::view_section(fl!("pending"));
for (_id, (op, progress)) in self.pending_operations.iter().rev() { for (_id, (op, progress)) in self.pending_operations.iter().rev() {
section = section.add(widget::column::with_children(vec![ 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) widget::progress_bar(0.0..=100.0, *progress)
.height(progress_bar_height) .height(progress_bar_height)
.into(), .into(),
@ -675,7 +675,7 @@ impl App {
let mut section = widget::settings::view_section(fl!("failed")); let mut section = widget::settings::view_section(fl!("failed"));
for (_id, (op, error)) in self.failed_operations.iter().rev() { for (_id, (op, error)) in self.failed_operations.iter().rev() {
section = section.add(widget::column::with_children(vec![ section = section.add(widget::column::with_children(vec![
widget::text(format!("{:?}", op)).into(), widget::text(op.pending_text()).into(),
widget::text(error).into(), widget::text(error).into(),
])); ]));
} }
@ -685,11 +685,15 @@ impl App {
if !self.complete_operations.is_empty() { if !self.complete_operations.is_empty() {
let mut section = widget::settings::view_section(fl!("complete")); let mut section = widget::settings::view_section(fl!("complete"));
for (_id, op) in self.complete_operations.iter().rev() { 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()); children.push(section.into());
} }
if children.is_empty() {
children.push(widget::text::body(fl!("no-history")).into());
}
widget::settings::view_column(children).into() widget::settings::view_column(children).into()
} }
@ -2114,8 +2118,8 @@ impl Application for App {
Some(match self.context_page { Some(match self.context_page {
ContextPage::About => self.about(), ContextPage::About => self.about(),
ContextPage::EditHistory => self.edit_history(),
ContextPage::OpenWith => self.open_with(), ContextPage::OpenWith => self.open_with(),
ContextPage::Operations => self.operations(),
ContextPage::Properties(entity) => self.properties(entity), ContextPage::Properties(entity) => self.properties(entity),
ContextPage::Settings => self.settings(), ContextPage::Settings => self.settings(),
}) })
@ -2354,19 +2358,35 @@ impl Application for App {
} }
fn header_end(&self) -> Vec<Element<Self::Message>> { fn header_end(&self) -> Vec<Element<Self::Message>> {
vec![if self.search_active { let mut elements = Vec::with_capacity(2);
widget::text_input::search_input("", &self.search_input)
.width(Length::Fixed(240.0)) if !self.pending_operations.is_empty() {
.id(self.search_id.clone()) elements.push(
.on_clear(Message::SearchClear) widget::button::text(format!("{}", self.pending_operations.len()))
.on_input(Message::SearchInput) .on_press(Message::ToggleContextPage(ContextPage::EditHistory))
.on_submit(Message::SearchSubmit) .into(),
.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 { } else {
widget::button::icon(widget::icon::from_name("system-search-symbolic")) elements.push(
.on_press(Message::SearchActivate) widget::button::icon(widget::icon::from_name("system-search-symbolic"))
.into() .on_press(Message::SearchActivate)
}] .into(),
)
}
elements
} }
/// Creates a view after each update. /// Creates a view after each update.

View file

@ -214,8 +214,7 @@ pub fn menu_bar<'a>(
menu::Item::Button(fl!("paste"), Action::Paste), menu::Item::Button(fl!("paste"), Action::Paste),
menu::Item::Button(fl!("select-all"), Action::SelectAll), menu::Item::Button(fl!("select-all"), Action::SelectAll),
menu::Item::Divider, menu::Item::Divider,
//TODO: edit history menu::Item::Button(fl!("history"), Action::EditHistory),
menu::Item::Button(fl!("operations"), Action::Operations),
], ],
), ),
), ),