Add Clear Recents history to Recents nav bar context menu
This commit is contained in:
parent
395b4922e4
commit
3fcaaf1ed7
5 changed files with 34 additions and 9 deletions
27
src/app.rs
27
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 {
|
||||
|
|
|
|||
|
|
@ -1221,6 +1221,13 @@ fn uri_to_path(uri: String) -> Option<PathBuf> {
|
|||
})
|
||||
}
|
||||
|
||||
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<Item> {
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue