window: Let the user select multiple files to open.

Uses code that drag and drop already uses. It's kinda ugly because the
file dialog returns a ListModel.

As an added bonus, since the button responds to the action "win.open",
it will also allow open multiple files with the primary menu.
It would be a good idea to change the "Open…" label in the primary menu though.

Closes #191
This commit is contained in:
Huan Thieu Nguyen 2023-05-21 23:41:22 +02:00
parent 8804938859
commit c6897da62d
2 changed files with 11 additions and 3 deletions

View file

@ -182,7 +182,7 @@
<child>
<object class="GtkButton">
<property name="halign">center</property>
<property name="label" translatable="yes">_Open File…</property>
<property name="label" translatable="yes">_Open Files…</property>
<property name="use-underline">True</property>
<property name="action-name">win.open</property>
<style>

View file

@ -485,8 +485,16 @@ impl LpWindow {
.modal(true)
.build();
if let Ok(file) = chooser.open_future(Some(self)).await {
self.image_view().set_image_from_file(file);
if let Ok(selected) = chooser.open_multiple_future(Some(self)).await {
let images: Vec<_> = selected
.into_iter()
.filter_map(|files| {
files
.ok()
.and_then(|object| object.downcast::<gio::File>().ok())
})
.collect();
self.image_view().set_images_from_files(images);
} else {
log::debug!("File dialog canceled or file not readable");
}