69 lines
2.0 KiB
C#
69 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using XSDVisualiser.Models;
|
|
|
|
namespace XSDVisualiser.Desktop.ViewModels
|
|
{
|
|
public class MainWindowViewModel : INotifyPropertyChanged
|
|
{
|
|
private SchemaModel _model;
|
|
private SchemaNode? _selectedRootElement;
|
|
|
|
public MainWindowViewModel(SchemaModel model)
|
|
{
|
|
_model = model ?? throw new ArgumentNullException(nameof(model));
|
|
}
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string? name = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
|
|
public SchemaModel Model
|
|
{
|
|
get => _model;
|
|
set
|
|
{
|
|
if (!ReferenceEquals(_model, value))
|
|
{
|
|
_model = value ?? throw new ArgumentNullException(nameof(value));
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(RootElements));
|
|
OnPropertyChanged(nameof(VisibleRootElements));
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerable<SchemaNode> RootElements => _model?.RootElements ?? Enumerable.Empty<SchemaNode>();
|
|
|
|
public SchemaNode? SelectedRootElement
|
|
{
|
|
get => _selectedRootElement;
|
|
set
|
|
{
|
|
if (!EqualityComparer<SchemaNode?>.Default.Equals(_selectedRootElement, value))
|
|
{
|
|
_selectedRootElement = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(VisibleRootElements));
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerable<SchemaNode> VisibleRootElements
|
|
{
|
|
get
|
|
{
|
|
if (SelectedRootElement != null)
|
|
return new[] { SelectedRootElement };
|
|
return RootElements;
|
|
}
|
|
}
|
|
}
|
|
}
|