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
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -6169,8 +6169,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "recently-used-xbel"
|
name = "recently-used-xbel"
|
||||||
version = "1.1.0"
|
version = "1.2.0"
|
||||||
source = "git+https://github.com/pop-os/recently-used-xbel.git#eeba9e08b0446175d7dd4f526d21ea867ed37e87"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63ab2febcd4f0245fbadd0b44f7cd35207128a7b210a089e65740625a45399b5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ i18n-embed = { version = "0.16", features = [
|
||||||
i18n-embed-fl = "0.10"
|
i18n-embed-fl = "0.10"
|
||||||
rust-embed = "8"
|
rust-embed = "8"
|
||||||
slotmap = "1.1.1"
|
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"
|
zip = "7"
|
||||||
uzers = "0.12.2"
|
uzers = "0.12.2"
|
||||||
md-5 = "0.10.6"
|
md-5 = "0.10.6"
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,7 @@ type-to-search-select = Selects the first matching file or folder
|
||||||
|
|
||||||
# Context menu
|
# Context menu
|
||||||
add-to-sidebar = Add to sidebar
|
add-to-sidebar = Add to sidebar
|
||||||
|
clear-recents-history = Clear Recents history
|
||||||
compress = Compress
|
compress = Compress
|
||||||
copy-to = Copy to...
|
copy-to = Copy to...
|
||||||
delete-permanently = Delete permanently
|
delete-permanently = Delete permanently
|
||||||
|
|
|
||||||
27
src/app.rs
27
src/app.rs
|
|
@ -313,13 +313,14 @@ pub enum PreviewKind {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum NavMenuAction {
|
pub enum NavMenuAction {
|
||||||
|
ClearRecents,
|
||||||
|
EmptyTrash,
|
||||||
Open(segmented_button::Entity),
|
Open(segmented_button::Entity),
|
||||||
OpenWith(segmented_button::Entity),
|
OpenWith(segmented_button::Entity),
|
||||||
OpenInNewTab(segmented_button::Entity),
|
OpenInNewTab(segmented_button::Entity),
|
||||||
OpenInNewWindow(segmented_button::Entity),
|
OpenInNewWindow(segmented_button::Entity),
|
||||||
Preview(segmented_button::Entity),
|
Preview(segmented_button::Entity),
|
||||||
RemoveFromSidebar(segmented_button::Entity),
|
RemoveFromSidebar(segmented_button::Entity),
|
||||||
EmptyTrash,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MenuAction for NavMenuAction {
|
impl MenuAction for NavMenuAction {
|
||||||
|
|
@ -2420,6 +2421,15 @@ impl Application for App {
|
||||||
NavMenuAction::RemoveFromSidebar(entity),
|
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))
|
if matches!(location_opt, Some(Location::Trash))
|
||||||
&& !trash::os_limited::is_empty().unwrap_or(true)
|
&& !trash::os_limited::is_empty().unwrap_or(true)
|
||||||
{
|
{
|
||||||
|
|
@ -4697,6 +4707,16 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::NavMenuAction(action) => match action {
|
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) => {
|
NavMenuAction::Open(entity) => {
|
||||||
if let Some(path) = self
|
if let Some(path) = self
|
||||||
.nav_model
|
.nav_model
|
||||||
|
|
@ -4841,11 +4861,6 @@ impl Application for App {
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NavMenuAction::EmptyTrash => {
|
|
||||||
return self
|
|
||||||
.push_dialog(DialogPage::EmptyTrash, Some(EMPTY_TRASH_BUTTON_ID.clone()));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Message::Recents => {
|
Message::Recents => {
|
||||||
if self.config.show_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> {
|
pub fn scan_recents(sizes: IconSizes) -> Vec<Item> {
|
||||||
let recent_files = match recently_used_xbel::parse_file() {
|
let recent_files = match recently_used_xbel::parse_file() {
|
||||||
Ok(recent_files) => recent_files,
|
Ok(recent_files) => recent_files,
|
||||||
|
|
@ -5928,6 +5935,7 @@ impl Tab {
|
||||||
tab_column = tab_column.push(popover);
|
tab_column = tab_column.push(popover);
|
||||||
}
|
}
|
||||||
match &self.location {
|
match &self.location {
|
||||||
|
Location::Recents => {}
|
||||||
Location::Trash => {
|
Location::Trash => {
|
||||||
if let Some(items) = self.items_opt()
|
if let Some(items) = self.items_opt()
|
||||||
&& !items.is_empty()
|
&& !items.is_empty()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue