File > Scripts > Browse: filter the picker to script files (#2452) (#2499)

This commit is contained in:
MarekSpodBiedry authored and GitHub committed 2026-10-10 15:20:22 -04:00
1 parent 0b4fe4b17f
commit ab76c242a1
2 files changed
+16 -1

No files matched your search

+12
View File
@@ -187,6 +187,18 @@ fn filtered_picker_requests_only_the_given_extensions() {
));
}
#[test]
fn scripts_browse_lists_only_script_files() {
let (mut app, open, _) = app();
menus::invoke(&mut app, &egui::Context::default(), "file.scripts.browse", json!({})).unwrap();
app.poll_file_dialog(&egui::Context::default(), None);
assert!(matches!(
open.borrow().first().map(|(r, _)| r),
Some(FileDialogRequest::Open { multiple: false, extensions: Some(exts), .. })
if exts.iter().map(String::as_str).collect::<Vec<_>>() == ["psjs", "ccjs", "jsx", "js", "jsxbin", "json", "txt"]
));
}
#[test]
fn last_used_dir_takes_the_most_recent_parent() {
assert_eq!(last_used_dir(&[]), None);
+4 -1
View File
@@ -39,6 +39,9 @@ fn form(app: &mut PhotocraftApp, command: &str, label: &str, fields: Value, choi
json!({"dialog": app.ui.open_dialog(DialogKind::Command, f)})
}
/// File › Scripts › Browse… lists these script files (plus the JSON/text the engine parses).
const SCRIPT_EXTENSIONS: &[&str] = &["psjs", "ccjs", "jsx", "js", "jsxbin", "json", "txt"];
/// Menu items fronted here (dialogs before the engine command). `None` when not ours.
pub fn invoke(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Value) -> Option<Result<Value, String>> {
if !no_params(params) {
@@ -86,7 +89,7 @@ pub fn invoke(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &V
form(app, id, "Image Statistics", json!({"mode": "median", "input": dir, "align": false}), json!({"mode": modes}))
}
"file.scripts.browse" => {
return Some(app.pick_file_bytes(|app, name, bytes| {
return Some(app.pick_file_bytes_filtered(SCRIPT_EXTENSIONS, |app, name, bytes| {
let r = app.run("file.scripts.browse", json!({"script": String::from_utf8_lossy(&bytes)}));
if r.is_ok() {
app.ui.status = format!("Ran script {name}");