From accf5b2ba64e3dd3da99138eda010d87690a7469 Mon Sep 17 00:00:00 2001 From: Will Sheehan Date: Sat, 25 Apr 2026 00:00:29 -0700 Subject: [PATCH] Add button to clear recents --- i18n/en/cosmic_files.ftl | 3 +++ src/app.rs | 8 ++++++++ src/tab.rs | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 69a76c6..2c86071 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -62,6 +62,9 @@ empty-trash = Empty trash empty-trash-title = Empty trash? empty-trash-warning = Items in the Trash folder will be permanently deleted +## Clear Recents +clear-recents = Clear Recents + ## Mount Error Dialog mount-error = Unable to access drive diff --git a/src/app.rs b/src/app.rs index feca9c5..cd01780 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4588,6 +4588,14 @@ impl Application for App { tab::Command::DropFiles(to, from) => { commands.push(self.update(Message::PasteContents(to, from))); } + tab::Command::ClearRecents => { + match recently_used_xbel::clear_recently_used() { + Ok(()) => {} + Err(err) => { + log::warn!("failed to clear recents history: {}", err); + } + } + } tab::Command::EmptyTrash => { return self.push_dialog( DialogPage::EmptyTrash, diff --git a/src/tab.rs b/src/tab.rs index 94eacdd..51cbd24 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1683,6 +1683,7 @@ pub enum Command { ContextMenu(Option, Option), Delete(Vec), DropFiles(PathBuf, ClipboardPaste), + ClearRecents, EmptyTrash, #[cfg(feature = "desktop")] ExecEntryAction(cosmic::desktop::DesktopEntryData, usize), @@ -1722,6 +1723,7 @@ pub enum Message { EditLocationSubmit, EditLocationTab, OpenInNewTab(PathBuf), + ClearRecents, EmptyTrash, #[cfg(feature = "desktop")] ExecEntryAction(Option, usize), @@ -3697,6 +3699,9 @@ impl Tab { Message::OpenInNewTab(path) => { commands.push(Command::OpenInNewTab(path)); } + Message::ClearRecents => { + commands.push(Command::ClearRecents); + } Message::EmptyTrash => { commands.push(Command::EmptyTrash); } @@ -6216,6 +6221,24 @@ impl Tab { ); } } + Location::Recents | Location::Search(SearchLocation::Recents, ..) => { + if let Some(items) = self.items_opt() + && !items.is_empty() + { + tab_column = tab_column.push( + widget::layer_container(widget::row::with_children([ + widget::space::horizontal().into(), + widget::button::standard(fl!("clear-recents")) + .on_press(Message::ClearRecents) + .into(), + ])) + .padding([space_xxs, space_xs]) + .layer(cosmic_theme::Layer::Primary) + .apply(widget::container) + .padding([0, 0, 7, 0]), + ); + } + } Location::Network(uri, _display_name, _path) if uri == "network:///" => { tab_column = tab_column.push( widget::layer_container(widget::row::with_children([