B2022-055 Fix to help prevent crashing when opening/closing/re-opening procedures.

This commit is contained in:
John Jenko 2022-05-16 13:54:46 +00:00
parent 4f987dc7fc
commit 4b6b9451df

View File

@ -14,7 +14,7 @@ using Volian.Base.Library;
namespace Volian.Controls.Library
{
public delegate ItemInfo DisplayTabControlEditorSearchIncTransEvent(object sender, vlnTreeItemInfoEventArgs args);
public delegate void DisplayTabControlEvent(object sender,EventArgs args);
public delegate void DisplayTabControlEvent(object sender, EventArgs args);
public delegate void DisplayTabControlStatusEvent(object sender, DisplayTabControlStatusEventArgs args);
public partial class DisplayTabControlStatusEventArgs : EventArgs
{
@ -49,17 +49,21 @@ namespace Volian.Controls.Library
_Text = text;
}
}
public partial class DisplayTabControl : UserControl
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
private static bool _SyncronizeEnahnced = false;
public static bool SyncronizeEnhanced
{
get { return DisplayTabControl._SyncronizeEnahnced; }
set { DisplayTabControl._SyncronizeEnahnced = value; }
}
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int _VersionID = 0;
// zero tells us to PROMS just opened and no procedure was selected yet so use the main proms window
@ -172,21 +176,24 @@ namespace Volian.Controls.Library
public event DisplayTabControlEvent ToggleRibbonExpanded;
public void OnToggleRibbonExpanded(object sender, EventArgs args)
{
if (ToggleRibbonExpanded != null) ToggleRibbonExpanded(sender,args);
if (ToggleRibbonExpanded != null) ToggleRibbonExpanded(sender, args);
}
public event DisplayTabControlEvent SelectedDisplayTabItemChanged;
public void OnSelectedDisplayTabItemChanged(object sender, EventArgs args)
{
if (SelectedDisplayTabItemChanged != null)SelectedDisplayTabItemChanged(sender, args);
if (SelectedDisplayTabItemChanged != null) SelectedDisplayTabItemChanged(sender, args);
}
// C2015-022 added copystep event to commuicate with child windows
public event ItemChangedEventHandler CopyStepSelected;
public void OnCopyStepSelected(ItemChangedEventArgs args)
{
if (CopyStepSelected != null)
CopyStepSelected(this, args);
}
#region Private Fields
/// <summary>
/// This is a lookup table for all of the DisplayTabItems that are currently open
/// The key is:
@ -194,11 +201,13 @@ namespace Volian.Controls.Library
/// "Doc - " + DocumentID for Word Documents
/// </summary>
public Dictionary<string, DisplayTabItem> _MyDisplayTabItems;
/// <summary>
/// When a Tab is closed it is added to this list.
/// When another Tab is opened, any Tabs in this list are closed
/// </summary>
private List<DisplayTabItem> _RemovedDisplayTabItems = null;
/// <summary>
/// This stores a UniqueID for Bars as they are opened.
/// A bar is the docking location for the DisplayTabItems.
@ -222,7 +231,7 @@ namespace Volian.Controls.Library
set { _MyEditItem = value; }
}
private StepRTB _MyStepRTB = null;
private bool _RibbonExpanded=true;
private bool _RibbonExpanded = true;
public StepRTB MyStepRTB
{
get { return _MyStepRTB; }
@ -367,7 +376,7 @@ namespace Volian.Controls.Library
if (_MyEditItem != null)
{
_MyStepRTB = _MyEditItem.MyStepRTB;
if(_MyStepRTB != null)
if (_MyStepRTB != null)
_MyStepRTB.Disposed += new EventHandler(_MyStepRTB_Disposed);
}
else
@ -381,47 +390,58 @@ namespace Volian.Controls.Library
}
if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args);
}
void _MyStepRTB_Disposed(object sender, EventArgs e)
{
_MyStepRTB = null;
}
public event StepPanelModeChangeEvent ModeChange;
internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{
if (ModeChange != null) ModeChange(sender, args);
else FlexibleMessageBox.Show("Cannot change mode");
}
public event StepPanelTabDisplayEvent PanelTabDisplay;
internal void OnPanelTabDisplay(object sender, StepPanelTabDisplayEventArgs args)
{
if (PanelTabDisplay != null) PanelTabDisplay(sender, args);
else FlexibleMessageBox.Show("Cannot display information");
}
public event StepPanelWordSectionCloseEvent WordSectionClose;
internal void OnWordSectionClose(object sender, WordSectionEventArgs args)
{
if (WordSectionClose != null) WordSectionClose(sender, args);
else FlexibleMessageBox.Show("Cannot close associated Word section");
}
public event StepPanelWordSectionDeletedEvent WordSectionDeleted;
internal void OnWordSectionDeleted(object sender, WordSectionEventArgs args)
{
if (WordSectionDeleted != null) WordSectionDeleted(sender, args);
else FlexibleMessageBox.Show("Cannot delete associated Word section");
}
public event StepPanelItemPastedEvent ItemPaste;
internal void OnItemPaste(object sender, vlnTreeItemInfoPasteEventArgs args)
{
if (ItemPaste != null) ItemPaste(sender, args);
else FlexibleMessageBox.Show("Cannot adjust panels for pasted item");
}
#endregion
#region Contructor & Setup
public DisplayTabControl()
{
InitializeComponent();
SetUp();
}
private void SetUp()
{
ItemsChangeIds = new Dictionary<int, string>();
@ -531,9 +551,10 @@ namespace Volian.Controls.Library
{
DisplayTabItem pg = _MyDisplayTabItems[key];
if (pg.MyStepTabPanel.MyStepPanel._LookupEditItems.ContainsKey(myItemInfo.ItemID))
OpenItem(myItemInfo,false);
OpenItem(myItemInfo, false);
}
}
public DisplayTabItem OpenItem(ItemInfo myItemInfo2)
{
//B2017-251 Added Error Log message for Open Step or MSWord section include time to do open
@ -542,6 +563,7 @@ namespace Volian.Controls.Library
_MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath);
return dti;
}
/// <summary>
/// Open a Step Item or a Word Item
/// </summary>
@ -550,11 +572,13 @@ namespace Volian.Controls.Library
public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus)
{
ItemInfo myItemInfo = myItemInfo2;
if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion
{
FlexibleMessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null;
}
string message = string.Empty;
//if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyDocVersion.VersionID, CheckOutType.DocVersion, ref message))
//{
@ -587,6 +611,7 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show("This is an automatically generated 'Table of Contents' section. It is not editable. It is generated during Print.", "Item not Editable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return SelectedDisplayTabItem;
}
bool libDocAlreadyOpen = false;
if (myItemInfo.MyContent.MyEntry != null) // Trying to open a Word document - see if it's a library document that is already opened.
libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo);
@ -611,6 +636,7 @@ namespace Volian.Controls.Library
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
}
if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
@ -621,11 +647,17 @@ namespace Volian.Controls.Library
VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs
_MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item.
if (myItemInfo.MyContent.MyEntry == null) // If it is not a Word document open in step editor
{
return OpenStepTabPage(myItemInfo, setFocus);
}
else // Otherwise open it in the Word editor
{
return OpenDSOTabPage(myItemInfo);
}
}
public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type)
{
CleanUpClosedItems();
@ -660,13 +692,14 @@ namespace Volian.Controls.Library
}
break;
default:
return false; ;
return false;
}
return true;
}
}
return false;
}
public bool DeleteRTBItem(ItemInfo myItemInfo)
{
CleanUpClosedItems();
@ -694,7 +727,8 @@ namespace Volian.Controls.Library
}
return false;
}
public bool InsertRTBItem(ItemInfo myItemInfo, string text, E_InsertType insertType, E_FromType fromType, int type,bool updateSelection)
public bool InsertRTBItem(ItemInfo myItemInfo, string text, E_InsertType insertType, E_FromType fromType, int type, bool updateSelection)
{
CleanUpClosedItems();
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -709,10 +743,10 @@ namespace Volian.Controls.Library
switch (insertType)
{
case E_InsertType.Before:
edtitm.AddSiblingBefore(text,updateSelection);
edtitm.AddSiblingBefore(text, updateSelection);
break;
case E_InsertType.After:
edtitm.AddSiblingAfter(text,updateSelection);
edtitm.AddSiblingAfter(text, updateSelection);
break;
case E_InsertType.Child:
edtitm.AddChild(text, fromType, type, null);
@ -725,6 +759,7 @@ namespace Volian.Controls.Library
}
return false;
}
private void CleanUpClosedItems()
{
while (_RemovedDisplayTabItems.Count > 0) // Clean-up any items that have been closed.
@ -734,10 +769,12 @@ namespace Volian.Controls.Library
RemoveItem(myTabItem);
}
}
public void CloseWordItem(ItemInfo myItemInfo)
{
CloseWordItem(myItemInfo, false);
}
public void CloseWordItem(ItemInfo myItemInfo, bool isBeingDeleted)
{
CleanUpClosedItems();
@ -925,7 +962,7 @@ namespace Volian.Controls.Library
}
}
}
private DisplayTabItem _SelectedDisplayTabItem=null;
private DisplayTabItem _SelectedDisplayTabItem = null;
public DisplayTabItem SelectedDisplayTabItem
{
get { return _SelectedDisplayTabItem; }
@ -1023,6 +1060,7 @@ namespace Volian.Controls.Library
}
}
}
public DisplayTabItem GetProcDisplayTabItem(ItemInfo myItemInfo)
{
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
@ -1059,6 +1097,7 @@ namespace Volian.Controls.Library
ItemInfo proc = myItemInfo.MyProcedure; // Find procedure Item
string key = "Item - " + proc.ItemID.ToString();
DisplayTabItem pg = null;
if (_MyDisplayTabItems.ContainsKey(key)) // If procedure page open use it
{
pg = _MyDisplayTabItems[key];
@ -1166,7 +1205,10 @@ namespace Volian.Controls.Library
private bool LibDocAlreadyOpen(ItemInfo myItemInfo, string key, ref DisplayTabItem pg, bool displayMsg)
{
bool libDocAlreadyOpen = false;
// C2015-022 part of separate windows logic, check all tabs in all windows to see if lib docs
if (_AllDTCs != null && _AllDTCs.Count > 0)
{
foreach (int k in _AllDTCs.Keys)
{
DisplayTabControl dtc = _AllDTCs[k];
@ -1185,6 +1227,8 @@ namespace Volian.Controls.Library
}
}
}
}
return libDocAlreadyOpen;
}
/// <summary>
@ -1252,16 +1296,27 @@ namespace Volian.Controls.Library
/// </summary>
/// <param name="myDisplayTabItem"></param>
internal void RemoveItem(DisplayTabItem myDisplayTabItem)
{
if (_MyDisplayTabItems.ContainsKey(myDisplayTabItem.MyKey))
{
try
{
_MyDisplayTabItems.Remove(myDisplayTabItem.MyKey);
// Dispose the Panel
// Dispose of the procedure tab panel
if (myDisplayTabItem.MyStepTabPanel != null)
myDisplayTabItem.MyStepTabPanel.Dispose();
// Dispose of the MS Word Panel
if (myDisplayTabItem.MyDSOTabPanel != null)
myDisplayTabItem.MyDSOTabPanel.CloseDSO();
components.Remove(myDisplayTabItem);
myDisplayTabItem.Dispose();
}
catch { }
}
}
#endregion
}
}