80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using XSDVisualiser.Core;
|
|
|
|
namespace XSDVisualiser.Desktop.ViewModels;
|
|
|
|
public class MainWindowViewModel(SchemaModel model) : INotifyPropertyChanged
|
|
{
|
|
private string? _currentFilePath;
|
|
private SchemaModel _model = model ?? throw new ArgumentNullException(nameof(model));
|
|
private SchemaNode? _selectedNode;
|
|
private SchemaNode? _selectedRootElement;
|
|
|
|
public SchemaModel Model
|
|
{
|
|
get => _model;
|
|
set
|
|
{
|
|
if (ReferenceEquals(_model, value)) return;
|
|
_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)) return;
|
|
_selectedRootElement = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(VisibleRootElements));
|
|
}
|
|
}
|
|
|
|
public SchemaNode? SelectedNode
|
|
{
|
|
get => _selectedNode;
|
|
set
|
|
{
|
|
if (EqualityComparer<SchemaNode?>.Default.Equals(_selectedNode, value)) return;
|
|
_selectedNode = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public IEnumerable<SchemaNode> VisibleRootElements =>
|
|
SelectedRootElement != null ? [SelectedRootElement] : RootElements;
|
|
|
|
public string? CurrentFilePath
|
|
{
|
|
get => _currentFilePath;
|
|
set
|
|
{
|
|
if (string.Equals(_currentFilePath, value, StringComparison.Ordinal)) return;
|
|
_currentFilePath = value;
|
|
OnPropertyChanged();
|
|
OnPropertyChanged(nameof(CurrentFileName));
|
|
OnPropertyChanged(nameof(CurrentDirectory));
|
|
}
|
|
}
|
|
|
|
public string? CurrentFileName =>
|
|
string.IsNullOrEmpty(_currentFilePath) ? null : Path.GetFileName(_currentFilePath);
|
|
|
|
public string? CurrentDirectory =>
|
|
string.IsNullOrEmpty(_currentFilePath) ? null : Path.GetDirectoryName(_currentFilePath);
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string? name = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
} |