Struct FileDialog

Source
pub struct FileDialog { /* private fields */ }
Expand description

A file dialog control

The file dialog builders accepts the following parameters:

  • title: The title of the dialog
  • action: The action to execute. Open, OpenDirectory for Save
  • multiselect: Whether the user can select more than one file. Only supported with the Open action
  • default_folder: Default folder to show in the dialog.
  • filters: If defined, filter the files that the user can select (In a Open dialog) or which extension to add to the saved file (in a Save dialog) The filters value must be a ‘|’ separated string having this format: “Test(.txt;.rs)|Any(.)”
    use native_windows_gui as nwg;
    fn layout(dialog: &mut nwg::FileDialog) {
        nwg::FileDialog::builder()
            .title("Hello")
            .action(nwg::FileDialogAction::Open)
            .multiselect(true)
            .build(dialog);
    }

Implementations§

Source§

impl FileDialog

Source

pub fn builder() -> FileDialogBuilder

Source

pub fn action(&self) -> FileDialogAction

Return the action type executed by this dialog

Source

pub fn run<C: Into<ControlHandle>>(&self, parent: Option<C>) -> bool

Display the dialog. Return true if the dialog was accepted or false if it was cancelled If the dialog was accepted, get_selected_item or get_selected_items can be used to find the selected file(s)

It’s important to note that run blocks the current thread until the user as chosen a file (similar to dispatch_thread_events)

The parent argument must be a window control otherwise the method will panic.

Source

pub fn get_selected_item(&self) -> Result<OsString, NwgError>

Return the item selected in the dialog by the user.

Failures:
• if the dialog was not called
• if there was a system error while reading the selected item
• if the dialog has the multiselect flag

Source

pub fn get_selected_items(&self) -> Result<Vec<OsString>, NwgError>

Return the selected items in the dialog by the user. Failures:
• if the dialog was not called
• if there was a system error while reading the selected items
• if the dialog has Save for action

Source

pub fn multiselect(&self) -> bool

Return true if the dialog accepts multiple values or false otherwise

Source

pub fn set_multiselect(&self, multiselect: bool) -> Result<(), NwgError>

Set the multiselect flag of the dialog. Failures:
• if there was a system error while setting the new flag value
• if the dialog has Save for action

Source

pub fn set_default_folder<'a>(&self, folder: &'a str) -> Result<(), NwgError>

Set the first opened folder when the dialog is shown. This value is overriden by the user after the dialog ran.
Call clear_client_data to fix that. Failures: • if the default folder do not identify a folder
• if the folder do not exists

Source

pub fn set_filters<'a>(&self, filters: &'a str) -> Result<(), NwgError>

Filter the files that the user can select (In a Open dialog) in the dialog or which extension to add to the saved file (in a Save dialog).
This can only be set ONCE (the initialization counts) and won’t work if the dialog is OpenDirectory.

The filters value must be a ‘|’ separated string having this format: “Test(.txt;.rs)|Any(.)”
Where the fist part is the “human name” and the second part is a filter for the system.

Source

pub fn set_title<'a>(&self, title: &'a str)

Change the dialog title

Source

pub fn clear_client_data(&self)

Instructs the dialog to clear all persisted state information (such as the last folder visited).

Trait Implementations§

Source§

impl Debug for FileDialog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FileDialog

Source§

fn default() -> FileDialog

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FileDialog

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for FileDialog

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.