mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-16 18:47:28 -05:00
More UI updates
This commit is contained in:
@@ -6,71 +6,70 @@ using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Realms;
|
||||
|
||||
namespace FeedCenter
|
||||
namespace FeedCenter;
|
||||
|
||||
public class Category : RealmObject, INotifyDataErrorInfo
|
||||
{
|
||||
public class Category : RealmObject, INotifyDataErrorInfo
|
||||
public const string DefaultName = "< default >";
|
||||
|
||||
private readonly DataErrorDictionary _dataErrorDictionary;
|
||||
|
||||
public Category()
|
||||
{
|
||||
public const string DefaultName = "< default >";
|
||||
_dataErrorDictionary = new DataErrorDictionary();
|
||||
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
|
||||
}
|
||||
|
||||
private readonly DataErrorDictionary _dataErrorDictionary;
|
||||
[Ignored]
|
||||
public ICollection<Feed> Feeds { get; set; }
|
||||
|
||||
public Category()
|
||||
[PrimaryKey]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public bool IsDefault { get; internal set; }
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => RawName;
|
||||
set
|
||||
{
|
||||
_dataErrorDictionary = new DataErrorDictionary();
|
||||
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
|
||||
}
|
||||
RawName = value;
|
||||
|
||||
[Ignored]
|
||||
public ICollection<Feed> Feeds { get; set; }
|
||||
|
||||
[PrimaryKey]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public bool IsDefault { get; internal set; }
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => RawName;
|
||||
set
|
||||
{
|
||||
RawName = value;
|
||||
|
||||
ValidateName();
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[MapTo("Name")]
|
||||
private string RawName { get; set; } = string.Empty;
|
||||
|
||||
[UsedImplicitly]
|
||||
public int SortKey => IsDefault ? 0 : 1;
|
||||
|
||||
public bool HasErrors => _dataErrorDictionary.Any();
|
||||
|
||||
public IEnumerable GetErrors(string propertyName)
|
||||
{
|
||||
return _dataErrorDictionary.GetErrors(propertyName);
|
||||
}
|
||||
|
||||
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
|
||||
|
||||
private void DataErrorDictionaryErrorsChanged(object sender, DataErrorsChangedEventArgs e)
|
||||
{
|
||||
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(e.PropertyName));
|
||||
}
|
||||
|
||||
public static Category CreateDefault()
|
||||
{
|
||||
return new Category { Name = DefaultName, IsDefault = true };
|
||||
}
|
||||
|
||||
private void ValidateName()
|
||||
{
|
||||
_dataErrorDictionary.ClearErrors(nameof(Name));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
_dataErrorDictionary.AddError(nameof(Name), "Name cannot be empty");
|
||||
ValidateName();
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[MapTo("Name")]
|
||||
private string RawName { get; set; } = string.Empty;
|
||||
|
||||
[UsedImplicitly]
|
||||
public int SortKey => IsDefault ? 0 : 1;
|
||||
|
||||
public bool HasErrors => _dataErrorDictionary.Any();
|
||||
|
||||
public IEnumerable GetErrors(string propertyName)
|
||||
{
|
||||
return _dataErrorDictionary.GetErrors(propertyName);
|
||||
}
|
||||
|
||||
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
|
||||
|
||||
private void DataErrorDictionaryErrorsChanged(object sender, DataErrorsChangedEventArgs e)
|
||||
{
|
||||
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(e.PropertyName));
|
||||
}
|
||||
|
||||
public static Category CreateDefault()
|
||||
{
|
||||
return new Category { Name = DefaultName, IsDefault = true };
|
||||
}
|
||||
|
||||
private void ValidateName()
|
||||
{
|
||||
_dataErrorDictionary.ClearErrors(nameof(Name));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
_dataErrorDictionary.AddError(nameof(Name), "Name cannot be empty");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user