diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-12-10 18:46:44 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-12-10 19:56:32 +0100 |
commit | 89afcb4844dd484f0c9cdfef7e5ff8d751647c43 (patch) | |
tree | f23e994a66ec562685ca44caa6ba939de34acdf1 /src/lib.rs | |
parent | 7d1a146003117694e9d970b0cf08c514ffad1c6e (diff) | |
download | dialog-rs-89afcb4844dd484f0c9cdfef7e5ff8d751647c43.tar.gz dialog-rs-89afcb4844dd484f0c9cdfef7e5ff8d751647c43.tar.bz2 |
Add Open/Save mode to the file selection dialogfile-selection
This patch adds the option to set a FileSelectionMode, either Open or
Save. Not all backends might support this – currently, only zenity and
kdialog do. Per default, the Open mode is used (as before).
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -348,11 +348,24 @@ impl DialogBox for Question { } } +/// The type of a file selection dialog. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum FileSelectionMode { + /// An Open File dialog, meaning that the user can only select an existing file. + Open, + /// A Save File dialog, meaning that the user is allowed to select a non-existing file. + Save, +} + /// A file chooser dialog box. /// -/// This dialog box opens a file chooser with an optional title in the specified path. If the path +/// This dialog box opens a file choser with an optional title in the specified path. If the path /// is not specified, it defaults to the user’s home directory. /// +/// The backends might support multiple operation modes, for example open or save dialogs. You can +/// select a mode using the [`FileSelectionMode`][] enum, though the backend might ignore the mode +/// and just display a simple file dialog. Per default, the mode is set to `Open`. +/// /// # Example /// /// ```no_run @@ -365,10 +378,13 @@ impl DialogBox for Question { /// .expect("Could not display dialog box"); /// println!("The user chose: {:?}", choice); /// ``` +/// +/// [`FileSelectionMode`]: enum.FileSelectionMode.html pub struct FileSelection { text: String, title: Option<String>, path: Option<PathBuf>, + mode: FileSelectionMode, } impl FileSelection { @@ -378,6 +394,7 @@ impl FileSelection { text: text.into(), title: None, path: dirs::home_dir(), + mode: FileSelectionMode::Open, } } @@ -409,6 +426,14 @@ impl FileSelection { _ => None, } } + + /// Sets the operation mode of the file chooser. + /// + /// This method returns a reference to `self` to enable chaining. + pub fn mode(&mut self, mode: FileSelectionMode) -> &mut FileSelection { + self.mode = mode; + self + } } impl DialogBox for FileSelection { |