diff options
| author | Robin Krahl <robin.krahl@ireas.org> | 2019-12-10 20:09:59 +0100 | 
|---|---|---|
| committer | Robin Krahl <robin.krahl@ireas.org> | 2019-12-10 20:09:59 +0100 | 
| commit | aa8148b958daac4b35173a1d28806b2fdc8609bd (patch) | |
| tree | d3c438f91a911f8e4bd0fb96dc833edaac4f21e6 /src/backends/zenity.rs | |
| parent | 10462c2c9f4ae2ffd3c32dd4628e0052067c15fa (diff) | |
| parent | 202c49a327b7a3dc3bfa199da2ac7484ee105f65 (diff) | |
| download | dialog-rs-aa8148b958daac4b35173a1d28806b2fdc8609bd.tar.gz dialog-rs-aa8148b958daac4b35173a1d28806b2fdc8609bd.tar.bz2 | |
Diffstat (limited to 'src/backends/zenity.rs')
| -rw-r--r-- | src/backends/zenity.rs | 59 | 
1 files changed, 31 insertions, 28 deletions
| diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index 85206b3..ac0f98f 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -3,12 +3,14 @@  use std::process; -use crate::{Choice, Error, Input, Message, Password, Question, Result}; +use crate::{ +    Choice, Error, FileSelection, FileSelectionMode, Input, Message, Password, Question, Result, +};  /// The `zenity` backend.  ///  /// This backend uses the external `zenity` program to display GTK+ dialog boxes. -#[derive(Debug)] +#[derive(Debug, Default)]  pub struct Zenity {      icon: Option<String>,      width: Option<String>, @@ -19,17 +21,12 @@ pub struct Zenity {  impl Zenity {      /// Creates a new `Zenity` instance without configuration.      pub fn new() -> Zenity { -        Zenity { -            icon: None, -            width: None, -            height: None, -            timeout: None, -        } +        Default::default()      }      /// Sets the icon of the dialog box.      /// -    /// The icon can either be one of `error`, `info`, `question` or `warning, or the path to an +    /// The icon can either be one of `error`, `info`, `question` or `warning`, or the path to an      /// image to use.  The default image depends on the dialog type.      pub fn set_icon(&mut self, icon: impl Into<String>) {          self.icon = Some(icon.into()); @@ -101,15 +98,13 @@ impl AsRef<Zenity> for Zenity {  fn require_success(status: process::ExitStatus) -> Result<()> {      if status.success() {          Ok(()) -    } else { -        if let Some(code) = status.code() { -            match code { -                5 => Ok(()), -                _ => Err(Error::from(("zenity", status))), -            } -        } else { -            Err(Error::from(("zenity", status))) +    } else if let Some(code) = status.code() { +        match code { +            5 => Ok(()), +            _ => Err(Error::from(("zenity", status))),          } +    } else { +        Err(Error::from(("zenity", status)))      }  } @@ -130,18 +125,16 @@ fn get_stdout(output: process::Output) -> Result<Option<String>> {      if output.status.success() {          String::from_utf8(output.stdout)              .map(|s| Some(s.trim_end_matches('\n').to_string())) -            .map_err(|err| Error::from(err)) -    } else { -        if let Some(code) = output.status.code() { -            match code { -                0 => Ok(None), -                1 => Ok(None), -                5 => Ok(None), -                _ => Err(Error::from(("zenity", output.status))), -            } -        } else { -            Err(Error::from(("zenity", output.status))) +            .map_err(Error::from) +    } else if let Some(code) = output.status.code() { +        match code { +            0 => Ok(None), +            1 => Ok(None), +            5 => Ok(None), +            _ => Err(Error::from(("zenity", output.status))),          } +    } else { +        Err(Error::from(("zenity", output.status)))      }  } @@ -172,4 +165,14 @@ impl super::Backend for Zenity {          self.execute(args, &question.title)              .and_then(|output| get_choice(output.status))      } + +    fn show_file_selection(&self, file_selection: &FileSelection) -> Result<Option<String>> { +        let dir = file_selection.path_to_string().ok_or("path not valid")?; +        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) +    }  } | 
