gtk: remove the hackish FileChooserDialog::new implementation
instead of having a fixed number of buttons, just call add_buttons once we create
the dialog
// Take a look at the license at the top of the repository in the LICENSE file.
+use crate::prelude::DialogExtManual;
use crate::{FileChooserAction, FileChooserDialog, ResponseType, Widget, Window};
use glib::object::{Cast, IsA};
use glib::translate::*;
@@ -16,53 +17,16 @@ impl FileChooserDialog {
) -> FileChooserDialog {
assert_initialized_main_thread!();
unsafe {
- Widget::from_glib_none(match buttons.len() {
- 0 => ffi::gtk_file_chooser_dialog_new(
+ let dialog: FileChooserDialog =
+ Widget::from_glib_none(ffi::gtk_file_chooser_dialog_new(
title.to_glib_none().0,
parent.map(|p| p.as_ref()).to_glib_none().0,
action.to_glib(),
ptr::null::<c_char>(),
- ),
- 1 => ffi::gtk_file_chooser_dialog_new(
- title.to_glib_none().0,
- parent.map(|p| p.as_ref()).to_glib_none().0,
- action.to_glib(),
- buttons[0].0.to_glib_none().0,
- buttons[0].1.to_glib(),
- ptr::null::<c_char>(),
- ),
- 2 => ffi::gtk_file_chooser_dialog_new(
- title.to_glib_none().0,
- parent.map(|p| p.as_ref()).to_glib_none().0,
- action.to_glib(),
- buttons[0].0.to_glib_none().0,
- buttons[0].1.to_glib(),
- (buttons[1].0.to_glib_none() as Stash<*const c_char, str>).0,
- buttons[1].1.to_glib(),
- ptr::null::<c_char>(),
- ),
- 3 => ffi::gtk_file_chooser_dialog_new(
- title.to_glib_none().0,
- parent.map(|p| p.as_ref()).to_glib_none().0,
- action.to_glib(),
- buttons[0].0.to_glib_none().0,
- buttons[0].1.to_glib(),
- (buttons[1].0.to_glib_none() as Stash<*const c_char, str>).0,
- buttons[1].1.to_glib(),
- (buttons[2].0.to_glib_none() as Stash<*const c_char, str>).0,
- buttons[2].1.to_glib(),
- ptr::null::<c_char>(),
- ),
- _ => {
- // TODO: Support arbitrary number of buttons once variadic functions are supported.
- // See: https://github.com/rust-lang/rust/issues/44930
- panic!(format!(
- "`FileChooserDialog::new` does not support 4+ buttons, received {}",
- buttons.len()
))
- }
- })
- .unsafe_cast()
+ .unsafe_cast();
+ dialog.add_buttons(buttons);
+ dialog
}
}
}
