Browse Source

Added a ListView sorting framework to the Widgets library and used it to implement SD2-1266 - sortable columns in resource editor.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2289 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Christian Hornung 19 years ago
parent
commit
c0ff641dcc
  1. 5
      src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj
  2. 36
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs
  3. 12
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj
  4. 63
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/AbstractListViewParseableColumnComparer.cs
  5. 37
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/AbstractListViewSubItemComparer.cs
  6. 32
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/IListViewItemComparer.cs
  7. 24
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewIntegerParseColumnComparer.cs
  8. 199
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewItemSorter.cs
  9. 74
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewMultipleColumnsComparer.cs
  10. 48
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewTextColumnComparer.cs
  11. 43
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/Resources/BitmapResources.cs
  12. BIN
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/Resources/Icons.16x16.SortAscending.png
  13. BIN
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/Resources/Icons.16x16.SortDescending.png

5
src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj

@ -103,6 +103,11 @@ @@ -103,6 +103,11 @@
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

36
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEdit/ResourceList.cs

@ -16,6 +16,7 @@ using System.Windows.Forms; @@ -16,6 +16,7 @@ using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Internal.Undo;
using ICSharpCode.SharpDevelop.Widgets.ListViewSorting;
namespace ResourceEditor
{
@ -37,6 +38,8 @@ namespace ResourceEditor @@ -37,6 +38,8 @@ namespace ResourceEditor
bool writeProtected = false;
int editListViewItemIndex = -1;
ListViewItemSorter sorter;
public event EventHandler Changed;
public bool WriteProtected
@ -97,7 +100,6 @@ namespace ResourceEditor @@ -97,7 +100,6 @@ namespace ResourceEditor
View = View.Details;
GridLines = true;
LabelEdit = true;
Sorting = SortOrder.Ascending;
Dock = DockStyle.Fill;
HideSelection = false;
@ -111,9 +113,37 @@ namespace ResourceEditor @@ -111,9 +113,37 @@ namespace ResourceEditor
images.Images.Add(ResourceService.GetIcon("Icons.16x16.ResourceEditor.obj"));
SmallImageList = images;
// Set up sorting:
// User can sort the list by name and by type,
// whereas sorting by type also implicitly sorts by name.
IListViewItemComparer textComparer = new ListViewTextColumnComparer();
IListViewItemComparer typeNameComparer = new ListViewMultipleColumnsComparer(textComparer, 1, textComparer, 0);
sorter = new ListViewItemSorter(this,
new IListViewItemComparer[] {
textComparer,
typeNameComparer,
null
});
sorter.SortColumnIndex = 0;
sorter.SortOrder = SortOrder.Ascending;
ContextMenuStrip = MenuService.CreateContextMenu(editor, "/SharpDevelop/ResourceEditor/ResourceList/ContextMenu");
}
protected override void Dispose(bool disposing)
{
try {
if (disposing) {
if (sorter != null) {
sorter.Dispose();
sorter = null;
}
}
} finally {
base.Dispose(disposing);
}
}
public void LoadFile(string filename)
{
switch (Path.GetExtension(filename).ToLowerInvariant()) {
@ -208,6 +238,8 @@ namespace ResourceEditor @@ -208,6 +238,8 @@ namespace ResourceEditor
public void InitializeListView()
{
BeginUpdate();
// Suspend sorting to improve performance
ListViewItemSorter = null;
Items.Clear();
foreach (KeyValuePair<string, ResourceItem> entry in resources) {
@ -219,6 +251,8 @@ namespace ResourceEditor @@ -219,6 +251,8 @@ namespace ResourceEditor
ListViewItem lv = new ListViewItem(new String[] {item.Name, type, tmp}, item.ImageIndex);
Items.Add(lv);
}
ListViewItemSorter = sorter;
EndUpdate();
}

12
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ICSharpCode.SharpDevelop.Widgets.csproj

@ -48,6 +48,14 @@ @@ -48,6 +48,14 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="ListViewSorting\AbstractListViewParseableColumnComparer.cs" />
<Compile Include="ListViewSorting\AbstractListViewSubItemComparer.cs" />
<Compile Include="ListViewSorting\ListViewIntegerParseColumnComparer.cs" />
<Compile Include="ListViewSorting\ListViewMultipleColumnsComparer.cs" />
<Compile Include="ListViewSorting\ListViewTextColumnComparer.cs" />
<Compile Include="ListViewSorting\IListViewItemComparer.cs" />
<Compile Include="ListViewSorting\ListViewItemSorter.cs" />
<Compile Include="Resources\BitmapResources.cs" />
<Compile Include="TreeGrid\CollectionWithEvents.cs" />
<Compile Include="TreeGrid\DynamicList.cs" />
<Compile Include="TreeGrid\DynamicListColumn.cs" />
@ -66,9 +74,13 @@ @@ -66,9 +74,13 @@
<Compile Include="SpinnerControl.cs" />
<Compile Include="DesignTimeSupport\DropDownEditor.cs" />
<Compile Include="DesignTimeSupport\DropDownEditorListBox.cs" />
<EmbeddedResource Include="Resources\Icons.16x16.SortAscending.png" />
<EmbeddedResource Include="Resources\Icons.16x16.SortDescending.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration" />
<Folder Include="ListViewSorting" />
<Folder Include="Resources" />
<Folder Include="TreeGrid" />
<Folder Include="AutoHide" />
<Folder Include="SideBar" />

63
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/AbstractListViewParseableColumnComparer.cs

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Provides the ability to compare two ListViewItems by the
/// content of ListViewSubItems of a specific column.
/// The text content is converted to the type T by parsing
/// and the parsed value is compared using its IComparable implementation.
/// Values that are not parseable are considered less than other values
/// and are compared by their text value.
/// </summary>
public abstract class AbstractListViewParseableColumnComparer<T>
: AbstractListViewSubItemComparer
where T : IComparable<T>
{
protected override int Compare(ListViewItem.ListViewSubItem lhs, ListViewItem.ListViewSubItem rhs)
{
T lhsValue, rhsValue;
bool lhsValid = this.TryParse(lhs.Text, out lhsValue);
bool rhsValid = this.TryParse(rhs.Text, out rhsValue);
if (lhsValid) {
if (rhsValid) {
// both are valid -> compare
return lhsValue.CompareTo(rhsValue);
} else {
// only left is valid -> left is greater than right
return 1;
}
} else {
if (rhsValid) {
// only right is valid -> left is less than right
return -1;
} else {
// both are invalid -> compare the text values
return String.Compare(lhs.Text, rhs.Text, StringComparison.InvariantCulture);
}
}
}
/// <summary>
/// Tries to convert a text value to a value of type T.
/// </summary>
/// <param name="textValue">The text value to convert.</param>
/// <param name="parsedValue">Receives the converted value if successful. When <c>true</c> is returned, this parameter must not be set to <c>null</c> by the method.</param>
/// <returns><c>true</c> if the text value has been converted successfully, otherwise <c>false</c>.</returns>
protected abstract bool TryParse(string textValue, out T parsedValue);
}
}

37
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/AbstractListViewSubItemComparer.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Provides the ability to compare two ListViewItems by the
/// ListViewSubItems of a specific column.
/// </summary>
public abstract class AbstractListViewSubItemComparer : IListViewItemComparer
{
public int Compare(ListViewItem lhs, ListViewItem rhs, int column)
{
return this.Compare(lhs.SubItems[column], rhs.SubItems[column]);
}
/// <summary>
/// Compares two ListViewSubItems.
/// </summary>
/// <returns>
/// Less than zero if <paramref name="lhs"/> is less than <paramref name="rhs"/>.
/// Zero if <paramref name="lhs"/> is equal to <paramref name="rhs"/>.
/// Greater than zero if <paramref name="lhs"/> is greater than <paramref name="rhs"/>.
/// </returns>
/// <remarks>
/// The implementation must always compare the specified subitems in ascending order.
/// </remarks>
protected abstract int Compare(ListViewItem.ListViewSubItem lhs, ListViewItem.ListViewSubItem rhs);
}
}

32
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/IListViewItemComparer.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Provides the ability to compare two ListViewItems with regard to
/// a specific column.
/// </summary>
public interface IListViewItemComparer
{
/// <summary>
/// Compares two ListViewItems with regard to the specified column.
/// </summary>
/// <returns>
/// Less than zero if <paramref name="lhs"/> is less than <paramref name="rhs"/>.
/// Zero if <paramref name="lhs"/> is equal to <paramref name="rhs"/>.
/// Greater than zero if <paramref name="lhs"/> is greater than <paramref name="rhs"/>.
/// </returns>
/// <remarks>
/// The implementation must always compare the specified items in ascending order.
/// </remarks>
int Compare(ListViewItem lhs, ListViewItem rhs, int column);
}
}

24
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewIntegerParseColumnComparer.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Globalization;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Compares ListViewItems by the signed integer content of a specific column.
/// </summary>
public sealed class ListViewIntegerParseColumnComparer
: AbstractListViewParseableColumnComparer<Int64>
{
protected override bool TryParse(string textValue, out Int64 parsedValue)
{
return Int64.TryParse(textValue, NumberStyles.Any, CultureInfo.InvariantCulture, out parsedValue);
}
}
}

199
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewItemSorter.cs

@ -0,0 +1,199 @@ @@ -0,0 +1,199 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Widgets.Resources;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Sorts items in a ListView.
/// The user can select the column to sort by clicking on the column header.
/// </summary>
public sealed class ListViewItemSorter : IComparer, IDisposable
{
readonly ListView listView;
readonly IListViewItemComparer[] itemComparers;
int sortColumnIndex;
SortOrder sortOrder = SortOrder.None;
#region Properties
/// <summary>
/// Gets the ListView this ListViewItemSorter is associated with.
/// </summary>
public ListView ListView {
get { return listView; }
}
/// <summary>
/// Gets or sets the index of the list view column that is currently sorted.
/// Assigning a value to this property causes the ListView to be re-sorted.
/// </summary>
public int SortColumnIndex {
get { return sortColumnIndex; }
set {
sortColumnIndex = value;
this.SetColumnHeaderIcons();
this.ListView.Sort();
}
}
/// <summary>
/// Gets or sets the current sort order.
/// Assigning a value to this property causes the ListView to be re-sorted.
/// </summary>
public SortOrder SortOrder {
get { return sortOrder; }
set {
sortOrder = value;
this.SetColumnHeaderIcons();
this.ListView.Sort();
}
}
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="ListViewItemSorter"/> class
/// that can sort all columns by their text content
/// and attaches the new instance to the specified ListView.
/// </summary>
/// <param name="listView">The ListView that should be sorted and monitored for column click events.</param>
/// <remarks>
/// Note that the ListViewItemSorter constructor adds two bitmaps to the
/// SmallImageList of the ListView (an empty ImageList will be created
/// first if none is assigned).
/// </remarks>
public ListViewItemSorter(ListView listView)
: this(listView, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ListViewItemSorter"/> class
/// that uses the specified comparers to sort columns
/// and attaches the new instance to the specified ListView.
/// </summary>
/// <param name="listView">The ListView that should be sorted and monitored for column click events.</param>
/// <param name="itemComparers">An array of objects that implement IListViewItemComparer.
/// The index of the comparer in the array corresponds to the index of the list view column that it sorts.
/// If an element is <c>null</c>, the corresponding column cannot be sorted.
/// If this parameter is <c>null</c>, all columns can be sorted by their text content.</param>
/// <remarks>
/// Note that the ListViewItemSorter constructor adds two bitmaps to the
/// SmallImageList of the ListView (an empty ImageList will be created
/// first if none is assigned).
/// </remarks>
public ListViewItemSorter(ListView listView, IListViewItemComparer[] itemComparers)
{
if (listView == null) {
throw new ArgumentNullException("listView");
}
this.listView = listView;
if (itemComparers == null) {
IListViewItemComparer defaultComparer = new ListViewTextColumnComparer();
this.itemComparers = new IListViewItemComparer[this.ListView.Columns.Count];
for (int i = 0; i < this.itemComparers.Length; i++) {
this.itemComparers[i] = defaultComparer;
}
} else {
this.itemComparers = itemComparers;
}
if (this.ListView.SmallImageList == null) {
this.ListView.SmallImageList = new ImageList();
}
this.ListView.SmallImageList.Images.Add("SortAscending", BitmapResources.GetBitmap("Icons.16x16.SortAscending.png"));
this.ListView.SmallImageList.Images.Add("SortDescending", BitmapResources.GetBitmap("Icons.16x16.SortDescending.png"));
this.ListView.ColumnClick += this.ListViewColumnClick;
this.ListView.ListViewItemSorter = this;
}
/// <summary>
/// Cleans up all used resources.
/// </summary>
public void Dispose()
{
this.Dispose(true);
}
void Dispose(bool disposing)
{
if (disposing) {
this.ListView.ListViewItemSorter = null;
this.ListView.ColumnClick -= this.ListViewColumnClick;
}
}
void SetColumnHeaderIcons()
{
for (int i = 0; i < this.ListView.Columns.Count; i++) {
if (i == this.SortColumnIndex && this.SortOrder != SortOrder.None) {
if (this.SortOrder == SortOrder.Ascending) {
this.ListView.Columns[i].ImageKey = "SortAscending";
} else {
this.ListView.Columns[i].ImageKey = "SortDescending";
}
} else {
this.ListView.Columns[i].ImageKey = null;
}
}
}
void ListViewColumnClick(object sender, ColumnClickEventArgs e)
{
if (e.Column >= this.itemComparers.Length || this.itemComparers[e.Column] == null) {
return;
}
if (this.sortColumnIndex == e.Column) {
// Reverse the current sort direction for this column.
if (this.SortOrder == SortOrder.Ascending) {
this.SortOrder = SortOrder.Descending;
} else {
this.SortOrder = SortOrder.Ascending;
}
} else {
// assign to the field to prevent re-sorting twice
this.sortOrder = SortOrder.Ascending;
this.SortColumnIndex = e.Column;
}
}
public int Compare(object x, object y)
{
if (this.SortOrder == SortOrder.None ||
this.SortColumnIndex < 0 || this.SortColumnIndex >= this.itemComparers.Length ||
this.itemComparers[this.SortColumnIndex] == null) {
return 0;
}
int compareResult = this.itemComparers[this.SortColumnIndex].Compare((ListViewItem)x, (ListViewItem)y, this.SortColumnIndex);
if (this.SortOrder == SortOrder.Ascending) {
return compareResult;
} else {
return -compareResult;
}
}
}
}

74
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewMultipleColumnsComparer.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Compares ListViewItems by comparing multiple columns,
/// using an object that implements <see cref="IListViewItemComparer"/>
/// for every column to compare.
/// </summary>
public class ListViewMultipleColumnsComparer : IListViewItemComparer
{
readonly List<IListViewItemComparer> comparers = new List<IListViewItemComparer>(2);
readonly List<int> columns = new List<int>(2);
/// <summary>
/// Initializes a new instance of the <see cref="ListViewMultipleColumnsComparer"/> class.
/// </summary>
/// <param name="firstComparer">The <see cref="IListViewItemComparer"/> to use to compare the first column.</param>
/// <param name="firstColumn">The 0-based index of the first column to compare.</param>
/// <param name="secondComparer">The <see cref="IListViewItemComparer"/> to use to compare the second column.</param>
/// <param name="secondColumn">The 0-based index of the second column to compare.</param>
/// <remarks>
/// You can add more columns to compare by using the <see cref="AddComparer"/> method.
/// </remarks>
public ListViewMultipleColumnsComparer(IListViewItemComparer firstComparer, int firstColumn, IListViewItemComparer secondComparer, int secondColumn)
{
if (firstComparer == null) {
throw new ArgumentNullException("firstComparer");
}
if (secondComparer == null) {
throw new ArgumentNullException("secondComparer");
}
this.AddComparer(firstComparer, firstColumn);
this.AddComparer(secondComparer, secondColumn);
}
/// <summary>
/// Adds another column to compare.
/// </summary>
/// <param name="comparer">The <see cref="IListViewItemComparer"/> to use to compare this column.</param>
/// <param name="column">The 0-based index of the column to compare.</param>
public void AddComparer(IListViewItemComparer comparer, int column)
{
if (comparer == null) {
throw new ArgumentNullException("comparer");
}
this.comparers.Add(comparer);
this.columns.Add(column);
}
public int Compare(ListViewItem lhs, ListViewItem rhs, int column)
{
int compareResult;
for (int i = 0; i < this.comparers.Count; i++) {
if ((compareResult = this.comparers[i].Compare(lhs, rhs, this.columns[i])) != 0) {
return compareResult;
}
}
return 0;
}
}
}

48
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/ListViewSorting/ListViewTextColumnComparer.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
{
/// <summary>
/// Compares ListViewItems by the text of a specific column.
/// </summary>
public class ListViewTextColumnComparer : AbstractListViewSubItemComparer
{
readonly IComparer<string> stringComparer;
/// <summary>
/// Creates a new instance of the <see cref="ListViewTextColumnComparer"/> class
/// with a culture-independent and case-sensitive string comparer.
/// </summary>
public ListViewTextColumnComparer()
: this(StringComparer.InvariantCulture)
{
}
/// <summary>
/// Creates a new instance of the <see cref="ListViewTextColumnComparer"/> class
/// with the specified string comparer.
/// </summary>
/// <param name="stringComparer">The string comparer used to compare the item texts.</param>
public ListViewTextColumnComparer(IComparer<string> stringComparer)
{
if (stringComparer == null) {
throw new ArgumentNullException("stringComparer");
}
this.stringComparer = stringComparer;
}
protected override int Compare(ListViewItem.ListViewSubItem lhs, ListViewItem.ListViewSubItem rhs)
{
return this.stringComparer.Compare(lhs.Text, rhs.Text);
}
}
}

43
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/Resources/BitmapResources.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Christian Hornung" email="c-hornung@gmx.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Drawing;
namespace ICSharpCode.SharpDevelop.Widgets.Resources
{
/// <summary>
/// Manages the bitmap resources used by the widgets library.
/// These resources are kept outside of the SharpDevelop core
/// so that this library can be used independently.
/// </summary>
public static class BitmapResources
{
static readonly Dictionary<string, Bitmap> bitmapCache = new Dictionary<string, Bitmap>();
/// <summary>
/// Gets a bitmap from the embedded bitmap resources.
/// </summary>
/// <param name="name">The name of the bitmap to get.</param>
/// <returns>The Bitmap.</returns>
public static Bitmap GetBitmap(string name)
{
lock(bitmapCache) {
Bitmap bmp;
if (bitmapCache.TryGetValue(name, out bmp)) {
return bmp;
}
bmp = new Bitmap(typeof(BitmapResources).Assembly.GetManifestResourceStream(typeof(BitmapResources), name));
bitmapCache[name] = bmp;
return bmp;
}
}
}
}

BIN
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/Resources/Icons.16x16.SortAscending.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

BIN
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/Resources/Icons.16x16.SortDescending.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B

Loading…
Cancel
Save