using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using Chernobyl.App.Core; namespace Chernobyl.App.Layout { /// /// A view model representing a view of some data and the actions that can be performed on that /// data. /// public class ContentTabsViewModel : ViewModel { /// The content vailable for viewing. public ContentTabsViewModel(ObservableCollection available) : this(available, Enumerable.Empty()) {} /// The content vailable for viewing. /// Tools that are common to all tabs. public ContentTabsViewModel(ObservableCollection available, IEnumerable tools) { _constantTools = tools; _tools = _constantTools.Cast(); Available = available; Current = Available.FirstOrDefault(); // Select the first piece of content once it is added. if (Current == null) { Available.CollectionChanged += (sender, args) => { if (args.Action == NotifyCollectionChangedAction.Add && (args.OldItems == null || args.OldItems.Count == 0)) Current = Available.FirstOrDefault(); }; } } /// /// The tools or information available for use when interacting with the content. /// public IEnumerable Tools { get => _tools; private set { if (_tools != value) { _tools = value; RaisePropertyChanged(); } } } /// /// The currently selected tab content being displayed. /// public Content Current { get => _current; set { if (_current != value) { _current = value; RaisePropertyChanged(); if (_current != null) Tools = _constantTools.Cast().Concat(_current.Tools.Cast()); } } } /// /// The content vailable for viewing. /// public ObservableCollection Available { get; } readonly IEnumerable _constantTools; IEnumerable _tools; Content _current; } }