6 changed files with 158 additions and 23 deletions
@ -1,21 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.Platform; |
|||
using Avalonia.Input.Platform; |
|||
using Avalonia.Platform; |
|||
|
|||
//TODO: This file should be empty once everything is implemented
|
|||
|
|||
namespace Avalonia.Gtk3 |
|||
{ |
|||
class SystemDialogStub : ISystemDialogImpl |
|||
{ |
|||
public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) => Task.FromResult(new string[0]); |
|||
|
|||
public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) |
|||
=> Task.FromResult((string) null); |
|||
} |
|||
} |
|||
@ -0,0 +1,94 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.Platform; |
|||
using Avalonia.Gtk3.Interop; |
|||
using Avalonia.Input.Platform; |
|||
using Avalonia.Platform; |
|||
|
|||
//TODO: This file should be empty once everything is implemented
|
|||
|
|||
namespace Avalonia.Gtk3 |
|||
{ |
|||
class SystemDialogStub : ISystemDialogImpl |
|||
{ |
|||
|
|||
unsafe static Task<string[]> ShowDialog(string title, GtkWindow parent, GtkFileChooserAction action, |
|||
bool multiselect, string initialFileName) |
|||
{ |
|||
GtkFileChooser dlg; |
|||
using (var name = title != null ? new Utf8Buffer(title) : null) |
|||
dlg = Native.GtkFileChooserDialogNew(name, parent, action, IntPtr.Zero); |
|||
if (multiselect) |
|||
Native.GtkFileChooserSetSelectMultiple(dlg, true); |
|||
|
|||
Native.GtkWindowSetModal(dlg, true); |
|||
var tcs = new TaskCompletionSource<string[]>(); |
|||
List<IDisposable> disposables = null; |
|||
Action dispose = () => |
|||
{ |
|||
foreach (var d in disposables) |
|||
d.Dispose(); |
|||
disposables.Clear(); |
|||
}; |
|||
disposables = new List<IDisposable> |
|||
{ |
|||
Signal.Connect<Native.D.signal_generic>(dlg, "close", delegate |
|||
{ |
|||
tcs.TrySetResult(null); |
|||
dispose(); |
|||
return false; |
|||
}), |
|||
Signal.Connect<Native.D.signal_dialog_response>(dlg, "response", (_, resp, __)=> |
|||
{ |
|||
string[] result = null; |
|||
if (resp == GtkResponseType.Accept) |
|||
{ |
|||
var rlst = new List<string>(); |
|||
var gs = Native.GtkFileChooserGetFilenames(dlg); |
|||
var cgs = gs; |
|||
while (cgs != null) |
|||
{ |
|||
if (cgs->Data != IntPtr.Zero) |
|||
rlst.Add(Utf8Buffer.StringFromPtr(cgs->Data)); |
|||
cgs = cgs->Next; |
|||
} |
|||
Native.GSlistFree(gs); |
|||
result = rlst.ToArray(); |
|||
} |
|||
Native.GtkWidgetHide(dlg); |
|||
dispose(); |
|||
tcs.TrySetResult(result); |
|||
return false; |
|||
}), |
|||
dlg |
|||
}; |
|||
using (var open = new Utf8Buffer("Open")) |
|||
Native.GtkDialogAddButton(dlg, open, GtkResponseType.Accept); |
|||
using (var open = new Utf8Buffer("Cancel")) |
|||
Native.GtkDialogAddButton(dlg, open, GtkResponseType.Cancel); |
|||
if(initialFileName!=null) |
|||
using (var fn = new Utf8Buffer(initialFileName)) |
|||
Native.GtkFileChooserSetFilename(dlg, fn); |
|||
Native.GtkWindowPresent(dlg); |
|||
return tcs.Task; |
|||
} |
|||
|
|||
public Task<string[]> ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) |
|||
{ |
|||
return ShowDialog(dialog.Title, ((TopLevelImpl) parent)?.GtkWidget, |
|||
dialog is OpenFileDialog ? GtkFileChooserAction.Open : GtkFileChooserAction.Save, |
|||
(dialog as OpenFileDialog)?.AllowMultiple ?? false, dialog.InitialFileName); |
|||
} |
|||
|
|||
public async Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) |
|||
{ |
|||
var res = await ShowDialog(dialog.Title, ((TopLevelImpl) parent)?.GtkWidget, |
|||
GtkFileChooserAction.SelectFolder, false, dialog.InitialDirectory); |
|||
return res?.FirstOrDefault(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue