|
|
|
@ -13,13 +13,15 @@ namespace Avalonia.Dialogs |
|
|
|
{ |
|
|
|
class ManagedSystemDialogImpl<T> : ISystemDialogImpl where T : Window, new() |
|
|
|
{ |
|
|
|
async Task<string[]> Show(SystemDialog d, IWindowImpl parent) |
|
|
|
async Task<string[]> Show(SystemDialog d, IWindowImpl parent, ManagedFileDialogOptions options = null) |
|
|
|
{ |
|
|
|
var model = new ManagedFileChooserViewModel((FileSystemDialog)d); |
|
|
|
var model = new ManagedFileChooserViewModel((FileSystemDialog)d, |
|
|
|
options ?? new ManagedFileDialogOptions()); |
|
|
|
|
|
|
|
var dialog = new T |
|
|
|
{ |
|
|
|
Content = new ManagedFileChooser(), |
|
|
|
Title = d.Title, |
|
|
|
DataContext = model |
|
|
|
}; |
|
|
|
|
|
|
|
@ -48,6 +50,11 @@ namespace Avalonia.Dialogs |
|
|
|
{ |
|
|
|
return (await Show(dialog, parent))?.FirstOrDefault(); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<string[]> ShowFileDialogAsync(FileDialog dialog, Window parent, ManagedFileDialogOptions options) |
|
|
|
{ |
|
|
|
return await Show(dialog, parent.PlatformImpl, options); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static TAppBuilder UseManagedSystemDialogs<TAppBuilder>(this TAppBuilder builder) |
|
|
|
@ -65,5 +72,14 @@ namespace Avalonia.Dialogs |
|
|
|
AvaloniaLocator.CurrentMutable.Bind<ISystemDialogImpl>().ToSingleton<ManagedSystemDialogImpl<TWindow>>()); |
|
|
|
return builder; |
|
|
|
} |
|
|
|
|
|
|
|
public static Task<string[]> ShowManagedAsync(this OpenFileDialog dialog, Window parent, |
|
|
|
ManagedFileDialogOptions options = null) => ShowManagedAsync<Window>(dialog, parent, options); |
|
|
|
|
|
|
|
public static Task<string[]> ShowManagedAsync<TWindow>(this OpenFileDialog dialog, Window parent, |
|
|
|
ManagedFileDialogOptions options = null) where TWindow : Window, new() |
|
|
|
{ |
|
|
|
return new ManagedSystemDialogImpl<TWindow>().ShowFileDialogAsync(dialog, parent, options); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|