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:
parent
d3d3cec136
commit
5be3a951c7
3 changed files with 86 additions and 2 deletions
31
src/app.rs
31
src/app.rs
|
|
@ -97,6 +97,7 @@ pub enum Action {
|
|||
EditHistory,
|
||||
EditLocation,
|
||||
EmptyTrash,
|
||||
ExecEntryAction(usize),
|
||||
ExtractHere,
|
||||
Gallery,
|
||||
HistoryNext,
|
||||
|
|
@ -158,6 +159,9 @@ impl Action {
|
|||
}
|
||||
Action::EmptyTrash => Message::TabMessage(None, tab::Message::EmptyTrash),
|
||||
Action::ExtractHere => Message::ExtractHere(entity_opt),
|
||||
Action::ExecEntryAction(action) => {
|
||||
Message::TabMessage(entity_opt, tab::Message::ExecEntryAction(None, *action))
|
||||
}
|
||||
Action::Gallery => Message::TabMessage(entity_opt, tab::Message::GalleryToggle),
|
||||
Action::HistoryNext => Message::TabMessage(entity_opt, tab::Message::GoNext),
|
||||
Action::HistoryPrevious => Message::TabMessage(entity_opt, tab::Message::GoPrevious),
|
||||
|
|
@ -614,6 +618,30 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
fn exec_entry_action(entry: cosmic::desktop::DesktopEntryData, action: usize) {
|
||||
if let Some(action) = entry.desktop_actions.get(action) {
|
||||
// Largely copied from COSMIC app library
|
||||
let mut exec = shlex::Shlex::new(&action.exec);
|
||||
match exec.next() {
|
||||
Some(cmd) if !cmd.contains('=') => {
|
||||
let mut proc = tokio::process::Command::new(cmd);
|
||||
for arg in exec {
|
||||
if !arg.starts_with('%') {
|
||||
proc.arg(arg);
|
||||
}
|
||||
}
|
||||
let _ = proc.spawn();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
log::warn!(
|
||||
"Invalid actions index `{action}` for desktop entry {}",
|
||||
entry.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn open_tab_entity(
|
||||
&mut self,
|
||||
location: Location,
|
||||
|
|
@ -2639,6 +2667,9 @@ impl Application for App {
|
|||
tab::Command::EmptyTrash => {
|
||||
self.dialog_pages.push_back(DialogPage::EmptyTrash);
|
||||
}
|
||||
tab::Command::ExecEntryAction(entry, action) => {
|
||||
App::exec_entry_action(entry, action);
|
||||
}
|
||||
tab::Command::Iced(iced_command) => {
|
||||
commands.push(iced_command.0.map(move |tab_message| {
|
||||
message::app(Message::TabMessage(Some(entity), tab_message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue