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.
50 lines
1.2 KiB
50 lines
1.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Avalonia.Controls;
|
|
|
|
namespace Avalonia.Dialogs
|
|
{
|
|
internal class ManagedFileChooserFilterViewModel : InternalViewModelBase
|
|
{
|
|
private readonly string[] _extensions;
|
|
public string Name { get; }
|
|
|
|
public ManagedFileChooserFilterViewModel(FileDialogFilter filter)
|
|
{
|
|
Name = filter.Name;
|
|
|
|
if (filter.Extensions.Contains("*"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_extensions = filter.Extensions?.Select(e => "." + e.ToLowerInvariant()).ToArray();
|
|
}
|
|
|
|
public ManagedFileChooserFilterViewModel()
|
|
{
|
|
Name = "All files";
|
|
}
|
|
|
|
public bool Match(string filename)
|
|
{
|
|
if (_extensions == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
foreach (var ext in _extensions)
|
|
{
|
|
if (filename.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override string ToString() => Name;
|
|
}
|
|
}
|
|
|