+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Libs/Gdk-4.0/Public/Clipboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Threading.Tasks;

namespace Gdk;

public partial class Clipboard
{
//TODO: Async methods should be generated automatically (https://github.com/gircore/gir.core/issues/893)
public Task<string?> ReadTextAsync()
{
var tcs = new TaskCompletionSource<string?>();

var callbackHandler = new Gio.Internal.AsyncReadyCallbackAsyncHandler((sourceObject, res, data) =>
{
if (sourceObject is null)
{
tcs.SetException(new Exception("Missing source object"));
return;
}

var readValue = Internal.Clipboard.ReadTextFinish(sourceObject.Handle, res.Handle, out var error);

if (!error.IsInvalid)
tcs.SetException(new GLib.GException(error));
else
tcs.SetResult(readValue.ConvertToString());
});

Internal.Clipboard.ReadTextAsync(
clipboard: Handle,
cancellable: IntPtr.Zero,
callback: callbackHandler.NativeCallback,
userData: IntPtr.Zero
);

return tcs.Task;
}
}
39 changes: 39 additions & 0 deletions src/Libs/Gtk-4.0/Public/AlertDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Threading.Tasks;

namespace Gtk;

public partial class FileDialog
{
//TODO: Async methods should be generated automatically (https://github.com/gircore/gir.core/issues/893)
public Task<int> ChooseAsync(Window parent)
{
var tcs = new TaskCompletionSource<int>();

var callbackHandler = new Gio.Internal.AsyncReadyCallbackAsyncHandler((sourceObject, res, data) =>
{
if (sourceObject is null)
{
tcs.SetException(new Exception("Missing source object"));
return;
}

var chooseValue = Internal.AlertDialog.ChooseFinish(sourceObject.Handle, res.Handle, out var error);

if (!error.IsInvalid)
tcs.SetException(new GLib.GException(error));
else
tcs.SetResult(chooseValue);
});

Internal.AlertDialog.Choose(
self: Handle,
parent: parent.Handle,
cancellable: IntPtr.Zero,
callback: callbackHandler.NativeCallback,
userData: IntPtr.Zero
);

return tcs.Task;
}
}
64 changes: 64 additions & 0 deletions src/Libs/Gtk-4.0/Public/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@ public partial class FileDialog
return tcs.Task;
}

//TODO: Async methods should be generated automatically (https://github.com/gircore/gir.core/issues/893)
public Task<Gio.ListModel?> OpenMultipleAsync(Window parent)
{
var tcs = new TaskCompletionSource<Gio.ListModel?>();

var callbackHandler = new Gio.Internal.AsyncReadyCallbackAsyncHandler((sourceObject, res, data) =>
{
if (sourceObject is null)
{
tcs.SetException(new Exception("Missing source object"));
return;
}

var listValue = Internal.FileDialog.OpenMultipleFinish(sourceObject.Handle, res.Handle, out var error);

if (!error.IsInvalid)
tcs.SetException(new GLib.GException(error));
else
tcs.SetResult(GObject.Internal.ObjectWrapper.WrapNullableInterfaceHandle<Gio.ListModelHelper>(listValue, true));
});

Internal.FileDialog.OpenMultiple(
self: Handle,
parent: parent.Handle,
cancellable: IntPtr.Zero,
callback: callbackHandler.NativeCallback,
userData: IntPtr.Zero
);

return tcs.Task;
}

//TODO: Async methods should be generated automatically (https://github.com/gircore/gir.core/issues/893)
public Task<Gio.File?> SaveAsync(Window parent)
{
Expand Down Expand Up @@ -107,4 +139,36 @@ public partial class FileDialog

return tcs.Task;
}

//TODO: Async methods should be generated automatically (https://github.com/gircore/gir.core/issues/893)
public Task<Gio.ListModel?> SelectMultipleFoldersAsync(Window parent)
{
var tcs = new TaskCompletionSource<Gio.ListModel?>();

var callbackHandler = new Gio.Internal.AsyncReadyCallbackAsyncHandler((sourceObject, res, data) =>
{
if (sourceObject is null)
{
tcs.SetException(new Exception("Missing source object"));
return;
}

var listValue = Internal.FileDialog.SelectMultipleFoldersFinish(sourceObject.Handle, res.Handle, out var error);

if (!error.IsInvalid)
tcs.SetException(new GLib.GException(error));
else
tcs.SetResult(GObject.Internal.ObjectWrapper.WrapNullableInterfaceHandle<Gio.ListModelHelper>(listValue, true));
});

Internal.FileDialog.SelectMultipleFolders(
self: Handle,
parent: parent.Handle,
cancellable: IntPtr.Zero,
callback: callbackHandler.NativeCallback,
userData: IntPtr.Zero
);

return tcs.Task;
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载