B2022-049: Copy/paste of enhanced procedure and bad links between source and enhanced
This commit is contained in:
@@ -1686,7 +1686,9 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
public void UnlinkEnhanced(ItemInfo enhII)
|
||||
{
|
||||
enhII.DoUnlinkEnhanced(enhII);
|
||||
// B2022-049: Copy/paste of enhanced procedure and bad links between source and enhanced
|
||||
// Pass in to unlink as before this change
|
||||
enhII.DoUnlinkEnhanced(enhII, 0, false);
|
||||
SetFocus();
|
||||
}
|
||||
public ItemInfo AddMissingEnhancedStep(ItemInfo ii, int EnhType)
|
||||
|
@@ -183,7 +183,9 @@ namespace Volian.Controls.Library
|
||||
if (bi.Name.StartsWith("btnEnhanced"))
|
||||
existingEnhancedButtons.Add(bi.Name);
|
||||
bool inSource = dveds[0].Type != 0;
|
||||
int buttonsNeeded = inSource ? dveds.Count : (dveds.Count * 2); // enhanced items need unlink button also.
|
||||
int buttonsNeeded = inSource ? dveds.Count : (dveds.Count * 2); // enhanced items need unlink button also.
|
||||
// if in view only mode, don't do unlink
|
||||
if (!inSource && MyEditItem != null && MyEditItem.MyStepPanel.VwMode == E_ViewMode.View) buttonsNeeded--;
|
||||
if (MyItemInfo.IsSection && !MyItemInfo.IsStepSection) buttonsNeeded = 0; // no buttons for word sections
|
||||
if (buttonsNeeded > existingEnhancedButtons.Count) // add buttons
|
||||
{
|
||||
@@ -195,7 +197,8 @@ namespace Volian.Controls.Library
|
||||
biEnhanced.Click += btnEnhancedGoTo_Click;
|
||||
myButtonItem.SubItems.Add(biEnhanced);
|
||||
existingEnhancedButtons.Add(biEnhanced.Name);
|
||||
if (!inSource)
|
||||
// if in view only mode, don't do unlink
|
||||
if (!inSource && MyEditItem != null && MyEditItem.MyStepPanel.VwMode != E_ViewMode.View)
|
||||
{
|
||||
// add unlink buttons:
|
||||
buttonName = string.Format("btnEnhancedUnlink{0}", dved.Type);
|
||||
|
@@ -1024,6 +1024,54 @@ namespace Volian.Controls.Library
|
||||
cm.MenuItems.Add("Incoming Transitions", new EventHandler(mi_Click));
|
||||
}
|
||||
#endregion
|
||||
#region Menu_UnLinkEnhanced
|
||||
// B2022-049: provide for way to unlink a procedure from the tree view. Also unlinks procedure if no
|
||||
// connected (linked) procedure.
|
||||
if (tn.VEObject is ProcedureInfo)
|
||||
{
|
||||
ItemInfo prc = (ItemInfo)tn.VEObject;
|
||||
if (ui.IsAdministrator() || ui.IsSetAdministrator(prc.MyDocVersion) || ui.IsWriter(prc.MyDocVersion))
|
||||
{
|
||||
DVEnhancedDocuments dveds = prc.MyDocVersion.DocVersionConfig.MyEnhancedDocuments;
|
||||
EnhancedDocuments eds = prc.GetMyEnhancedDocuments();
|
||||
|
||||
// if just one link, add single menu item to unlink. If more than one, need a list with all.
|
||||
if (eds != null && eds.Count == 1)
|
||||
{
|
||||
// Get menu string, must start with 'Unlink Source '
|
||||
string doclink = null;
|
||||
doclink = dveds.GetByType(eds[0].Type).Name; // need background/dev if on source
|
||||
if (eds[0].Type == 0)
|
||||
{
|
||||
ItemInfo prl = ItemInfo.Get(eds[0].ItemID);
|
||||
DVEnhancedDocuments dvedsl = prl.MyDocVersion.DocVersionConfig.MyEnhancedDocuments;
|
||||
foreach (DVEnhancedDocument dvel in dvedsl) if (dvel.VersionID == prc.MyDocVersion.VersionID) doclink = dvel.Name;
|
||||
}
|
||||
doclink = string.Format("Unlink Source and {0} Procedure", doclink);
|
||||
MenuItem mix = cm.MenuItems.Add(doclink, new EventHandler(miEnhanced_Click));
|
||||
mix.Tag = -1; // NOTE this is what flags what gets processed on menu click, i.e. -1
|
||||
}
|
||||
// if this is a source procedure that has enhanced, for example Background and/or deviation, ask which should be unlinked including all
|
||||
else if (eds != null && eds.Count > 1)
|
||||
{
|
||||
MenuItem miu = new MenuItem("Unlink Enhanced Procedure(s) from Source");
|
||||
miu.Tag = -2; // this menu item doesn't get used.
|
||||
int k = 0;
|
||||
foreach (EnhancedDocument ed in eds)
|
||||
{
|
||||
// add submenu item for it
|
||||
k++;
|
||||
MenuItem mp = miu.MenuItems.Add(dveds.GetByType(ed.Type).Name, new EventHandler(miEnhanced_Click));
|
||||
mp.Tag = k;
|
||||
}
|
||||
// add all submenu item
|
||||
MenuItem mp1 = miu.MenuItems.Add("All", new EventHandler(miEnhanced_Click));
|
||||
mp1.Tag = 0; // Tag of 0 flags All
|
||||
cm.MenuItems.Add(miu);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Menu_Properties
|
||||
// Add Properties to the menu unless at the very 'top' node or on a grouping (partinfo)
|
||||
// node (RNOs, Steps, Cautions, Notes) or at the step level.
|
||||
@@ -1687,6 +1735,73 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
}
|
||||
//end jcb multiunit
|
||||
private bool CheckForValidEnhLink(ItemInfo prc) // Check if this procedure has valid link
|
||||
{
|
||||
EnhancedDocuments eds = prc.GetMyEnhancedDocuments();
|
||||
foreach (EnhancedDocument ed in eds) // only unlink those that are selected
|
||||
{
|
||||
ItemInfo lprc = ItemInfo.Get(ed.ItemID);
|
||||
EnhancedDocuments edsl = lprc.GetMyEnhancedDocuments();
|
||||
foreach (EnhancedDocument edl in edsl) if (edl.ItemID == prc.ItemID) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// B2022-049: Copy/paste of enhanced procedure and bad links between source and enhanced
|
||||
// Handle menu selection for unlinking the source/enhanced OR if not valid links, just the procedure selected
|
||||
void miEnhanced_Click(object sender, EventArgs e)
|
||||
{
|
||||
MenuItem mi = sender as MenuItem;
|
||||
VETreeNode tnprc = SelectedNode as VETreeNode;
|
||||
ItemInfo selprc = tnprc.VEObject as ItemInfo;
|
||||
EnhancedDocuments seleds = selprc.GetMyEnhancedDocuments();
|
||||
// if tag on menu = -1, it is a single document, no need to loop. This can be from either the source or enhanced.
|
||||
if ((int)mi.Tag == -1)
|
||||
{
|
||||
bool hasValidConnectingProc = CheckForValidEnhLink(selprc);
|
||||
if (FlexibleMessageBox.Show(this, "Do you want to unlink the Enhanced procedure from its Source?", "Confirm Procedure Unlink", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
if (selprc.IsEnhancedProcedure)
|
||||
{
|
||||
selprc.DoUnlinkEnhanced(selprc, 0, !hasValidConnectingProc); // if no valid linked: enhtype = 0 since this an enhanced doc is getting unlinked
|
||||
}
|
||||
else // from source
|
||||
{
|
||||
// if valid connection, make call from the linked enhanced, otherwise just unlink the source only
|
||||
if (hasValidConnectingProc)
|
||||
{
|
||||
ItemInfo lprc = ItemInfo.Get(seleds[0].ItemID);
|
||||
lprc.DoUnlinkEnhanced(lprc, 0, !hasValidConnectingProc);
|
||||
}
|
||||
else
|
||||
selprc.DoUnlinkEnhanced(selprc, seleds[0].Type, !hasValidConnectingProc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The following code is run if selection made from source. There may be moore than one enhanced, for example background
|
||||
// and deviation
|
||||
if (FlexibleMessageBox.Show(this, "Do you want to unlink the selected Enhanced procedure(s) from the Source procedure?", "Confirm Procedure Unlink", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int k = 1;
|
||||
foreach (EnhancedDocument ed in seleds) // only unlink those that are selected
|
||||
{
|
||||
if (k == (int)mi.Tag || (int)mi.Tag == 0)
|
||||
{
|
||||
ItemInfo lprc = ItemInfo.Get(ed.ItemID);
|
||||
bool hasValidConnectingProc = CheckForValidEnhLink(lprc);
|
||||
// if there is a valid connection, unlink both. Otherwise, just unlink this selected procedure.
|
||||
if (hasValidConnectingProc)
|
||||
lprc.DoUnlinkEnhanced(lprc, ed.Type, !hasValidConnectingProc);
|
||||
else
|
||||
selprc.DoUnlinkEnhanced(selprc, ed.Type, !hasValidConnectingProc);
|
||||
}
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void mi_Click(object sender, EventArgs e)
|
||||
{
|
||||
MenuItem mi = sender as MenuItem;
|
||||
|
Reference in New Issue
Block a user