diff --git a/src/actions/tempfiles.rs b/src/actions/tempfiles.rs index 928678c3..1d3ee581 100644 --- a/src/actions/tempfiles.rs +++ b/src/actions/tempfiles.rs @@ -18,6 +18,11 @@ pub fn open_dir() -> anyhow::Result<()> { Ok(()) } +pub fn open_file(path: &str) -> anyhow::Result<()> { + open::that(Path::new(path))?; + Ok(()) +} + pub fn clear() -> anyhow::Result<()> { crate::plugins::tempfile::clear_files()?; Ok(()) diff --git a/src/dashboard/widgets/tempfiles.rs b/src/dashboard/widgets/tempfiles.rs index 5ffcc3bf..7692b783 100644 --- a/src/dashboard/widgets/tempfiles.rs +++ b/src/dashboard/widgets/tempfiles.rs @@ -199,6 +199,15 @@ impl TempfilesWidget { args: None, } } + + fn open_action(path: &Path, name: &str) -> Action { + Action { + label: format!("Open {name}"), + desc: "Tempfile".into(), + action: format!("tempfile:open:{}", path.to_string_lossy()), + args: None, + } + } } impl Default for TempfilesWidget { @@ -267,6 +276,17 @@ impl Widget for TempfilesWidget { .small()); } } + if ui + .small_button("Open") + .on_hover_text("Open file (not folder)") + .clicked() + { + let action = Self::open_action(&entry.path, display_name); + clicked = Some(WidgetAction { + query_override: Some(action.label.clone()), + action, + }); + } if ui.small_button("Clear").clicked() { let action = Self::remove_action(&entry.path, display_name); clicked = Some(WidgetAction { diff --git a/src/launcher.rs b/src/launcher.rs index 25ac8c7e..c1925d0d 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -386,6 +386,7 @@ enum ActionKind<'a> { BrowserTabClear, TempfileNew(Option<&'a str>), TempfileOpen, + TempfileOpenFile(&'a str), TempfileClear, TempfileRemove(&'a str), TempfileAlias { @@ -713,6 +714,9 @@ fn parse_action_kind(action: &Action) -> ActionKind<'_> { if s == "tempfile:new" { return ActionKind::TempfileNew(None); } + if let Some(path) = s.strip_prefix("tempfile:open:") { + return ActionKind::TempfileOpenFile(path); + } if s == "tempfile:open" { return ActionKind::TempfileOpen; } @@ -910,6 +914,7 @@ pub fn launch_action(action: &Action) -> anyhow::Result<()> { } ActionKind::TempfileNew(alias) => tempfiles::new(alias), ActionKind::TempfileOpen => tempfiles::open_dir(), + ActionKind::TempfileOpenFile(path) => tempfiles::open_file(path), ActionKind::TempfileClear => tempfiles::clear(), ActionKind::TempfileRemove(path) => tempfiles::remove(path), ActionKind::TempfileAlias { path, alias } => tempfiles::set_alias(path, alias),