csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.3 KiB
78 lines
2.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls.Platform;
|
|
|
|
namespace Avalonia.Controls
|
|
{
|
|
public abstract class FileDialog : FileSystemDialog
|
|
{
|
|
public List<FileDialogFilter> Filters { get; set; } = new List<FileDialogFilter>();
|
|
public string InitialFileName { get; set; }
|
|
}
|
|
|
|
public abstract class FileSystemDialog : SystemDialog
|
|
{
|
|
[Obsolete("Use Directory")]
|
|
public string InitialDirectory
|
|
{
|
|
get => Directory;
|
|
set => Directory = value;
|
|
}
|
|
public string Directory { get; set; }
|
|
}
|
|
|
|
public class SaveFileDialog : FileDialog
|
|
{
|
|
public string DefaultExtension { get; set; }
|
|
|
|
public async Task<string> ShowAsync(Window parent)
|
|
{
|
|
if(parent == null)
|
|
throw new ArgumentNullException(nameof(parent));
|
|
return ((await AvaloniaLocator.Current.GetService<ISystemDialogImpl>()
|
|
.ShowFileDialogAsync(this, parent?.PlatformImpl)) ??
|
|
Array.Empty<string>()).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
public class OpenFileDialog : FileDialog
|
|
{
|
|
public bool AllowMultiple { get; set; }
|
|
|
|
public Task<string[]> ShowAsync(Window parent)
|
|
{
|
|
if(parent == null)
|
|
throw new ArgumentNullException(nameof(parent));
|
|
return AvaloniaLocator.Current.GetService<ISystemDialogImpl>().ShowFileDialogAsync(this, parent?.PlatformImpl);
|
|
}
|
|
}
|
|
|
|
public class OpenFolderDialog : FileSystemDialog
|
|
{
|
|
[Obsolete("Use Directory")]
|
|
public string DefaultDirectory
|
|
{
|
|
get => Directory;
|
|
set => Directory = value;
|
|
}
|
|
public Task<string> ShowAsync(Window parent)
|
|
{
|
|
if(parent == null)
|
|
throw new ArgumentNullException(nameof(parent));
|
|
return AvaloniaLocator.Current.GetService<ISystemDialogImpl>().ShowFolderDialogAsync(this, parent?.PlatformImpl);
|
|
}
|
|
}
|
|
|
|
public abstract class SystemDialog
|
|
{
|
|
public string Title { get; set; }
|
|
}
|
|
|
|
public class FileDialogFilter
|
|
{
|
|
public string Name { get; set; }
|
|
public List<string> Extensions { get; set; } = new List<string>();
|
|
}
|
|
}
|
|
|