This commit is contained in:
Kathy Ruffing 2009-11-13 15:40:46 +00:00
parent 61bea1edc4
commit bd2f521f73

View File

@ -6,8 +6,15 @@ using System.Windows.Forms;
namespace Volian.Controls.Library
{
public delegate void MostRecentItemEvent();
public class MostRecentItemList : List<MostRecentItem>
{
public event ItemInfoEvent AfterRemove;
internal void OnAfterRemove(object sender)
{
if (AfterRemove != null) AfterRemove(sender);
}
private int _MaxItems = 10;
public int MaxItems
{
@ -23,13 +30,36 @@ namespace Volian.Controls.Library
tmp = mri;
// If it exists - remove it
if (tmp != null)
{
tmp.MyItemInfo.BeforeDelete -= new ItemInfoEvent(MyItemInfo_BeforeDelete);
Remove(tmp);
}
// Insert it in the first place in the list
Insert(0, myMRI);
// If more than MaxItems exist remove the items beyond MaxItems
while (Count > MaxItems) RemoveAt(MaxItems);
myMRI.MyItemInfo.BeforeDelete += new ItemInfoEvent(MyItemInfo_BeforeDelete);
return myMRI;
}
// delete the item from the most recently used list. This event gets handled
// when a delete item occurs.
void MyItemInfo_BeforeDelete(object sender)
{
ItemInfo ii = sender as ItemInfo;
if (ii != null)
{
MostRecentItem tmp = null;
// Look for the ItemID
foreach (MostRecentItem mri in this)
if (mri.ItemID == ii.ItemID)
tmp = mri;
// If it exists - remove it
if (tmp != null)
Remove(tmp);
OnAfterRemove(null);
}
}
public MostRecentItem Add(int itemID)
{
ItemInfo tmp = ItemInfo.Get(itemID);
@ -156,7 +186,7 @@ namespace Volian.Controls.Library
return null; // Path doesn't match
if (parts.Length > 2 && parts[2] != GetToolTip(item) && !RetainBadMRIs())
return null;// Tooltip doesn't match
Console.WriteLine("{0},'{1}'", parts[0], parts[1]);
//Console.WriteLine("{0},'{1}'", parts[0], parts[1]);
return new MostRecentItem(item);
}
private static int _RetainBadMRIs = 0;