From 518c79216ab38497e1c24d05b6d7278af702cc49 Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 16 Apr 2009 14:56:48 +0000 Subject: [PATCH] Cleanup OLD MRI list If the ItemID doesn't exist, remove the item. If the Menu text and Tooltip don't match, ask if the item should be removed. Always use the current Menu text and tooltip on the menu, rather than the one that was saved. --- .../Volian.Controls.Library/MostRecentItem.cs | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/PROMS/Volian.Controls.Library/MostRecentItem.cs b/PROMS/Volian.Controls.Library/MostRecentItem.cs index f2e4de05..9e786e92 100644 --- a/PROMS/Volian.Controls.Library/MostRecentItem.cs +++ b/PROMS/Volian.Controls.Library/MostRecentItem.cs @@ -39,7 +39,10 @@ namespace Volian.Controls.Library } public MostRecentItem Add(string s) { - return Add(new MostRecentItem(s)); + MostRecentItem mri = MostRecentItem.ParseString(s); + if(mri != null) + Add(mri); + return mri; } public MostRecentItem Add(IVEDrillDownReadOnly myDrillDown) { @@ -81,7 +84,7 @@ namespace Volian.Controls.Library _ItemID = value.ItemID; _MyItemInfo = value; _MenuTitle = GetMenuTitle(); - _ToolTip = GetToolTip(); + _ToolTip = GetToolTip(_MyItemInfo); } } private int _ItemID; @@ -111,37 +114,53 @@ namespace Volian.Controls.Library get { if (_ToolTip == null) - _ToolTip = GetToolTip(); + _ToolTip = GetToolTip(MyItemInfo); return _ToolTip; } set { _ToolTip = value; } } - private string GetToolTip() + private static string GetToolTip(ItemInfo item) { // reset active parent if null // if (MyItemInfo.MyProcedure.ActiveParent == null) MyItemInfo.MyProcedure.ActiveParent = null; - DocVersionInfo tmp = (DocVersionInfo)(MyItemInfo.MyProcedure.ActiveParent); + DocVersionInfo tmp = (DocVersionInfo)(item.MyProcedure.ActiveParent); StringBuilder sb = new StringBuilder(); int indent = BuildPath(tmp.MyFolder, ref sb); return sb.ToString(); } - private int BuildPath(FolderInfo folderInfo, ref StringBuilder sb) + private static 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)); + sb.Append(string.Format("{0}{1}\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) + public static MostRecentItem ParseString(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]; + int itemID = int.Parse(parts[0]); + ItemInfo item = ItemInfo.Get(itemID); + if (item == null) return null; + if (parts.Length > 1 && parts[1] != item.Path && !RetainBadMRIs()) + 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]); + return new MostRecentItem(item); + } + private static int _RetainBadMRIs = 0; + private static bool RetainBadMRIs() + { + if (_RetainBadMRIs == 0) + { + System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Do you want to retain old Recently Used Entries?", "Retain Recent Locations", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question); + _RetainBadMRIs = result == System.Windows.Forms.DialogResult.Yes ? 2 : 1; + } + return _RetainBadMRIs == 2; } public MostRecentItem(ItemInfo myItem) {