C2015-022 Separate Windows Upgrade – support CopyStep among child windows, manage dictionary of child windows, OpenItem will decide if need to open in a child window or main window, child windows support of library documents

This commit is contained in:
John Jenko 2018-03-12 14:36:44 +00:00
parent d00ebcc35d
commit 8ba6a5d64a
2 changed files with 203 additions and 81 deletions

View File

@ -23,6 +23,10 @@ namespace Volian.Controls.Library
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
// C2015-022 part of separate windows upgrade. Remove the tab from our dictionary of all tab controls
//if (_AllDTCs.Count > 0 && VersionID != null && _AllDTCs.ContainsKey((int)VersionID))
if (_AllDTCs.Count > 0 && _AllDTCs.ContainsKey((int)VersionID))
_AllDTCs.Remove((int)VersionID);
} }
#region Component Designer generated code #region Component Designer generated code

View File

@ -58,25 +58,95 @@ namespace Volian.Controls.Library
set { DisplayTabControl._SyncronizeEnahnced = value; } set { DisplayTabControl._SyncronizeEnahnced = value; }
} }
private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>(); private static Dictionary<int, DisplayTabControl> _AllDTCs = new Dictionary<int, DisplayTabControl>();
private int? _VersionID = null; private int _VersionID = 0;
public int? VersionID // zero tells us to PROMS just opened and no procedure was selected yet so use the main proms window
// when the first procedure is opened, the VersionID is set and added to _AllDTCs
public int VersionID
{ {
get { return _VersionID; } get { return _VersionID; }
set set
{ {
if (_AllDTCs.ContainsKey((int)value)) if ((int)value != 0)
_AllDTCs[(int)value] = this; {
else if (!_AllDTCs.ContainsKey((int)value))
{
_AllDTCs.Add((int)value, this); _AllDTCs.Add((int)value, this);
if (_VersionID == 0)
_VersionID = value;
else
_MyLog.WarnFormat("VersionID tried to be Changed from {0} to {1}", _VersionID, value);
}
}
else
_VersionID = value; _VersionID = value;
} }
} }
public event ItemSelectedChangedEvent OpenEnhancedDocument; // This tells the display tab control whether or not the Separate Windows setting was set
public void OnOpenEnhancedDocument(ItemSelectedChangedEventArgs args) private bool _SeparateWindows = false;
public bool SeparateWindows
{ {
if (OpenEnhancedDocument != null) get { return _SeparateWindows; }
OpenEnhancedDocument(this, args); set { _SeparateWindows = value; }
}
// this gets called before displaying the PROMS Settings dialog (off of the V button)
// return true if at least one procedure is one in more than one procedure set
// Also cleanup the _AllDTCs dictionary by removing the VersionID's (procedure sets) that are not opened
public bool MoreThanOneProcedureSetIsOpen
{
get
{
List<int> verIdList = new List<int>(); // list of procedure sets being used
List<int> rmvList = new List<int>(); // list of procedure set no longer being used
if (_AllDTCs.Count > 0 && _AllDTCs.Keys.Count > 0)
{
foreach (int k in _AllDTCs.Keys)
{
DisplayTabControl dtc = _AllDTCs[k];
if (_AllDTCs.Count > 1 && dtc._MyDisplayTabItems.Count == 0)
{
if (!rmvList.Contains(k))
rmvList.Add(k);
}
else
{
int numKeysVersionID = 0;
foreach (string dtikey in dtc._MyDisplayTabItems.Keys)
{
DisplayTabItem dti = dtc._MyDisplayTabItems[dtikey];
if (dti.MyItemInfo.MyDocVersion.VersionID == k)
{
numKeysVersionID++;
if (!verIdList.Contains(dti.MyItemInfo.MyDocVersion.VersionID))
verIdList.Add(dti.MyItemInfo.MyDocVersion.VersionID);
}
}
if (numKeysVersionID == 0 && !rmvList.Contains(k))
rmvList.Add(k);
}
}
}
// remove the VersionID's that no not being used from the AllDTCs list
if (rmvList.Count > 0)
foreach (int i in rmvList)
_AllDTCs.Remove(i);
if (_AllDTCs.Count == 0)
_VersionID = 0;
return (verIdList.Count > 1);
}
}
//public event ItemSelectedChangedEvent OpenEnhancedDocument;
//public void OnOpenEnhancedDocument(ItemSelectedChangedEventArgs args)
//{
// if (OpenEnhancedDocument != null)
// OpenEnhancedDocument(this, args);
//}
public event ItemSelectedChangedEvent OpenInSeparateWindow;
public void OnOpenInSeparateWindow(ItemSelectedChangedEventArgs args)
{
if (OpenInSeparateWindow != null)
OpenInSeparateWindow(this, args);
} }
public event ItemSelectedChangedEvent RefreshEnhancedDocument; public event ItemSelectedChangedEvent RefreshEnhancedDocument;
public void OnRefreshEnhancedDocument(ItemSelectedChangedEventArgs args) public void OnRefreshEnhancedDocument(ItemSelectedChangedEventArgs args)
@ -99,6 +169,13 @@ namespace Volian.Controls.Library
{ {
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 #region Private Fields
/// <summary> /// <summary>
/// This is a lookup table for all of the DisplayTabItems that are currently open /// This is a lookup table for all of the DisplayTabItems that are currently open
@ -398,6 +475,8 @@ namespace Volian.Controls.Library
{ {
e.RemoveDockTab = true; e.RemoveDockTab = true;
_RemovedDisplayTabItems.Add((DisplayTabItem)e.DockContainerItem); _RemovedDisplayTabItems.Add((DisplayTabItem)e.DockContainerItem);
if (_MyDisplayTabItems.ContainsKey(((DisplayTabItem)e.DockContainerItem).MyKey))
_MyDisplayTabItems.Remove(((DisplayTabItem)e.DockContainerItem).MyKey); // C2015-022 separate windows supporting logic
DisplayTabItem dti = e.DockContainerItem as DisplayTabItem; DisplayTabItem dti = e.DockContainerItem as DisplayTabItem;
if (dti != null && dti.MyStepTabPanel != null) if (dti != null && dti.MyStepTabPanel != null)
dti.MyStepTabPanel.MyStepPanel.Dispose(); dti.MyStepTabPanel.MyStepPanel.Dispose();
@ -461,15 +540,6 @@ namespace Volian.Controls.Library
MessageBox.Show(this, "Possible disconnected item", "Item Not Found"); MessageBox.Show(this, "Possible disconnected item", "Item Not Found");
return null; return null;
} }
if(VersionID!=myItemInfo.MyDocVersion.VersionID)
{
if(_AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
if(VersionID != 0)
return _AllDTCs[0].OpenItem(myItemInfo);
}
string message = string.Empty; string message = string.Empty;
if (myItemInfo.MyContent.MyEntry == null) //not a document if (myItemInfo.MyContent.MyEntry == null) //not a document
{ {
@ -487,23 +557,46 @@ namespace Volian.Controls.Library
return null; return null;
} }
} }
//if (myItemInfo.IsProcedure)
//{
// DateTime start = DateTime.Now;
// myItemInfo = ProcedureInfo.GetItemAndChildrenByUnit(myItemInfo.ItemID, 0, 2);
// TimeSpan howlong = DateTime.Now - start;
// Console.WriteLine("Overall - " + howlong.ToString());
//}
CleanUpClosedItems(); CleanUpClosedItems();
if (myItemInfo == null) return null; if (myItemInfo == null) return null;
// if this is an auto table of contents section, don't edit it: // if this is an auto table of contents section, don't edit it:
if (myItemInfo.IsAutoTOCSection) if (myItemInfo.IsAutoTOCSection)
{ {
MessageBox.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); MessageBox.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; 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);
// C2015-022 modified if statement logic to support separate windows
// if opening the first procedure in a set, and the main PROMS window has a procedure opened from a different set,
// then create a new child window. All other procedures from that same set will open in this child window.
// _AllDTCs is a dictionary of of all procedure sets opened along with their DisplayTabContol. The key to
// the dictioan is the set's VersionID
if (VersionID != 0)
{
if (SeparateWindows && !libDocAlreadyOpen)
{
if (!_AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
OnOpenInSeparateWindow(new ItemSelectedChangedEventArgs(myItemInfo2)); // create a child (separate) PROMS window
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
}
if (VersionID != myItemInfo.MyDocVersion.VersionID && _AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
{
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
}
}
if (!libDocAlreadyOpen)
VersionID = myItemInfo.MyDocVersion.VersionID; // add it to _AllDTCs
_MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item. _MyBar = GetParentBar(myItemInfo); // Get the docking bar associated with this item.
if (myItemInfo.MyContent.MyEntry == null) // If it is a Word document open in step editor if (myItemInfo.MyContent.MyEntry == null) // If it is not a Word document open in step editor
return OpenStepTabPage(myItemInfo, setFocus); return OpenStepTabPage(myItemInfo, setFocus);
else // Otherwise open it in the Word editor else // Otherwise open it in the Word editor
return OpenDSOTabPage(myItemInfo); return OpenDSOTabPage(myItemInfo);
@ -1021,6 +1114,39 @@ namespace Volian.Controls.Library
if (pg != null && pg.MyStepTabPanel != null) pg.MyStepTabPanel.MyStepTabRibbon.SetChangeId(chgid, ii); if (pg != null && pg.MyStepTabPanel != null) pg.MyStepTabPanel.MyStepTabRibbon.SetChangeId(chgid, ii);
ChgId = chgid; ChgId = chgid;
} }
private bool LibDocAlreadyOpen(ItemInfo myItemInfo)
{
EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID;
DisplayTabItem pg = null;
return LibDocAlreadyOpen(myItemInfo, key, ref pg, false);
}
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
foreach (int k in _AllDTCs.Keys)
{
DisplayTabControl dtc = _AllDTCs[k];
if (dtc._MyDisplayTabItems.ContainsKey(key))
{
pg = dtc._MyDisplayTabItems[key];
if (pg.MyItemInfo.ItemID != myItemInfo.ItemID)
{
if (displayMsg)
{
string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle);
MessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK);
}
libDocAlreadyOpen = true;
break;
}
}
}
return libDocAlreadyOpen;
}
/// <summary> /// <summary>
/// This opens a Word page based upon an itemInfo. Since a word document may be a library /// This opens a Word page based upon an itemInfo. Since a word document may be a library
/// document, the related DocID is used for the Word document. /// document, the related DocID is used for the Word document.
@ -1032,16 +1158,8 @@ namespace Volian.Controls.Library
DisplayTabItem pg = null; DisplayTabItem pg = null;
EntryInfo myEntry = myItemInfo.MyContent.MyEntry; EntryInfo myEntry = myItemInfo.MyContent.MyEntry;
string key = "Doc - " + myEntry.DocID; string key = "Doc - " + myEntry.DocID;
if (_MyDisplayTabItems.ContainsKey(key)) // If document page open use it bool libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo, key, ref pg, true);
{ if (!libDocAlreadyOpen && pg == null)
pg = _MyDisplayTabItems[key];
if (pg.MyItemInfo.ItemID != myItemInfo.ItemID)
{
string msg = string.Format("{0} is already open", myItemInfo.MyContent.MyEntry.MyDocument.LibTitle);
MessageBox.Show(msg, "Library Document is Already Open", MessageBoxButtons.OK);
}
}
else
{ {
if (DSOTabPanel.Count >= DSOTabPanel.MSWordLimit) // Limit the number of open document pages to 18 if (DSOTabPanel.Count >= DSOTabPanel.MSWordLimit) // Limit the number of open document pages to 18
{ {