jwharm / java-gi

GObject-Introspection bindings generator for Java
GNU Lesser General Public License v2.1
93 stars 9 forks source link

Example Of FileDialog ! #117

Closed SudoDios closed 3 months ago

SudoDios commented 3 months ago

Can you write example of FileDialog with openMultiple ? (how to get file from ListModel of GObjects ?)

val files = openMultipleFinish(result) //this is ListModel of GObject
jwharm commented 3 months ago

FileDialog.openMultipleFinish doesn't specify the item type of the ListModel, so it defaults to plain GObjects. I'll log an issue in Gtk to add the missing annotation.

You can work around it in the meantime:

ListModel list = dialog.openMultipleFinish(result);
List<File> files = new ArrayList<>();
for (int i = 0; i < list.getNItems(); i++)
    files.add(new File.FileImpl(list.getItem(i).handle()));
SudoDios commented 3 months ago

thanks bro. Okay

jwharm commented 3 months ago

Correction; it's not a missing annotation. ListModels just always return plain GObjects. I'll try to find a better solution than the workaround above though.

SudoDios commented 3 months ago

Yes that's right.

ListModels just always return plain GObjects.

jwharm commented 3 months ago

In the next release it will be possible to do var file = (File) listmodel.getItem(i).

SudoDios commented 3 months ago

How great 👍