Skip to content

Commit ee552ae

Browse files
authored
Merge pull request #664 from multiplex55/codex/add-open-button-for-temp-files
Add per-tempfile Open button and action to launch files
2 parents 6f705e9 + cd3d141 commit ee552ae

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/actions/tempfiles.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ pub fn open_dir() -> anyhow::Result<()> {
1818
Ok(())
1919
}
2020

21+
pub fn open_file(path: &str) -> anyhow::Result<()> {
22+
open::that(Path::new(path))?;
23+
Ok(())
24+
}
25+
2126
pub fn clear() -> anyhow::Result<()> {
2227
crate::plugins::tempfile::clear_files()?;
2328
Ok(())

src/dashboard/widgets/tempfiles.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ impl TempfilesWidget {
199199
args: None,
200200
}
201201
}
202+
203+
fn open_action(path: &Path, name: &str) -> Action {
204+
Action {
205+
label: format!("Open {name}"),
206+
desc: "Tempfile".into(),
207+
action: format!("tempfile:open:{}", path.to_string_lossy()),
208+
args: None,
209+
}
210+
}
202211
}
203212

204213
impl Default for TempfilesWidget {
@@ -267,6 +276,17 @@ impl Widget for TempfilesWidget {
267276
.small());
268277
}
269278
}
279+
if ui
280+
.small_button("Open")
281+
.on_hover_text("Open file (not folder)")
282+
.clicked()
283+
{
284+
let action = Self::open_action(&entry.path, display_name);
285+
clicked = Some(WidgetAction {
286+
query_override: Some(action.label.clone()),
287+
action,
288+
});
289+
}
270290
if ui.small_button("Clear").clicked() {
271291
let action = Self::remove_action(&entry.path, display_name);
272292
clicked = Some(WidgetAction {

src/launcher.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ enum ActionKind<'a> {
386386
BrowserTabClear,
387387
TempfileNew(Option<&'a str>),
388388
TempfileOpen,
389+
TempfileOpenFile(&'a str),
389390
TempfileClear,
390391
TempfileRemove(&'a str),
391392
TempfileAlias {
@@ -713,6 +714,9 @@ fn parse_action_kind(action: &Action) -> ActionKind<'_> {
713714
if s == "tempfile:new" {
714715
return ActionKind::TempfileNew(None);
715716
}
717+
if let Some(path) = s.strip_prefix("tempfile:open:") {
718+
return ActionKind::TempfileOpenFile(path);
719+
}
716720
if s == "tempfile:open" {
717721
return ActionKind::TempfileOpen;
718722
}
@@ -910,6 +914,7 @@ pub fn launch_action(action: &Action) -> anyhow::Result<()> {
910914
}
911915
ActionKind::TempfileNew(alias) => tempfiles::new(alias),
912916
ActionKind::TempfileOpen => tempfiles::open_dir(),
917+
ActionKind::TempfileOpenFile(path) => tempfiles::open_file(path),
913918
ActionKind::TempfileClear => tempfiles::clear(),
914919
ActionKind::TempfileRemove(path) => tempfiles::remove(path),
915920
ActionKind::TempfileAlias { path, alias } => tempfiles::set_alias(path, alias),

0 commit comments

Comments
 (0)