Skip to content

Commit a9ce753

Browse files
gtk: Manually implement FileChooser::set_current_folder
To drop the assertion as the folder might not be set correctly in some cases without an error being returned Which causes the panic described in #1049. Note, that upstream code has to be changed as well in order to fix passing a NULL folder which is the cause of the critical mentioned in the issue above. Fixes #1049
1 parent 7272eff commit a9ce753

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

gtk4/Gir.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ manual_traits = ["FileChooserExtManual"]
11611161
[[object.function]]
11621162
name = "add_choice"
11631163
manual = true # rust-ify the options param
1164+
[[object.function]]
1165+
name = "set_current_folder"
1166+
manual = true # Drops the error assertion as it is not always correct
11641167

11651168
[[object]]
11661169
name = "Gtk.FileChooserDialog"

gtk4/src/auto/file_chooser.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ pub trait FileChooserExt: 'static {
9696
#[doc(alias = "gtk_file_chooser_set_create_folders")]
9797
fn set_create_folders(&self, create_folders: bool);
9898

99-
#[doc(alias = "gtk_file_chooser_set_current_folder")]
100-
fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<(), glib::Error>;
101-
10299
#[doc(alias = "gtk_file_chooser_set_current_name")]
103100
fn set_current_name(&self, name: &str);
104101

@@ -306,23 +303,6 @@ impl<O: IsA<FileChooser>> FileChooserExt for O {
306303
}
307304
}
308305

309-
fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<(), glib::Error> {
310-
unsafe {
311-
let mut error = ptr::null_mut();
312-
let is_ok = ffi::gtk_file_chooser_set_current_folder(
313-
self.as_ref().to_glib_none().0,
314-
file.map(|p| p.as_ref()).to_glib_none().0,
315-
&mut error,
316-
);
317-
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
318-
if error.is_null() {
319-
Ok(())
320-
} else {
321-
Err(from_glib_full(error))
322-
}
323-
}
324-
}
325-
326306
fn set_current_name(&self, name: &str) {
327307
unsafe {
328308
ffi::gtk_file_chooser_set_current_name(

gtk4/src/file_chooser.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use glib::IsA;
99
pub trait FileChooserExtManual: 'static {
1010
#[doc(alias = "gtk_file_chooser_add_choice")]
1111
fn add_choice(&self, id: &str, label: &str, options: &[(&str, &str)]);
12+
13+
#[doc(alias = "gtk_file_chooser_set_current_folder")]
14+
fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<bool, glib::Error>;
1215
}
1316

1417
impl<O: IsA<FileChooser>> FileChooserExtManual for O {
@@ -44,4 +47,20 @@ impl<O: IsA<FileChooser>> FileChooserExtManual for O {
4447
);
4548
}
4649
}
50+
51+
fn set_current_folder(&self, file: Option<&impl IsA<gio::File>>) -> Result<bool, glib::Error> {
52+
unsafe {
53+
let mut error = std::ptr::null_mut();
54+
let result = from_glib(ffi::gtk_file_chooser_set_current_folder(
55+
self.as_ref().to_glib_none().0,
56+
file.map(|p| p.as_ref()).to_glib_none().0,
57+
&mut error,
58+
));
59+
if error.is_null() {
60+
Ok(result)
61+
} else {
62+
Err(from_glib_full(error))
63+
}
64+
}
65+
}
4766
}

0 commit comments

Comments
 (0)