///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
namespace JetBrains.Omea.OpenAPI
{
///
/// Specifies possible flags for a column.
///
[Flags]
public enum ColumnDescriptorFlags
{
///
/// No special flags.
///
None = 0,
///
/// The column cannot be resized by the user.
///
FixedSize = 1,
///
/// The column is shown only if at least one resource in the displayed resource list
/// has a value in the column.
///
/// 2.0
ShowIfNotEmpty = 2,
///
/// The column is shown only if the resources in the displayed resource list have
/// different values for the column.
///
/// 2.0
ShowIfDistinct = 4,
///
/// The column is resized so that the available space in the resource list is divided
/// between the autosize columns and no scroll bars appear.
///
/// 2.0
AutoSize = 8
}
///
/// The descriptor for a single column which can be displayed in the resource browser.
/// Contains the property names, width, flags and a custom comparer for the column.
///
public struct ColumnDescriptor
{
///
/// The names of properties displayed in the column.
///
public string[] PropNames;
///
/// The width of the column in pixels.
///
public int Width;
///
/// The flags of the column.
///
public ColumnDescriptorFlags Flags;
///
/// The custom comparer used for sorting by the column.
///
public IResourceComparer CustomComparer;
///
/// The group provider used for grouping by the column.
///
/// 2.0
public IResourceGroupProvider GroupProvider;
///
/// The text which is displayed in the sort direction header when the multiline
/// view list is sorted by this column in ascending order.
///
/// 2.0
public string SortMenuAscText;
///
/// The text which is displayed in the sort direction header when the multiline
/// view list is sorted by this column in descending order.
///
/// 2.0
public string SortMenuDescText;
///
/// Creates a column descriptor for displaying a single property with default flags.
///
/// The name of the property displayed in the column.
/// The width of the column in pixels.
public ColumnDescriptor( string propName, int width )
: this( propName, width, ColumnDescriptorFlags.None ) {}
///
/// Creates a column descriptor for displaying multiple properties with default flags.
///
/// The names of the properties displayed in the column.
/// The width of the column in pixels.
public ColumnDescriptor( string[] propNames, int width )
: this( propNames, width, ColumnDescriptorFlags.None ) {}
///
/// Creates a column descriptor for displaying a single property with specified flags.
///
/// The name of the property displayed in the column.
/// The width of the column in pixels.
/// The flags of the column.
public ColumnDescriptor( string propName, int width, ColumnDescriptorFlags flags )
{
PropNames = new string[] { propName };
Width = width;
Flags = flags;
CustomComparer = null;
GroupProvider = null;
SortMenuAscText = null;
SortMenuDescText = null;
}
///
/// Creates a column descriptor for displaying multiple properties with default flags.
///
/// The names of the properties displayed in the column.
/// The width of the column in pixels.
/// The flags of the column.
public ColumnDescriptor( string[] propNames, int width, ColumnDescriptorFlags flags )
{
PropNames = propNames;
Width = width;
Flags = flags;
CustomComparer = null;
GroupProvider = null;
SortMenuAscText = null;
SortMenuDescText = null;
}
public override string ToString()
{
string result = String.Join( "|", PropNames ) + ":" + Width;
if ( ( Flags & ColumnDescriptorFlags.FixedSize ) != 0 )
{
result += "F";
}
return result;
}
public override bool Equals( object obj )
{
if ( obj == null || !(obj is ColumnDescriptor) )
return false;
ColumnDescriptor rhs = (ColumnDescriptor) obj;
if ( !EqualsIgnoreWidth( rhs ) )
return false;
if ( Width != rhs.Width )
return false;
return true;
}
public bool EqualsIgnoreWidth( ColumnDescriptor rhs )
{
if ( !PropNamesEqual( rhs ) )
return false;
if ( Flags != rhs.Flags )
return false;
return true;
}
public bool PropNamesEqual( ColumnDescriptor rhs )
{
if ( rhs.PropNames.Length != PropNames.Length )
return false;
for( int i=0; i