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/backends | |
parent | 7d1a146003117694e9d970b0cf08c514ffad1c6e (diff) | |
download | dialog-rs-file-selection.tar.gz dialog-rs-file-selection.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/backends')
-rw-r--r-- | src/backends/kdialog.rs | 10 | ||||
-rw-r--r-- | src/backends/zenity.rs | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/backends/kdialog.rs b/src/backends/kdialog.rs index e556ddf..21928f8 100644 --- a/src/backends/kdialog.rs +++ b/src/backends/kdialog.rs @@ -4,7 +4,9 @@ use std::process; -use crate::{Choice, Error, FileSelection, Input, Message, Password, Question, Result}; +use crate::{ + Choice, Error, FileSelection, FileSelectionMode, Input, Message, Password, Question, Result, +}; /// Subprocess exit codes /// @@ -139,7 +141,11 @@ impl super::Backend for KDialog { fn show_file_selection(&self, file_selection: &FileSelection) -> Result<Option<String>> { let dir = file_selection.path_to_string().ok_or("path not valid")?; - let args = vec!["--getopenfilename", &dir]; + let option = match file_selection.mode { + FileSelectionMode::Open => "--getopenfilename", + FileSelectionMode::Save => "--getsavefilename", + }; + let args = vec![option, &dir]; self.execute(args, &file_selection.title) .and_then(get_stdout) } diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index 4ee7785..ac0f98f 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -3,7 +3,9 @@ use std::process; -use crate::{Choice, Error, FileSelection, Input, Message, Password, Question, Result}; +use crate::{ + Choice, Error, FileSelection, FileSelectionMode, Input, Message, Password, Question, Result, +}; /// The `zenity` backend. /// @@ -166,7 +168,10 @@ impl super::Backend for Zenity { fn show_file_selection(&self, file_selection: &FileSelection) -> Result<Option<String>> { let dir = file_selection.path_to_string().ok_or("path not valid")?; - let args = vec!["--file-selection", "--filename", &dir]; + let mut args = vec!["--file-selection", "--filename", &dir]; + if file_selection.mode == FileSelectionMode::Save { + args.push("--save"); + } self.execute(args, &file_selection.title) .and_then(get_stdout) } |