-
-
Notifications
You must be signed in to change notification settings - Fork 82
Conversation
src/file_chooser_dialog.rs
Outdated
0 => ffi::gtk_file_chooser_dialog_new(title.to_glib_none().0, parent.to_glib_none().0, action.to_glib(), ptr::null::<c_char>()), | ||
1 => ffi::gtk_file_chooser_dialog_new(title.to_glib_none().0, parent.to_glib_none().0, action.to_glib(), buttons[0].0.to_glib_none().0, buttons[0].1.to_glib(), ptr::null::<c_char>()), | ||
2 => { | ||
let second_button_text: *const c_char = buttons[1].0.to_glib_none().0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work.
You need save Stash
to variable and use .0
in function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit
src/file_chooser_dialog.rs
Outdated
let second_button_text: *const c_char = buttons[1].0.to_glib_none().0; | ||
ffi::gtk_file_chooser_dialog_new(title.to_glib_none().0, parent.to_glib_none().0, action.to_glib(), buttons[0].0.to_glib_none().0, buttons[0].1.to_glib(), second_button_text, buttons[1].1.to_glib(), ptr::null::<c_char>()) | ||
}, | ||
_ => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hard-coding of 4 different settings for the file chooser is also not ideal, and the usage of the enum prevents adding "custom" buttons to there. Not sure how to fix either of those though, the C API is kind of suboptimal in this regard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit: instead of silently truncating the buttons, it panics. This is a temporary solution until variadic functions are supported.
To remove "breaking change" you can just add this as "with_buttons" instead. |
Thank you for the helpful reviews. I am not very familiar with these bindings but I'll fix these issues.
|
The |
@sdroege |
Ok, so I'll panic for now. |
@demurgos Please add TODO comment with link to rust-lang/rust#44930 |
Following the reviews in gtk-rs#602, this commit: - uses the `with_buttons` function instead of modifying `new` to keep backward compatibility. - saves the button texts in `Stash` objects to avoid invalid pointers - panics when the number of buttons is too high (instead of silently truncating the number of buttons)
Please, remove this comment, I will add it to right place (https://github.com/gtk-rs/lgpl-docs) after PR merged
|
@EPashkin Done, I removed the doc comment. |
@demurgos I will change doc' example to this. It works for you?
|
Yes, this is fine. I was using |
cc @sdroege and @GuillaumeGomez for final decision. |
src/file_chooser_dialog.rs
Outdated
title.to_glib_none().0, | ||
parent.to_glib_none().0, | ||
action.to_glib(), | ||
first_button_text.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just buttons[0].0.to_glib_none().0
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the other branches.
To be honest, I also do not really understand how Stash works. I just know that when I used a single stash, I had some errors with pointers and adding more stashes fixed it.
Looks good to me except for the comment I just added. Feel free to ignore me on that though if there's a reason |
I wrote a va_list crate which works on every OS/arch. It's used by a VLC demuxer so I suppose it's fine enough. Maybe give it a look? |
@sdroege |
If it's not needed, it seems simpler/shorter to not define new variables for the Stash but just directly use the value |
This commit removes the `first_button_text` variable from `FileChooserDialog::with_buttons`, as requested in the PR gtk-rs#602
@sdroege It is still not clear for me why I can omit the stash for the first button but if I try to do it for the others it breaks. |
The CI error seems to be caused by the usage example. Travis tries to compile it even if it's not a complete program. |
How does it break for the other buttons? It should work in all cases |
I get the wrong text, instead of printing the text of the button 2, it reuses the window title as button labels. I'll try to reproduce it, it may have been an error on my side. |
b046957
to
b1f268a
Compare
This commit removes the Stash variables from `FileChooserDialog::with_buttons`, as requested in the PR gtk-rs#602
b1f268a
to
607e824
Compare
This commit removes the Stash variables from `FileChooserDialog::with_buttons`, as requested in the PR gtk-rs#602
I was not able to reproduce my issue (wrong text when not using the Stash) so I assume the error was on my side. I pushed the version without any local variables. |
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stash
IMHO don't needed here and in other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot that it var_arg
:( so rust can't infer type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, I can omit it for the first text but not for the other ones.
Seems good now? |
It's good for me. |
All good from my side |
src/file_chooser_dialog.rs
Outdated
panic!(format!("`FileChooserDialog::with_buttons` does not support 4+ buttons, received {}", buttons.len())) | ||
} | ||
}) | ||
.downcast_unchecked() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this call on the previous line, right after })
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit.
Well now please squash your commits. Otherwise seems good to me. |
This commit adds support for file chooser buttons. They are represented as a slice of tuples `(text, action)`. The original function uses varargs to support an arbitrary number of arguments. This implementation supports up to 3 buttons. **This is a breaking change.** See: https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html#gtk-file-chooser-dialog-new Improve file chooser with buttons reliability Following the reviews in gtk-rs#602, this commit: - uses the `with_buttons` function instead of modifying `new` to keep backward compatibility. - saves the button texts in `Stash` objects to avoid invalid pointers - panics when the number of buttons is too high (instead of silently truncating the number of buttons) Remove doc comment for `FileChooserDialog::with_buttons` Remove local variables in `FileChooserDialog::with_buttons` This commit removes the Stash variables from `FileChooserDialog::with_buttons`, as requested in the PR gtk-rs#602 Fix formatting issue Keep `downcast_unchecked` method on the same line as the closing parenthesis of the chopped-down call to `Widget::from_glib_none`.
d5eb9f6
to
06d9c44
Compare
@GuillaumeGomez |
Just waiting confirmation from @EPashkin. |
@demurgos Thanks. |
This commit adds support for file chooser buttons. They are represented as a slice of tuples `(text, action)`. The original function uses varargs to support an arbitrary number of arguments. This implementation supports up to 3 buttons. **This is a breaking change.** See: https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html#gtk-file-chooser-dialog-new Improve file chooser with buttons reliability Following the reviews in gtk-rs#602, this commit: - uses the `with_buttons` function instead of modifying `new` to keep backward compatibility. - saves the button texts in `Stash` objects to avoid invalid pointers - panics when the number of buttons is too high (instead of silently truncating the number of buttons) Remove doc comment for `FileChooserDialog::with_buttons` Remove local variables in `FileChooserDialog::with_buttons` This commit removes the Stash variables from `FileChooserDialog::with_buttons`, as requested in the PR gtk-rs#602 Fix formatting issue Keep `downcast_unchecked` method on the same line as the closing parenthesis of the chopped-down call to `Widget::from_glib_none`.
Add support for file chooser buttons
Async exctraction
This commit adds support for file chooser buttons. They are represented
as a slice of tuples
(text, action)
. The original function usesvarargs to support an arbitrary number of arguments. This implementation
supports up to 3 buttons.
This is a breaking change.See: https://developer.gnome.org/gtk3/stable/GtkFileChooserDialog.html#gtk-file-chooser-dialog-new