From 9273f3f45f7418e87b6e53baef78612ef0d6c5e7 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Thu, 24 Oct 2019 20:44:39 -0400 Subject: Fix clippy complaints that don't change the semantics (Clippy also complains about `new()` without `impl Default`) --- src/backends/zenity.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/backends/zenity.rs') diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index 85206b3..12e052b 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -101,15 +101,13 @@ impl AsRef 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 +128,16 @@ fn get_stdout(output: process::Output) -> Result> { 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))) } } -- cgit v1.2.1 From dfe809ae6c191cbc8478363bc5b0ed2626f91bb0 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 26 Oct 2019 13:07:41 +0200 Subject: Add missing backtick in doc comment --- src/backends/zenity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/backends/zenity.rs') diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index 12e052b..d5745eb 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -29,7 +29,7 @@ impl Zenity { /// 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) { self.icon = Some(icon.into()); -- cgit v1.2.1 From 0970381271bd07f020a888b027653ca627e8655c Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 27 Oct 2019 10:55:30 +0000 Subject: Implement Default for all backend structs This fixes the clippy warning new_without_default [0]. [0] https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default --- src/backends/zenity.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/backends/zenity.rs') diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index d5745eb..0deca0a 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -8,7 +8,7 @@ use crate::{Choice, Error, 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, width: Option, @@ -19,12 +19,7 @@ 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. -- cgit v1.2.1 From 2f3e2b5474834e3d733edf09b831c5607d451f49 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Tue, 10 Dec 2019 15:24:36 +0000 Subject: Add FileSelection dialog type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds the FileSelection struct representing a file selection dialog. It can be displayed using the backend’s show_file_selection function. Currently, we only support file open dialogs (i. e. choosing an existing file). Support for save dialogs should be added in the future. --- src/backends/zenity.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/backends/zenity.rs') diff --git a/src/backends/zenity.rs b/src/backends/zenity.rs index 0deca0a..4ee7785 100644 --- a/src/backends/zenity.rs +++ b/src/backends/zenity.rs @@ -3,7 +3,7 @@ use std::process; -use crate::{Choice, Error, Input, Message, Password, Question, Result}; +use crate::{Choice, Error, FileSelection, Input, Message, Password, Question, Result}; /// The `zenity` backend. /// @@ -163,4 +163,11 @@ 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> { + let dir = file_selection.path_to_string().ok_or("path not valid")?; + let args = vec!["--file-selection", "--filename", &dir]; + self.execute(args, &file_selection.title) + .and_then(get_stdout) + } } -- cgit v1.2.1 From 89afcb4844dd484f0c9cdfef7e5ff8d751647c43 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 10 Dec 2019 18:46:44 +0000 Subject: Add Open/Save mode to the file selection dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- src/backends/zenity.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/backends/zenity.rs') 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> { 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) } -- cgit v1.2.1