Skip to main content

lingxia_platform/traits/
file.rs

1use std::future::Future;
2
3use crate::error::PlatformError;
4
5#[derive(Debug, Clone)]
6pub struct OpenDocumentRequest {
7    pub file_path: String,
8    pub mime_type: Option<String>,
9    pub show_menu: Option<bool>,
10}
11
12#[derive(Debug, Clone)]
13pub struct FileDialogFilter {
14    pub name: Option<String>,
15    pub extensions: Vec<String>,
16}
17
18#[derive(Debug, Clone)]
19pub struct ChooseFileRequest {
20    pub multiple: bool,
21    pub filters: Vec<FileDialogFilter>,
22    pub title: Option<String>,
23    pub default_path: Option<String>,
24}
25
26#[derive(Debug, Clone)]
27pub struct ChooseDirectoryRequest {
28    pub title: Option<String>,
29    pub default_path: Option<String>,
30}
31
32#[derive(Debug, Clone)]
33pub struct FileDialogResult {
34    pub canceled: bool,
35    pub paths: Vec<String>,
36}
37
38pub trait FileInteraction: Send + Sync + 'static {
39    fn open_document(
40        &self,
41        request: OpenDocumentRequest,
42    ) -> impl Future<Output = Result<(), PlatformError>> + Send;
43
44    fn choose_file(
45        &self,
46        _request: ChooseFileRequest,
47    ) -> impl Future<Output = Result<FileDialogResult, PlatformError>> + Send {
48        async {
49            Err(PlatformError::NotSupported(
50                "choose_file is not supported on this platform".into(),
51            ))
52        }
53    }
54
55    fn choose_directory(
56        &self,
57        _request: ChooseDirectoryRequest,
58    ) -> impl Future<Output = Result<FileDialogResult, PlatformError>> + Send {
59        async {
60            Err(PlatformError::NotSupported(
61                "choose_directory is not supported on this platform".into(),
62            ))
63        }
64    }
65}