From 3fcaaf1ed77662df894dcf0faf8f6da18c109215 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 18 Feb 2026 09:08:53 -0700 Subject: [PATCH] Add Clear Recents history to Recents nav bar context menu --- Cargo.lock | 5 +++-- Cargo.toml | 2 +- i18n/en/cosmic_files.ftl | 1 + src/app.rs | 27 +++++++++++++++++++++------ src/tab.rs | 8 ++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7d2010..9d197b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6169,8 +6169,9 @@ dependencies = [ [[package]] name = "recently-used-xbel" -version = "1.1.0" -source = "git+https://github.com/pop-os/recently-used-xbel.git#eeba9e08b0446175d7dd4f526d21ea867ed37e87" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63ab2febcd4f0245fbadd0b44f7cd35207128a7b210a089e65740625a45399b5" dependencies = [ "chrono", "dirs 5.0.1", diff --git a/Cargo.toml b/Cargo.toml index 3650136..d6d443e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,7 @@ i18n-embed = { version = "0.16", features = [ i18n-embed-fl = "0.10" rust-embed = "8" slotmap = "1.1.1" -recently-used-xbel = { git = "https://github.com/pop-os/recently-used-xbel.git" } +recently-used-xbel = "1.2.0" zip = "7" uzers = "0.12.2" md-5 = "0.10.6" diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 1771d8a..03bfc32 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -315,6 +315,7 @@ type-to-search-select = Selects the first matching file or folder # Context menu add-to-sidebar = Add to sidebar +clear-recents-history = Clear Recents history compress = Compress copy-to = Copy to... delete-permanently = Delete permanently diff --git a/src/app.rs b/src/app.rs index e78c02c..8a9feed 100644 --- a/src/app.rs +++ b/src/app.rs @@ -313,13 +313,14 @@ pub enum PreviewKind { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum NavMenuAction { + ClearRecents, + EmptyTrash, Open(segmented_button::Entity), OpenWith(segmented_button::Entity), OpenInNewTab(segmented_button::Entity), OpenInNewWindow(segmented_button::Entity), Preview(segmented_button::Entity), RemoveFromSidebar(segmented_button::Entity), - EmptyTrash, } impl MenuAction for NavMenuAction { @@ -2420,6 +2421,15 @@ impl Application for App { NavMenuAction::RemoveFromSidebar(entity), )); } + + if matches!(location_opt, Some(Location::Recents)) && tab::has_recents() { + items.push(cosmic::widget::menu::Item::Button( + fl!("clear-recents-history"), + None, + NavMenuAction::ClearRecents, + )); + } + if matches!(location_opt, Some(Location::Trash)) && !trash::os_limited::is_empty().unwrap_or(true) { @@ -4697,6 +4707,16 @@ impl Application for App { } } Message::NavMenuAction(action) => match action { + NavMenuAction::ClearRecents => match recently_used_xbel::clear_recently_used() { + Ok(()) => {} + Err(err) => { + log::warn!("failed to clear recents history: {}", err); + } + }, + NavMenuAction::EmptyTrash => { + return self + .push_dialog(DialogPage::EmptyTrash, Some(EMPTY_TRASH_BUTTON_ID.clone())); + } NavMenuAction::Open(entity) => { if let Some(path) = self .nav_model @@ -4841,11 +4861,6 @@ impl Application for App { return self.update_config(); } } - - NavMenuAction::EmptyTrash => { - return self - .push_dialog(DialogPage::EmptyTrash, Some(EMPTY_TRASH_BUTTON_ID.clone())); - } }, Message::Recents => { if self.config.show_recents { diff --git a/src/tab.rs b/src/tab.rs index 18cb0dd..1cd29aa 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -1221,6 +1221,13 @@ fn uri_to_path(uri: String) -> Option { }) } +pub fn has_recents() -> bool { + match recently_used_xbel::parse_file() { + Ok(recent_files) => !recent_files.bookmarks.is_empty(), + Err(_) => false, + } +} + pub fn scan_recents(sizes: IconSizes) -> Vec { let recent_files = match recently_used_xbel::parse_file() { Ok(recent_files) => recent_files, @@ -5928,6 +5935,7 @@ impl Tab { tab_column = tab_column.push(popover); } match &self.location { + Location::Recents => {} Location::Trash => { if let Some(items) = self.items_opt() && !items.is_empty()