Enhanced: Additional context menu items for create missing & unlink; allow insert hls if in enhanced

This commit is contained in:
Kathy Ruffing 2016-05-09 11:33:29 +00:00
parent be3fb618b6
commit d4c0f2098d

View File

@ -139,11 +139,14 @@ namespace Volian.Controls.Library
// have links to enhanced, but should. // have links to enhanced, but should.
List<string> existingEnhancedButtons = new List<string>(); List<string> existingEnhancedButtons = new List<string>();
foreach (DevComponents.DotNetBar.ButtonItem bi in myButtonItem.SubItems) foreach (DevComponents.DotNetBar.ButtonItem bi in myButtonItem.SubItems)
if (bi.Name.StartsWith("btnEnhancedTo")) if (bi.Name.StartsWith("btnEnhanced"))
existingEnhancedButtons.Add(bi.Name); existingEnhancedButtons.Add(bi.Name);
bool inSource = dveds[0].Type != 0; // for later, only 'create missing' enhanced if in Source document bool inSource = dveds[0].Type != 0;
if (dveds.Count > existingEnhancedButtons.Count) // add buttons int buttonsNeeded = inSource ? dveds.Count : (dveds.Count * 2); // enhanced items need unlink button also.
if (MyItemInfo.IsSection && !MyItemInfo.IsStepSection) buttonsNeeded = 0; // no buttons for word sections
if (buttonsNeeded > existingEnhancedButtons.Count) // add buttons
{ {
// may need to change the following to add more buttons if a new working draft level was made
foreach (DVEnhancedDocument dved in dveds) foreach (DVEnhancedDocument dved in dveds)
{ {
string buttonName = string.Format("btnEnhancedTo{0}", dved.Type); string buttonName = string.Format("btnEnhancedTo{0}", dved.Type);
@ -151,75 +154,149 @@ namespace Volian.Controls.Library
biEnhanced.Click += btnEnhancedGoTo_Click; biEnhanced.Click += btnEnhancedGoTo_Click;
myButtonItem.SubItems.Add(biEnhanced); myButtonItem.SubItems.Add(biEnhanced);
existingEnhancedButtons.Add(biEnhanced.Name); existingEnhancedButtons.Add(biEnhanced.Name);
if (!inSource)
{
// add unlink buttons:
buttonName = string.Format("btnEnhancedUnlink{0}", dved.Type);
biEnhanced = new DevComponents.DotNetBar.ButtonItem(buttonName, "Unlink " + dved.Name + " Document");
biEnhanced.Click += btnEnhancedGoTo_Click;
myButtonItem.SubItems.Add(biEnhanced);
existingEnhancedButtons.Add(biEnhanced.Name);
}
} }
} }
// Now handle specific cases for the Item that user is positioned on. // Now handle specific cases for the Item that user is positioned on.
// If a link exists, the menu item should be 'go to'. // If a link exists, the menu item should be 'go to' and 'Unlink' if on an enhanced item.
// If link doesn't exist // If link doesn't exist
// if in source & on high, note or caution, the menu item should be 'create missing' // if in source & on procedure, section, high, note or caution, the menu item should be 'create missing'
// else the menu item should be made invisible. // else the menu item should be made invisible.
StepRTB myStepRTB = sender as StepRTB ?? _MyStepRTB; StepRTB myStepRTB = sender as StepRTB ?? _MyStepRTB;
StepConfig sc = new StepConfig(myStepRTB.MyItemInfo.MyContent.Config); EnhancedDocuments eds = myStepRTB.MyItemInfo.GetMyEnhancedDocuments();
foreach (string btnenh in existingEnhancedButtons) foreach (string btnenh in existingEnhancedButtons)
{ {
DevComponents.DotNetBar.ButtonItem biEnhanced = myButtonItem.SubItems[btnenh] as DevComponents.DotNetBar.ButtonItem; DevComponents.DotNetBar.ButtonItem biEnhanced = myButtonItem.SubItems[btnenh] as DevComponents.DotNetBar.ButtonItem;
int edtypebtn = System.Convert.ToInt32(biEnhanced.Name.Substring(biEnhanced.Name.Length - 1)); int edtypebtn = System.Convert.ToInt32(biEnhanced.Name.Substring(biEnhanced.Name.Length - 1));
bool itemHasLink = false; bool itemHasLink = false;
foreach (EnhancedDocument ed in sc.MyEnhancedDocuments) if (myStepRTB.MyItemInfo.MyContent.Text == "") // empty text represents a newly inserted step - don't do any enhanced buttons until saved (moved off)
biEnhanced.Visible = false;
else
{ {
if (edtypebtn == ed.Type) // this button is for this document: foreach (EnhancedDocument ed in eds)
{ {
biEnhanced.Visible = true; if (edtypebtn == ed.Type) // this button is for this document:
biEnhanced.Text = "Go To " + dveds.GetByType(ed.Type).Name + " Document";
biEnhanced.Tag = ed.ItemID;
itemHasLink = true;
break;
}
}
if (!itemHasLink)
{
// don't put up 'create missing' if the enhanced procedure does not have a section for this step:
ItemInfo sectInfo = MyItemInfo.ActiveSection;
SectionConfig sectConfig = sectInfo.MyConfig as SectionConfig;
bool hasEnhSect = false;
foreach (EnhancedDocument edsect in sectConfig.MyEnhancedDocuments)
{
if (edsect.Type == edtypebtn)
{ {
hasEnhSect = true; if (biEnhanced.Name.StartsWith("btnEnhancedTo"))
break; {
biEnhanced.Visible = true;
biEnhanced.Text = "Go To " + dveds.GetByType(ed.Type).Name + " Document";
biEnhanced.Tag = ed.ItemID;
itemHasLink = true;
break;
}
else // this is for 'unlink'
{
biEnhanced.Visible = true;
biEnhanced.Tag = ed.ItemID;
itemHasLink = true;
break;
}
} }
} }
if (inSource && hasEnhSect && (MyItemInfo.IsHigh || ((MyItemInfo.IsCaution || MyItemInfo.IsNote) && MyItemInfo.MyHLS.GetMyEnhancedDocuments().Count > 0))) // if there is no link & item is in the 'source document', allow the user to create missing
// enhanced items
if (!itemHasLink && inSource)
{ {
biEnhanced.Visible = true; // need to handle procedures, sections and steps differently:
biEnhanced.Text = string.Format("Create Missing Enhanced {0} Document Step", dveds.GetByType(edtypebtn).Name); if (MyItemInfo.IsProcedure)
biEnhanced.Tag = MyItemInfo.ItemID; {
biEnhanced.Visible = true;
biEnhanced.Text = string.Format("Create Missing Enhanced {0} Document Procedure", dveds.GetByType(edtypebtn).Name);
biEnhanced.Tag = MyItemInfo.ItemID;
}
else if (MyItemInfo.IsSection)
{
// verify that procedure has enhanced procedure for this type
EnhancedDocuments peds = MyItemInfo.MyProcedure.GetMyEnhancedDocuments();
bool didMenuItem = false;
foreach (EnhancedDocument ped in peds)
{
if (edtypebtn == ped.Type && MyItemInfo.IsStepSection) // this button is for this document:
{
biEnhanced.Visible = true;
biEnhanced.Text = string.Format("Create Missing Enhanced {0} Document Section", dveds.GetByType(edtypebtn).Name);
biEnhanced.Tag = MyItemInfo.ItemID;
didMenuItem = true;
break;
}
}
if (!didMenuItem) biEnhanced.Visible = false;
}
else if (MyItemInfo.IsHigh || MyItemInfo.IsCaution || MyItemInfo.IsNote)
{
EnhancedDocuments seds = MyItemInfo.ActiveSection.GetMyEnhancedDocuments();
bool didMenuItem = false;
foreach (EnhancedDocument sed in seds)
{
if (sed.Type == edtypebtn)
{
if (MyItemInfo.IsHigh || ((MyItemInfo.IsCaution || MyItemInfo.IsNote) && MyItemInfo.MyHLS.GetMyEnhancedDocuments().Count > 0))
{
biEnhanced.Visible = true;
biEnhanced.Text = string.Format("Create Missing Enhanced {0} Document Step", dveds.GetByType(edtypebtn).Name);
biEnhanced.Tag = MyItemInfo.ItemID;
didMenuItem = true;
break;
}
}
}
if (!didMenuItem) biEnhanced.Visible = false;
}
else
biEnhanced.Visible = false;
} }
else else if (!itemHasLink && !inSource)
biEnhanced.Visible = false; biEnhanced.Visible = false;
} }
} }
#endregion #endregion
} }
public ItemInfo enhUseExist = null;
void btnEnhancedGoTo_Click(object sender, EventArgs e) void btnEnhancedGoTo_Click(object sender, EventArgs e)
{ {
DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem; DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem;
ItemInfo ii = ItemInfo.Get(int.Parse(btn.Tag.ToString())); ItemInfo ii = ItemInfo.Get(int.Parse(btn.Tag.ToString()));
if (ii.ItemID != MyItemInfo.ItemID) if (ii.ItemID != MyItemInfo.ItemID)
{ {
//StepTabPanel tmp = Parent as StepTabPanel; // if button name starts with btnEnhancedTo... open it, otherwise, unlink:
//tmp.MyDisplayTabControl.OpenItem(ii); if (btn.Name.StartsWith("btnEnhancedTo"))
// OpenEnhancedDocument(this, new StepTabRibbonEventArgs(ii)); {
MyEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnOpenEnhancedDocument(new ItemSelectedChangedEventArgs(ii)); MyEditItem.SaveContents();
MyEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnOpenEnhancedDocument(new ItemSelectedChangedEventArgs(ii)); // is this creating ONE?
}
else if (btn.Name.Contains("Unlink"))
MyEditItem.UnlinkEnhanced(MyEditItem.MyItemInfo);
} }
else else
{ {
// have to create it. // have to create it. This will bring up a dialog to either create a new step or
int edtype = System.Convert.ToInt32(btn.Name.Replace("btnEnhancedTo", "")); // link to an existing step:
MyEditItem.AddMissingEnhancedStep(ii, edtype); enhUseExist = null;
int enhtype = System.Convert.ToInt32(btn.Name.Replace("btnEnhancedTo", ""));
dlgEnhMissingItem enhMissDlg = new dlgEnhMissingItem(this, ii, enhtype);
DialogResult dr = enhMissDlg.ShowDialog(this.Parent);
if (dr == DialogResult.OK)
{
if (enhUseExist == null)
{
ItemInfo newEnh = MyEditItem.AddMissingEnhancedStep(ii, enhtype);
if (ii.IsProcedure && newEnh != null) OnAddProcToDVInTree(new StepTabRibbonEventArgs(newEnh));
}
else
MyEditItem.CreateLinksEnhancedSteps(ii, enhUseExist, enhtype);
MyEditItem.SetFocus();
}
} }
} }
@ -790,6 +867,12 @@ namespace Volian.Controls.Library
if (ContActionSummaryRequest != null) if (ContActionSummaryRequest != null)
ContActionSummaryRequest(this, args); ContActionSummaryRequest(this, args);
} }
public event StepTabRibbonEvent AddProcToDVInTree;
private void OnAddProcToDVInTree(StepTabRibbonEventArgs args)
{
if (AddProcToDVInTree != null)
AddProcToDVInTree(this, args);
}
void _MyStepRTB_LinkChanged(object sender, StepPanelLinkEventArgs args) void _MyStepRTB_LinkChanged(object sender, StepPanelLinkEventArgs args)
{ {
// do all Transition and ReferencedObject menu items/buttons based on whether a 'link is selected' and the link type. // do all Transition and ReferencedObject menu items/buttons based on whether a 'link is selected' and the link type.
@ -1385,7 +1468,8 @@ namespace Volian.Controls.Library
// disable buttons. Info panels for ROs and Transitions are made invisible in frmVEPROMS.cs // disable buttons. Info panels for ROs and Transitions are made invisible in frmVEPROMS.cs
btnInsTrans.Enabled = btnCMTransition.Enabled = btnInsRO.Enabled = btnCMRO.Enabled = false; btnInsTrans.Enabled = btnCMTransition.Enabled = btnInsRO.Enabled = btnCMRO.Enabled = false;
btnInsAftH.Enabled = btnInsBefH.Enabled = false; btnInsAftH.Enabled = btnInsBefH.Enabled = false;
btnInsHLS.Enabled = (!MyItemInfo.IsStepSection || (MyItemInfo.IsStepSection && MyItemInfo.IsEnhancedSection)) ? false : true; // allow hls from step section //btnInsHLS.Enabled = (!MyItemInfo.IsStepSection || (MyItemInfo.IsStepSection && MyItemInfo.IsEnhancedSection)) ? false : true; // allow hls from step section
btnInsHLS.Enabled = !MyItemInfo.IsStepSection ? false : true; // allow hls from step section
// if active item is a section and format has metasections, check that a hls can be added. // if active item is a section and format has metasections, check that a hls can be added.
if (MyItemInfo.IsStepSection) if (MyItemInfo.IsStepSection)
{ {
@ -1413,7 +1497,8 @@ namespace Volian.Controls.Library
StepData sd = MyItemInfo.FormatStepData; StepData sd = MyItemInfo.FormatStepData;
actable = sd.StepEditData.AcTable; actable = sd.StepEditData.AcTable;
if (actable == null) actable = 0; if (actable == null) actable = 0;
btnInsHLS.Enabled = !MyItemInfo.IsEnhancedStep && MyItemInfo.MyHLS != null && !MyItemInfo.MyHLS.IsEnhancedStep; // (actable & E_AccStep.EnhancedLinkedStep) == 0; //btnInsHLS.Enabled = !MyItemInfo.IsEnhancedStep && MyItemInfo.MyHLS != null && !MyItemInfo.MyHLS.IsEnhancedStep; // (actable & E_AccStep.EnhancedLinkedStep) == 0;
btnInsHLS.Enabled = MyItemInfo.MyHLS != null; // (actable & E_AccStep.EnhancedLinkedStep) == 0;
btnInsCaut.Enabled = ((actable & E_AccStep.AddingCaution) > 0) && !MyItemInfo.IsEnhancedStep; // ((actable & E_AccStep.AddingCaution) > 0) && ((actable & E_AccStep.EnhancedLinkedStep) == 0); btnInsCaut.Enabled = ((actable & E_AccStep.AddingCaution) > 0) && !MyItemInfo.IsEnhancedStep; // ((actable & E_AccStep.AddingCaution) > 0) && ((actable & E_AccStep.EnhancedLinkedStep) == 0);
btnInsNote.Enabled = ((actable & E_AccStep.AddingNote) > 0) && !MyItemInfo.IsEnhancedStep; btnInsNote.Enabled = ((actable & E_AccStep.AddingNote) > 0) && !MyItemInfo.IsEnhancedStep;