using System; using System.Collections.Generic; using System.Text; using VEPROMS.CSLA.Library; namespace Volian.Controls.Library { public class MostRecentItemList : List { private int _MaxItems = 10; public int MaxItems { get { return _MaxItems; } set { _MaxItems = value; } } public new MostRecentItem Add(MostRecentItem myMRI) { MostRecentItem tmp = null; // Look for the ItemID foreach (MostRecentItem mri in this) if (mri.ItemID == myMRI.ItemID) tmp = mri; // If it exists - remove it if (tmp != null) 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); return myMRI; } public MostRecentItem Add(int itemID) { return Add(new MostRecentItem(ItemInfo.Get(itemID))); } public MostRecentItem Add(ItemInfo myItem) { return Add(new MostRecentItem(myItem)); } public MostRecentItem Add(string s) { return Add(new MostRecentItem(s)); } public MostRecentItem Add(IVEDrillDownReadOnly myDrillDown) { if (typeof(ItemInfo).IsAssignableFrom(myDrillDown.GetType())) return Add(new MostRecentItem((ItemInfo)myDrillDown)); return null; } public static MostRecentItemList GetMRILst(System.Collections.Specialized.StringCollection list) { MostRecentItemList mril = new MostRecentItemList(); if (list != null) for (int i = list.Count - 1; i >= 0;i-- )// Add in reverse order so first is last and last is first mril.Add(list[i]); return mril; } public System.Collections.Specialized.StringCollection ToSettings() { if (Count == 0) return null; System.Collections.Specialized.StringCollection retval = new System.Collections.Specialized.StringCollection(); foreach (MostRecentItem mri in this) retval.Add(mri.ToString()); return retval; } } // Class public class MostRecentItem { [NonSerialized] private ItemInfo _MyItem; public ItemInfo MyItem { get { if (_MyItem == null) _MyItem = ItemInfo.Get(_ItemID); return _MyItem; } set { _ItemID = value.ItemID; _MyItem = value; _MenuTitle = GetMenuTitle(); _ToolTip = GetToolTip(); } } private int _ItemID; public int ItemID { get { return _ItemID; } set { _ItemID = value; } } private string _MenuTitle; public string MenuTitle { get { if (_MenuTitle == null) _MenuTitle = GetMenuTitle(); return _MenuTitle; } set { _MenuTitle = value; } } private string GetMenuTitle() { return MyItem.Path; } private string _ToolTip; public string ToolTip { get { if (_ToolTip == null) _ToolTip = GetToolTip(); return _ToolTip; } set { _ToolTip = value; } } private string GetToolTip() { DocVersionInfo tmp = (DocVersionInfo)(MyItem.MyProcedure.ActiveParent); StringBuilder sb = new StringBuilder(); int indent = BuildPath(tmp.MyFolder, ref sb); return sb.ToString(); } private int BuildPath(FolderInfo folderInfo, ref StringBuilder sb) { if (folderInfo.MyParent == null) return 0; int indent = BuildPath(folderInfo.MyParent, ref sb); sb.Append(string.Format("{0}{1}\r\n", "".PadLeft(indent * 2), folderInfo.Name)); return indent; } public override string ToString() { return string.Format("{0}~{1}~{2}", _ItemID, MenuTitle, ToolTip); } public MostRecentItem(string str) { string[] parts = str.Split("~".ToCharArray()); _ItemID = int.Parse(parts[0]); if (parts.Length > 1) _MenuTitle = parts[1]; if (parts.Length > 2) _ToolTip = parts[2]; } public MostRecentItem(ItemInfo myItem) { MyItem = myItem; } } }