-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gtk: manually implement FileChooser::add_choice
- Loading branch information
1 parent
803192d
commit 82815d8
Showing
4 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Take a look at the license at the top of the repository in the LICENSE file. | ||
|
||
use crate::FileChooser; | ||
use glib::translate::*; | ||
use glib::IsA; | ||
|
||
pub trait FileChooserExtManual: 'static { | ||
#[doc(alias = "gtk_file_chooser_add_choice")] | ||
fn add_choice(&self, id: &str, label: &str, options: Option<&[(&str, &str)]>); | ||
} | ||
|
||
impl<O: IsA<FileChooser>> FileChooserExtManual for O { | ||
fn add_choice(&self, id: &str, label: &str, options: Option<&[(&str, &str)]>) { | ||
unsafe { | ||
let (options_ids, options_labels) = if let Some(options) = options { | ||
( | ||
options | ||
.iter() | ||
.map(|o| o.0.to_glib_none().0) | ||
.collect::<Vec<*const libc::c_char>>() | ||
.as_ptr(), | ||
options | ||
.iter() | ||
.map(|o| o.1.to_glib_none().0) | ||
.collect::<Vec<*const libc::c_char>>() | ||
.as_ptr(), | ||
) | ||
} else { | ||
(std::ptr::null(), std::ptr::null()) | ||
}; | ||
|
||
ffi::gtk_file_chooser_add_choice( | ||
self.as_ref().to_glib_none().0, | ||
id.to_glib_none().0, | ||
label.to_glib_none().0, | ||
mut_override(options_ids), | ||
mut_override(options_labels), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters