///
/// 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;
using System.Windows.Forms;
using JetBrains.Omea.Base;
using JetBrains.Omea.Containers;
using JetBrains.Omea.OpenAPI;
namespace JetBrains.Omea
{
///
/// A complete state of a resource list.
///
internal class ResourceListState
{
private ColumnDescriptor[] _columns;
private SortSettings _sortSettings;
private IResource _columnSchemeResource;
private string[] _keyTypes;
private IResource _ownerResource;
private string _ownerTab;
private bool _groupItems;
internal ResourceListState( ColumnDescriptor[] columns, SortSettings sortSettings, bool groupItems )
{
_columns = columns;
_sortSettings = sortSettings;
_groupItems = groupItems;
}
public ColumnDescriptor[] Columns
{
get { return _columns; }
set { _columns = value; }
}
public SortSettings SortSettings
{
get { return _sortSettings; }
}
public bool GroupItems
{
get { return _groupItems; }
set { _groupItems = value; }
}
public string[] KeyTypes
{
get { return _keyTypes; }
set { _keyTypes = value; }
}
public IResource OwnerResource
{
get { return _ownerResource; }
}
public void SetOwner( IResource resource, string tabId )
{
_keyTypes = null;
_ownerResource = resource;
_ownerTab = tabId;
}
internal void Delete()
{
new ResourceProxy( _columnSchemeResource ).DeleteAsync();
_columnSchemeResource = null;
}
internal static ResourceListState FromResource( IResource res )
{
DisplayColumnProps props = (Core.DisplayColumnManager as DisplayColumnManager).Props;
IResourceList columnDescriptorResources = res.GetLinksOfType( "ColumnDescriptor", props.ColumnDescriptor );
columnDescriptorResources.Sort( new int[] { props.ColumnOrder }, true );
ColumnDescriptor[] columns = new ColumnDescriptor [columnDescriptorResources.Count];
for( int i=0; i= oldColumnDescriptors.Count )
{
_columnSchemeResource.AddLink( props.ColumnDescriptor, columnDescriptorResource );
}
columnDescriptorResource.EndUpdate();
}
for( int i=_columns.Length; i < oldColumnDescriptors.Count; i++ )
{
new ResourceProxy( oldColumnDescriptors [i] ).Delete();
}
if ( _sortSettings != null )
{
string[] sortPropNames = new string[_sortSettings.SortProps.Length];
for( int i = 0; i < _sortSettings.SortProps.Length; i++ )
{
int sortProp = _sortSettings.SortProps[ i ];
if( sortProp < 0 )
{
sortPropNames[ i ] = "-" + Core.ResourceStore.PropTypes[ -sortProp ].Name;
}
else
{
sortPropNames[ i ] = Core.ResourceStore.PropTypes[ sortProp ].Name;
}
}
SetStringListProp( _columnSchemeResource, props.ColumnSortProps, sortPropNames );
_columnSchemeResource.SetProp( props.ColumnSortAsc, _sortSettings.SortAscending );
}
else
{
_columnSchemeResource.DeleteProp( props.ColumnSortProps );
}
if ( _keyTypes != null )
{
_columnSchemeResource.SetProp( props.ColumnKeyTypes, String.Join( ";", _keyTypes ) );
}
else if ( _ownerResource != null )
{
_columnSchemeResource.AddLink( props.ColumnSchemeOwner, _ownerResource );
_columnSchemeResource.SetProp( props.ColumnSchemeTab, _ownerTab );
}
_columnSchemeResource.SetProp( props.GroupItems, _groupItems );
_columnSchemeResource.EndUpdate();
}
private static SortSettings LoadSortSettings( IResource res, DisplayColumnProps props )
{
IStringList sortPropList = res.GetStringListProp( props.ColumnSortProps );
IntArrayList sortProps = IntArrayListPool.Alloc();
try
{
for( int i=0; i