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); {
_VersionID = value; _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;
} }
} }
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();
@ -448,66 +527,80 @@ namespace Volian.Controls.Library
_MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath); _MyLog.InfoFormat("OpenItem {0} seconds {1} {2}", TimeSpan.FromTicks(DateTime.Now.Ticks - tStart.Ticks).TotalSeconds, myItemInfo2.ItemID, myItemInfo2.ShortPath);
return dti; return dti;
} }
/// <summary> /// <summary>
/// Open a Step Item or a Word Item /// Open a Step Item or a Word Item
/// </summary> /// </summary>
/// <param name="myItemInfo"></param> /// <param name="myItemInfo"></param>
/// <returns></returns> /// <returns></returns>
public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus) public DisplayTabItem OpenItem(ItemInfo myItemInfo2, bool setFocus)
{ {
ItemInfo myItemInfo = myItemInfo2; ItemInfo myItemInfo = myItemInfo2;
if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion if (myItemInfo.MyDocVersion == null) // bug fix: B2016-108 disconnected data will not have a MyDocVersion
{ {
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) string message = string.Empty;
{ if (myItemInfo.MyContent.MyEntry == null) //not a document
if(_AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID)) {
{ if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyProcedure.ItemID, CheckOutType.Procedure, ref message))
return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo); {
} MessageBox.Show(this, message, "Procedure Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
if(VersionID != 0) return null;
return _AllDTCs[0].OpenItem(myItemInfo); }
} }
string message = string.Empty; else
if (myItemInfo.MyContent.MyEntry == null) //not a document {
{ if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyContent.MyEntry.DocID, CheckOutType.Document, ref message))
if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyProcedure.ItemID, CheckOutType.Procedure, ref message)) {
{ MessageBox.Show(this, message, "Document Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(this, message, "Procedure Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning); return null;
return null; }
} }
}
else CleanUpClosedItems();
{ if (myItemInfo == null) return null;
if (!MySessionInfo.CanCheckOutItem(myItemInfo.MyContent.MyEntry.DocID, CheckOutType.Document, ref message))
{ // if this is an auto table of contents section, don't edit it:
MessageBox.Show(this, message, "Document Already Checked Out", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (myItemInfo.IsAutoTOCSection)
return null; {
} 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;
//if (myItemInfo.IsProcedure) }
//{ bool libDocAlreadyOpen = false;
// DateTime start = DateTime.Now; if (myItemInfo.MyContent.MyEntry != null) // Trying to open a Word document - see if it's a library document that is already opened.
// myItemInfo = ProcedureInfo.GetItemAndChildrenByUnit(myItemInfo.ItemID, 0, 2); libDocAlreadyOpen = LibDocAlreadyOpen(myItemInfo);
// TimeSpan howlong = DateTime.Now - start;
// Console.WriteLine("Overall - " + howlong.ToString()); // 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,
CleanUpClosedItems(); // then create a new child window. All other procedures from that same set will open in this child window.
if (myItemInfo == null) return null; // _AllDTCs is a dictionary of of all procedure sets opened along with their DisplayTabContol. The key to
// if this is an auto table of contents section, don't edit it: // the dictioan is the set's VersionID
if (myItemInfo.IsAutoTOCSection) if (VersionID != 0)
{ {
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); if (SeparateWindows && !libDocAlreadyOpen)
return SelectedDisplayTabItem; {
} if (!_AllDTCs.ContainsKey(myItemInfo.MyDocVersion.VersionID))
_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 OnOpenInSeparateWindow(new ItemSelectedChangedEventArgs(myItemInfo2)); // create a child (separate) PROMS window
return OpenStepTabPage(myItemInfo,setFocus); return _AllDTCs[myItemInfo.MyDocVersion.VersionID].OpenItem(myItemInfo);
else // Otherwise open it in the Word editor }
return OpenDSOTabPage(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.
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) public bool PasteRTBItem(ItemInfo myItemInfo, int copyStartID, ItemInfo.EAddpingPart pasteType, int type)
{ {
CleanUpClosedItems(); CleanUpClosedItems();
@ -648,7 +741,7 @@ namespace Volian.Controls.Library
{ {
b.CloseDockTab(myTabItem); b.CloseDockTab(myTabItem);
//b.Items.Remove(myTabItem); //b.Items.Remove(myTabItem);
RemoveItem(myTabItem); RemoveItem(myTabItem);
} }
} }
/// <summary> /// <summary>
@ -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.
@ -1030,18 +1156,10 @@ namespace Volian.Controls.Library
private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo) private DisplayTabItem OpenDSOTabPage(ItemInfo myItemInfo)
{ {
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
{ {