Improved desktop entry menu

Currently, desktop entries display a generic menu with items that aren't
relevant to apps. This patch improves the menu by removing the unneeded
items and listing desktop specific entries such as actions. For example,
right clicking a Firefox desktop entry will show the action to open a
private tab.

Should compose well with pop-os/cosmic-applibrary#179
This commit is contained in:
Josh Megnauth 2024-10-29 03:18:05 -04:00 committed by Jeremy Soller
parent d3d3cec136
commit 5be3a951c7
3 changed files with 86 additions and 2 deletions

View file

@ -38,6 +38,7 @@ use cosmic::{
};
use chrono::{DateTime, Utc};
use i18n_embed::LanguageLoader;
use mime_guess::{mime, Mime};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
@ -1005,6 +1006,7 @@ pub enum Command {
ChangeLocation(String, Location, Option<PathBuf>),
DropFiles(PathBuf, ClipboardPaste),
EmptyTrash,
ExecEntryAction(cosmic::desktop::DesktopEntryData, usize),
Iced(TaskWrapper),
MoveToTrash(Vec<PathBuf>),
OpenFile(PathBuf),
@ -1034,6 +1036,7 @@ pub enum Message {
EditLocationEnable,
OpenInNewTab(PathBuf),
EmptyTrash,
ExecEntryAction(Option<PathBuf>, usize),
Gallery(bool),
GalleryPrevious,
GalleryNext,
@ -2319,6 +2322,24 @@ impl Tab {
Message::EmptyTrash => {
commands.push(Command::EmptyTrash);
}
Message::ExecEntryAction(path, action) => {
let lang_id = crate::localize::LANGUAGE_LOADER.current_language();
let language = lang_id.language.as_str();
match path.map_or_else(
|| {
let items = self.items_opt.as_deref()?;
items.iter().find(|item| item.selected).and_then(|item| {
let location = item.location_opt.as_ref()?;
let path = location.path_opt()?;
cosmic::desktop::load_desktop_file(Some(language), path)
})
},
|path| cosmic::desktop::load_desktop_file(Some(language), path),
) {
Some(entry) => commands.push(Command::ExecEntryAction(entry, action)),
None => log::warn!("Invalid desktop entry path passed to ExecEntryAction"),
}
}
Message::Gallery(gallery) => {
self.gallery = gallery;
}