/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; namespace dnSpy.Contracts.MVVM { /// /// Provides the column descs /// public interface IGridViewColumnDescsProvider { /// /// Gets the column descriptions list. The UI and the VM get notified when a column is selected (clicked). /// GridViewColumnDescs Descs { get; } } /// /// Contains all column descs. Notifies listeners (UI and VM) when a column is selected and sort direction is updated. /// public sealed class GridViewColumnDescs { /// /// All columns in UI order. Gets updated by the UI when the user drags a column. /// public GridViewColumnDesc[] Columns { get; set; } = Array.Empty(); /// /// Currently selected column and sort direction /// public GridViewSortedColumn SortedColumn { get => sortedColumn; set { if (value.Column != sortedColumn.Column || value.Direction != sortedColumn.Direction) { sortedColumn = value; SortedColumnChanged?.Invoke(this, EventArgs.Empty); } } } GridViewSortedColumn sortedColumn; /// /// Raised when is changed /// public event EventHandler? SortedColumnChanged; } /// /// Contains the active column and sort direction /// public readonly struct GridViewSortedColumn { /// /// Column or null to use default sort order /// public readonly GridViewColumnDesc? Column; /// /// Sort direction /// public readonly GridViewSortDirection Direction; /// /// Constructor /// /// Column or null to use default sort order /// Sort direction public GridViewSortedColumn(GridViewColumnDesc? column, GridViewSortDirection direction) { Column = column; Direction = direction; } /// /// Deconstruct /// /// /// public void Deconstruct(out GridViewColumnDesc? column, out GridViewSortDirection direction) { column = Column; direction = Direction; } } /// /// Grid view column info needed by UI and VM /// public sealed class GridViewColumnDesc { /// /// A unique ID. No other coulumn in this grid view can have the same id. /// public int Id { get; } /// /// Name shown in the UI or an empty string /// public string Name { get; } /// /// true if the user can sort this column /// public bool CanBeSorted { get; set; } /// /// true if the column is visible in the UI /// public bool IsVisible => true; /// /// Constructor /// /// A unique ID. No other coulumn in this grid view can have the same id. /// Name shown in the UI or an empty string public GridViewColumnDesc(int id, string name) { Id = id; Name = name ?? throw new ArgumentNullException(nameof(name)); CanBeSorted = name != string.Empty; } } /// /// Sort direction /// public enum GridViewSortDirection { /// /// Default order /// Default, /// /// Ascending order /// Ascending, /// /// Descending order /// Descending, } }