Skip to main content

EventContextFileDialogExt

Trait EventContextFileDialogExt 

Source
pub trait EventContextFileDialogExt {
    // Required methods
    fn pick_file(
        &mut self,
        request: FileDialogRequest,
        on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static,
    ) -> Result<RequestId, String>;
    fn pick_files(
        &mut self,
        request: FileDialogRequest,
        on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static,
    ) -> Result<RequestId, String>;
    fn pick_folder(
        &mut self,
        request: FileDialogRequest,
        on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static,
    ) -> Result<RequestId, String>;
    fn save_file(
        &mut self,
        request: FileDialogRequest,
        on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static,
    ) -> Result<RequestId, String>;
}
Expand description

Convenience methods on EventContext for opening native file dialogs. Brings the four shapes (open file, open files, pick folder, save file) into scope as ctx.pick_file(req, |result| ...) without forcing every caller to look up the handle and poster from app-state by hand.

Apps use teksilo_platform::file_dialog::EventContextFileDialogExt (or use teksilo::prelude::* once the umbrella re-exports it).

All four methods perform the same internal sequence:

  1. (macOS only) focus the current window so the panel comes to front for non-bundled binaries.
  2. Stamp the parent handle into the request.
  3. Look up FileDialogHandle and the teksilo_core::AppEventPoster via app-state.
  4. Forward to FileDialogHandle::submit.

Returns Err only when the request fails validation (FileDialogRequest::validate) or when the framework was not initialised with a FileDialogHandle (i.e. the application did not call TeksiloAppBuilder::install_file_dialog).

Convenience method overrides the request kind. The method you call dictates the operation: ctx.pick_file(req, …) always opens a single-file picker even if req was built with FileDialogRequest::save_file. Each method overwrites request.kind so the FileDialogResult variant returned to the callback always matches the method name. To control the kind explicitly, call FileDialogHandle::submit directly with a pre-built request.

Required Methods§

Source

fn pick_file( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Open a single-file dialog parented to the current window. on_result runs on the main thread on dialog completion or is dropped if the originating window closes first.

The request’s kind is forced to PickFile regardless of how it was constructed — see the trait-level docs.

Source

fn pick_files( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Open a multi-file selection dialog. The request’s kind is forced to PickFiles. See Self::pick_file.

Source

fn pick_folder( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Open a folder picker. The request’s kind is forced to PickFolder. See Self::pick_file.

Source

fn save_file( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Open a save dialog. The request’s kind is forced to SaveFile. See Self::pick_file.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl EventContextFileDialogExt for EventContext<'_>

Source§

fn pick_file( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Source§

fn pick_files( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Source§

fn pick_folder( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Source§

fn save_file( &mut self, request: FileDialogRequest, on_result: impl FnOnce(FileDialogResult, &mut EventContext<'_>) + 'static, ) -> Result<RequestId, String>

Implementors§