Skip to main content

blocking_dialog/linux/
pick_files.rs

1// SPDX-FileCopyrightText: 2026 Manuel Quarneti <mq1@ik.me>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use crate::{BlockingDialogError, BlockingPickFilesDialog};
5use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
6use rfd::FileDialog;
7use std::path::PathBuf;
8
9impl<'a, W: HasWindowHandle + HasDisplayHandle> BlockingPickFilesDialog<'a, W> {
10    pub fn show(&self) -> Result<Vec<PathBuf>, BlockingDialogError> {
11        let mut dialog = FileDialog::new()
12            .set_title(self.title)
13            .set_parent(&self.window);
14
15        for entry in self.filter {
16            dialog = dialog.add_filter(entry.name, entry.extensions);
17        }
18
19        if self.multiple {
20            match dialog.pick_files() {
21                Some(files) => Ok(files),
22                None => Ok(Vec::new()),
23            }
24        } else {
25            match dialog.pick_file() {
26                Some(file) => Ok(vec![file]),
27                None => Ok(Vec::new()),
28            }
29        }
30    }
31}