From 834febf19693db4d7b311c0446abf09583eab7c6 Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 28 May 2020 13:21:48 +0000 Subject: [PATCH] B2020-076: Create template steps when insert step from treeview with editor not open (made 2 methods public) --- .../Extension/ItemInsertExt.cs | 6 +- PROMS/Volian.Controls.Library/vlnTreeView.cs | 67 +++++++++++++------ 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index ca2f25ed..18acba93 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -358,7 +358,7 @@ namespace VEPROMS.CSLA.Library ((ItemInfo)ActiveParent).MyContent.RefreshContentParts(); return tmp; } - private ItemInfo InsertSmartTemplateSubStep(string text, string number, ItemInfo tmp, EAddpingPart adPart, int type, E_FromType fromTypeTop) + public ItemInfo InsertSmartTemplateSubStep(string text, string number, ItemInfo tmp, EAddpingPart adPart, int type, E_FromType fromTypeTop) { int newItemID = 0; int topType = GetSmartTemplateTopLevelIndxOfThisType(type); @@ -414,7 +414,7 @@ namespace VEPROMS.CSLA.Library return tmp; } - private ItemInfo InsertSmartTemplateSteps(string text, string number, ItemInfo tmp, EAddpingPart adPart, int type) + public ItemInfo InsertSmartTemplateSteps(string text, string number, ItemInfo tmp, EAddpingPart adPart, int type) { int newItemID = 0; int topType = GetSmartTemplateTopLevelIndx(); @@ -686,7 +686,7 @@ namespace VEPROMS.CSLA.Library } public ItemInfo InsertSiblingAfter(string text, string number, int? type) { - ItemInfo tmp = null; + ItemInfo tmp = null; // KBR need template code in tree view? if (!IsSection && (FormatStepData.UseSmartTemplate || (MyHLS != null && MyHLS.FormatStepData.UseSmartTemplate) || FormatStepData.UseOldTemplate)) tmp = InsertSmartTemplateSteps(text, number, tmp, EAddpingPart.After, (int)((type == null)? MyContent.Type : type)); // B2018-051 use the type passed in instead of current step type if (tmp == null) diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs index 0ccbba63..1d70d27b 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs @@ -2803,20 +2803,32 @@ namespace Volian.Controls.Library } else { - // The parent step was not open in the step editor, just create new step and add treenode. - // this line (below) adds the new step to the bottom of the section, the other line (not commented) adds it to the top. Bug fix B2016-002 - //using (Step step = Step.MakeStep(_LastItemInfo, _LastItemInfo.LastChild(E_FromType.Step), null, "New Step", 20002, E_FromType.Step)) - using (Step step = Step.MakeStep(_LastItemInfo, null , null, "New Step", 20002, E_FromType.Step)) + // The parent step was not open in the step editor, just create new step(s) and add treenode. + int newId = -1; + // B2020-076: if this step has a template, insert template steps. + int topType = ii.GetSmartTemplateTopLevelIndxOfThisType(20002); + if (topType != -1) { - ShowBrokenRules(step.BrokenRulesCollection); - SetLastValues(StepInfo.Get(step.ItemID)); - tn = new VETreeNode(_LastStepInfo); - //SelectedNode.Nodes.Add(tn); // add tree node to end of list. - _LastStepInfo.UpdateTransitionText(); - _LastStepInfo.UpdateROText(); - TreeNode par = SelectedNode; - par.Nodes.Insert(0, tn); + ItemInfo tmp = null; + tmp = ii.InsertSmartTemplateSubStep("New Step", null, null, ItemInfo.EAddpingPart.Child, 20002, E_FromType.Step); + newId = tmp.ItemID; } + else + { + // this line (below) adds the new step to the bottom of the section, the other line (not commented) adds it to the top. Bug fix B2016-002 + //using (Step step = Step.MakeStep(_LastItemInfo, _LastItemInfo.LastChild(E_FromType.Step), null, "New Step", 20002, E_FromType.Step)) + using (Step step = Step.MakeStep(_LastItemInfo, null, null, "New Step", 20002, E_FromType.Step)) + { + ShowBrokenRules(step.BrokenRulesCollection); + newId = step.ItemID; + } + } + SetLastValues(StepInfo.Get(newId)); + tn = new VETreeNode(_LastStepInfo); + _LastStepInfo.UpdateTransitionText(); + _LastStepInfo.UpdateROText(); + TreeNode par = SelectedNode; + par.Nodes.Insert(0, tn); } // see if enhanced related steps need created: @@ -2861,18 +2873,29 @@ namespace Volian.Controls.Library { // The parent step was not open in the step editor, just create new step and add treenode. int tvindex = SelectedNode.Index; - // if inserting before, the parent is set in case previous is null, i.e. beginning of the list. - ItemInfo parent = (newtype == MenuSelections.StepAfter) ? null : _LastStepInfo.MyParent; - using (Step step = Step.MakeStep(parent, (newtype == MenuSelections.StepAfter) ? _LastStepInfo : _LastStepInfo.MyPrevious, null, "New Step", (int)_LastStepInfo.MyContent.Type, (E_FromType)_LastStepInfo.FirstSibling.ItemParts[0].FromType)) + // B2020-076: if this step has a template, insert template steps. + int newid = -1; + if (ii.FormatStepData.UseSmartTemplate || ii.FormatStepData.UseOldTemplate) { - ShowBrokenRules(step.BrokenRulesCollection); - SetLastValues(StepInfo.Get(step.ItemID)); - tn = new VETreeNode(_LastStepInfo); - _LastStepInfo.UpdateTransitionText(); - _LastStepInfo.UpdateROText(); - TreeNode par = SelectedNode.Parent; - par.Nodes.Insert(tvindex + ((newtype == MenuSelections.StepBefore) ? 0 : 1), tn); + ItemInfo tmp = ii.InsertSmartTemplateSteps("New Step", null, null, newtype == MenuSelections.StepAfter ? ItemInfo.EAddpingPart.After : ItemInfo.EAddpingPart.Before, (int)ii.MyContent.Type); + newid = tmp.ItemID; } + else + { + // if inserting before, the parent is set in case previous is null, i.e. beginning of the list. + ItemInfo parent = (newtype == MenuSelections.StepAfter) ? null : _LastStepInfo.MyParent; + using (Step step = Step.MakeStep(parent, (newtype == MenuSelections.StepAfter) ? _LastStepInfo : _LastStepInfo.MyPrevious, null, "New Step", (int)_LastStepInfo.MyContent.Type, (E_FromType)_LastStepInfo.FirstSibling.ItemParts[0].FromType)) + { + ShowBrokenRules(step.BrokenRulesCollection); + newid = step.ItemID; + } + } + SetLastValues(StepInfo.Get(newid)); + tn = new VETreeNode(_LastStepInfo); + _LastStepInfo.UpdateTransitionText(); + _LastStepInfo.UpdateROText(); + TreeNode par = SelectedNode.Parent; + par.Nodes.Insert(tvindex + ((newtype == MenuSelections.StepBefore) ? 0 : 1), tn); } if (tn != null) {