Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manual bindings for async functions #903

Merged
merged 3 commits into from
Jul 23, 2023
Merged

Conversation

fsobolev
Copy link
Contributor

@fsobolev fsobolev commented Jul 20, 2023

  • I agree that my contribution may be licensed either under MIT or any version of LGPL license.

Added:

  • Gtk.FileDialog.OpenAsync
  • Gtk.FileDialog.SaveAsync
  • Gtk.FileDialog.SelectFolderAsync
  • Gtk.FileLauncher.LaunchAsync
  • Gtk.FileLauncher.OpenContainingFolderAsync
  • Gtk.UriLauncher.LaunchAsync

I don't think that throwing an exception on error like it's done in WebView is desired behavior, error is set even if a dialog was simply cancelled by the user, which is definitely not a critical error and I think just checking for null/false makes more sense:

Related: #900

@fsobolev fsobolev force-pushed the async branch 4 times, most recently from bff04ac to 200884c Compare July 21, 2023 21:31
@fsobolev
Copy link
Contributor Author

/home/runner/work/gir.core/gir.core/src/Libs/Gtk-4.0/Public/FileDialog.cs(1,1): error CHARSET: Fix file encoding. [/home/runner/work/gir.core/gir.core/src/Libs/Gtk-4.0/Gtk-4.0.csproj]
/home/runner/work/gir.core/gir.core/src/Libs/Gtk-4.0/Public/FileLauncher.cs(1,1): error CHARSET: Fix file encoding. [/home/runner/work/gir.core/gir.core/src/Libs/Gtk-4.0/Gtk-4.0.csproj]
/home/runner/work/gir.core/gir.core/src/Libs/Gtk-4.0/Public/UriLauncher.cs(1,1): error CHARSET: Fix file encoding. [/home/runner/work/gir.core/gir.core/src/Libs/Gtk-4.0/Gtk-4.0.csproj]

Ugh... What does that mean? 😓 Files are just ASCII text.

@badcel
Copy link
Member

badcel commented Jul 22, 2023

You should be able to run dotnet format GirCore.Libs.slnf in folder src which should fix those things. If it does not work you can try to specify the csproj from GTK directly to only Format the GTK project.

@fsobolev fsobolev force-pushed the async branch 2 times, most recently from 49ad94d to 85f0ec3 Compare July 22, 2023 06:24
@badcel
Copy link
Member

badcel commented Jul 22, 2023

One more thing is necessary. If the ...Finish method can return null (see documentation) then it is necessary to check the return value for IntPtr.Zero after the GLib.Error.ThrowOnError:

Rough sample:

if(result == IntPtr.Zero)
{
tcs.SetResult(null);
}
else
{
//here original code to get and set the result in the task completion source.
}

@fsobolev fsobolev force-pushed the async branch 3 times, most recently from 12b4dbb to 88a2532 Compare July 22, 2023 18:10
@fsobolev
Copy link
Contributor Author

Added Gtk.FileLauncher.OpenContainingFolderAsync

@badcel badcel merged commit 6c95f0b into gircore:main Jul 23, 2023
@badcel
Copy link
Member

badcel commented Jul 23, 2023

Looks good to me. Thanks for your contribution 🚀

@fsobolev fsobolev deleted the async branch July 23, 2023 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants