platform: PathPromptOptions.allowed_extensions; Linux portal glob filter

The system file pickers can restrict the choosable files to the
extensions the host wants (project import: .ove/.otio/.fcpxml;
export: the chosen format). Linux's ashpd OpenFileRequest applies a
FileFilter of glob patterns per extension; empty = no restriction.
This commit is contained in:
2026-09-02 12:00:23 +08:00
parent 209c593da6
commit a934be5bc6
3 changed files with 19 additions and 5 deletions
+2
View File
@@ -1128,6 +1128,7 @@ mod tests {
directories: true,
multiple: true,
prompt: None,
allowed_extensions: Vec::new(),
})
});
assert!(cx.did_prompt_for_paths());
@@ -1154,6 +1155,7 @@ mod tests {
directories: false,
multiple: false,
prompt: None,
allowed_extensions: Vec::new(),
})
});
+3
View File
@@ -1845,6 +1845,9 @@ pub struct PathPromptOptions {
pub multiple: bool,
/// The prompt to show to a user when selecting a path
pub prompt: Option<SharedString>,
/// Restrict the choosable items to these lowercase extensions
/// (without the dot; empty = no restriction). Empty also means "any".
pub allowed_extensions: Vec<String>,
}
/// What kind of prompt styling to show
+14 -5
View File
@@ -358,16 +358,25 @@ impl<P: LinuxClient + 'static> Platform for LinuxPlatform<P> {
"Open File"
};
let request = match ashpd::desktop::file_chooser::OpenFileRequest::default()
let mut request = ashpd::desktop::file_chooser::OpenFileRequest::default()
.identifier(identifier.await)
.modal(true)
.title(title)
.accept_label(options.prompt.as_ref().map(gpui::SharedString::as_str))
.multiple(options.multiple)
.directory(options.directories)
.send()
.await
{
.directory(options.directories);
// Extension filter (the caller's allowed_extensions, e.g.
// ["ove","otio","fcpxml"] for the project import/export):
// the portal filter globs the accepted patterns.
if !options.allowed_extensions.is_empty() {
let mut filter =
ashpd::desktop::file_chooser::FileFilter::new("Supported files");
for ext in &options.allowed_extensions {
filter = filter.glob(&format!("*.{ext}"));
}
request = request.filter(filter);
}
let request = match request.send().await {
Ok(request) => request,
Err(err) => {
let result = match err {