diff --git a/i18n/en/cosmic_files.ftl b/i18n/en/cosmic_files.ftl index 129e6f9..2a1938a 100644 --- a/i18n/en/cosmic_files.ftl +++ b/i18n/en/cosmic_files.ftl @@ -342,6 +342,7 @@ extract-here = Extract new-file = New file... new-folder = New folder... open-in-terminal = Open in terminal +edit-desktop-entry = Edit desktop entry move-to = Move to... move-to-trash = Move to trash restore-from-trash = Restore from trash diff --git a/i18n/fr/cosmic_files.ftl b/i18n/fr/cosmic_files.ftl index e85a1f6..0d40341 100644 --- a/i18n/fr/cosmic_files.ftl +++ b/i18n/fr/cosmic_files.ftl @@ -349,6 +349,7 @@ extract-here = Extraire new-file = Nouveau fichier... new-folder = Nouveau dossier... open-in-terminal = Ouvrir dans le terminal +edit-desktop-entry = Modifier le fichier .desktop move-to-trash = Déplacer vers la corbeille restore-from-trash = Restaurer depuis la corbeille remove-from-sidebar = Supprimer de la barre latérale diff --git a/src/app.rs b/src/app.rs index ebd32d9..b197005 100644 --- a/src/app.rs +++ b/src/app.rs @@ -247,6 +247,7 @@ pub enum Action { CosmicSettingsWallpaper, DesktopViewOptions, Delete, + EditDesktopEntry, EditHistory, EditLocation, Eject, @@ -320,6 +321,7 @@ impl Action { Self::CosmicSettingsWallpaper => Message::CosmicSettings("wallpaper"), Self::Delete => Message::Delete(entity_opt), Self::DesktopViewOptions => Message::DesktopViewOptions, + Self::EditDesktopEntry => Message::EditDesktopEntry(entity_opt), Self::EditHistory => Message::ToggleContextPage(ContextPage::EditHistory), Self::EditLocation => Message::TabMessage(entity_opt, tab::Message::EditLocationEnable), Self::Eject => Message::Eject, @@ -455,6 +457,7 @@ pub enum Message { DesktopDialogs(bool), DialogCancel, DialogComplete, + EditDesktopEntry(Option), Eject, FileDialogMessage(DialogMessage), DialogPush(DialogPage, Option), @@ -1060,6 +1063,21 @@ impl App { } } + /// Open paths with the default text editor, ignoring their own MIME type. + /// + /// Desktop entries launch the application they describe when opened, so + /// `open_file` never shows the file itself. This gives the file manager a + /// way to edit one without falling back to a terminal. + fn edit_file(&self, paths: &[PathBuf]) -> Task { + let Ok(text_plain) = "text/plain".parse::() else { + return Task::none(); + }; + if !self.launch_from_mime_cache(&text_plain, paths) { + log::warn!("no application registered for text/plain, cannot edit {paths:?}"); + } + Task::none() + } + fn launch_from_mime_cache

(&self, mime: &Mime, paths: &[P]) -> bool where P: std::fmt::Debug + AsRef + AsRef, @@ -4114,6 +4132,21 @@ impl Application for App { } None => {} }, + Message::EditDesktopEntry(entity_opt) => { + let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); + if let Some(tab) = self.tab_model.data::(entity) + && let Some(items) = tab.items_opt() + { + let paths: Vec = items + .iter() + .filter(|item| item.selected) + .filter_map(|item| item.path_opt().cloned()) + .collect(); + if !paths.is_empty() { + return self.edit_file(&paths); + } + } + } Message::OpenWithDialog(entity_opt) => { let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); if let Some(tab) = self.tab_model.data::(entity) diff --git a/src/menu.rs b/src/menu.rs index 8439655..dd31819 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -214,6 +214,8 @@ pub fn context_menu<'a>( |(i, action)| menu_item(action.name, Action::ExecEntryAction(i)).into(), )); } + children + .push(menu_item(fl!("edit-desktop-entry"), Action::EditDesktopEntry).into()); children.push(divider::horizontal::light().into()); children.push(menu_item(fl!("rename"), Action::Rename).into()); children.push(menu_item(fl!("cut"), Action::Cut).into());