From e6ad27120c50f27940302aca36d0650fa6c1d076 Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 14 Apr 2016 12:45:33 +0000 Subject: [PATCH] C2016008: Create an enhanced step if it is missing from source (menuing) & Enable delete of unlinked enhanced step --- .../Volian.Controls.Library/StepTabRibbon.cs | 123 ++++++++++++------ 1 file changed, 84 insertions(+), 39 deletions(-) diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index b461f8b8..ad292adb 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -129,59 +129,86 @@ namespace Volian.Controls.Library private void AddEnhancedDocumentMenu(DevComponents.DotNetBar.ButtonItem myButtonItem, object sender) { - // get a list of all of the current enhanced buttons that been defined for context menu - List unusedEnhancedButtons = new List(); + DVEnhancedDocuments dveds = MyItemInfo.MyDocVersion.DocVersionConfig.MyEnhancedDocuments; + if (dveds.Count == 0) return; // No enhanced! + + // for all enhanced documents, create the list of buttons as they should be for items in the docversion + // using the list of enhanced documents that are on the docversion. Note that later, some may be + // made invisible or menu text changed. + // first, get correct number of enhanced buttons. This is needed in case the selected item doesn't + // have links to enhanced, but should. + List existingEnhancedButtons = new List(); foreach (DevComponents.DotNetBar.ButtonItem bi in myButtonItem.SubItems) if (bi.Name.StartsWith("btnEnhancedTo")) - unusedEnhancedButtons.Add(bi.Name); + existingEnhancedButtons.Add(bi.Name); + bool inSource = dveds[0].Type != 0; // for later, only 'create missing' enhanced if in Source document + if (dveds.Count > existingEnhancedButtons.Count) // add buttons + { + foreach (DVEnhancedDocument dved in dveds) + { + string buttonName = string.Format("btnEnhancedTo{0}", dved.Type); + DevComponents.DotNetBar.ButtonItem biEnhanced = new DevComponents.DotNetBar.ButtonItem(buttonName, "Go To " + dved.Name + " Document"); + biEnhanced.Click += btnEnhancedGoTo_Click; + myButtonItem.SubItems.Add(biEnhanced); + existingEnhancedButtons.Add(biEnhanced.Name); + } + } - // for all enhanced documents, get the list of buttons as they should be for the - // selected step + // Now handle specific cases for the Item that user is positioned on. + // If a link exists, the menu item should be 'go to'. + // If link doesn't exist + // if in source & on high, note or caution, the menu item should be 'create missing' + // else the menu item should be made invisible. StepRTB myStepRTB = sender as StepRTB ?? _MyStepRTB; StepConfig sc = new StepConfig(myStepRTB.MyItemInfo.MyContent.Config); - DVEnhancedDocuments dveds = MyItemInfo.MyDocVersion.DocVersionConfig.MyEnhancedDocuments; - foreach(EnhancedDocument ed in sc.MyEnhancedDocuments) + foreach (string btnenh in existingEnhancedButtons) { - string buttonName = string.Format("btnEnhancedTo{0}", dveds.GetByType(ed.Type)); - //string buttonName = string.Format("btnEnhancedTo{0}", dveds[ed.Type]); - if (unusedEnhancedButtons.Contains(buttonName)) unusedEnhancedButtons.Remove(buttonName); - DevComponents.DotNetBar.ButtonItem biEnhanced; - if (!myButtonItem.SubItems.Contains(buttonName)) + DevComponents.DotNetBar.ButtonItem biEnhanced = myButtonItem.SubItems[btnenh] as DevComponents.DotNetBar.ButtonItem; + int edtypebtn = System.Convert.ToInt32(biEnhanced.Name.Substring(biEnhanced.Name.Length - 1)); + bool itemHasLink = false; + foreach (EnhancedDocument ed in sc.MyEnhancedDocuments) { - //biEnhanced = new DevComponents.DotNetBar.ButtonItem(buttonName, "Go To " + dveds[ed.Type].Name + " Document"); - biEnhanced = new DevComponents.DotNetBar.ButtonItem(buttonName, "Go To " + dveds.GetByType(ed.Type).Name + " Document"); - biEnhanced.Click += btnSourceToBackground_Click; - myButtonItem.SubItems.Add(biEnhanced); + if (edtypebtn == ed.Type) // this button is for this document: + { + biEnhanced.Visible = true; + biEnhanced.Text = "Go To " + dveds.GetByType(ed.Type).Name + " Document"; + biEnhanced.Tag = ed.ItemID; + itemHasLink = true; + break; + } + } + if (!itemHasLink) + { + if (inSource && (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; + } + else + biEnhanced.Visible = false; } - else - biEnhanced = myButtonItem.SubItems[buttonName] as DevComponents.DotNetBar.ButtonItem; - biEnhanced.Tag = ed.ItemID; - biEnhanced.Visible = true; - } - foreach(string btnNotInUse in unusedEnhancedButtons) - { - DevComponents.DotNetBar.ButtonItem biUnused = myButtonItem.SubItems[btnNotInUse] as DevComponents.DotNetBar.ButtonItem; - biUnused.Visible = false; } #endregion } - void btnBackgroundToSource_Click(object sender, EventArgs e) + void btnEnhancedGoTo_Click(object sender, EventArgs e) { DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem; ItemInfo ii = ItemInfo.Get(int.Parse(btn.Tag.ToString())); - StepTabPanel tmp = Parent as StepTabPanel; - tmp.MyDisplayTabControl.OpenItem(ii); - } - - void btnSourceToBackground_Click(object sender, EventArgs e) - { - DevComponents.DotNetBar.BaseItem btn = sender as DevComponents.DotNetBar.BaseItem; - ItemInfo ii = ItemInfo.Get(int.Parse(btn.Tag.ToString())); - //StepTabPanel tmp = Parent as StepTabPanel; - //tmp.MyDisplayTabControl.OpenItem(ii); -// OpenEnhancedDocument(this, new StepTabRibbonEventArgs(ii)); - MyEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnOpenEnhancedDocument(new ItemSelectedChangedEventArgs(ii)); + if (ii.ItemID != MyItemInfo.ItemID) + { + //StepTabPanel tmp = Parent as StepTabPanel; + //tmp.MyDisplayTabControl.OpenItem(ii); + // OpenEnhancedDocument(this, new StepTabRibbonEventArgs(ii)); + MyEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnOpenEnhancedDocument(new ItemSelectedChangedEventArgs(ii)); + } + else + { + // have to create it. + int edtype = System.Convert.ToInt32(btn.Name.Replace("btnEnhancedTo", "")); + MyEditItem.AddMissingEnhancedStep(ii, edtype); + } } #region set up save ro menu jcb 20121221 @@ -1085,10 +1112,28 @@ namespace Volian.Controls.Library btnPaste.Enabled = btnCut.Enabled = setting; btnUndo.Enabled = btnRedo.Enabled = setting; rbFont.Enabled = rbStepType.Enabled = setting; - rbSteps.Enabled = setting; + // if disabling the step buttons, first check if the step has 'linked' config data. If it does not, + // it can be deleted: + bool allowDel = false; + EnhancedDocuments eds = MyItemInfo.GetMyEnhancedDocuments(); + if (!setting && MyItemInfo.IsStep && (eds == null || eds.Count == 0)) + { + allowDel = true; + rbSteps.Enabled = true; //just in case it was disabled, enable it so specific buttons can be turned off/on + btnDelelete.Enabled = true; + itemContainer1.Enabled = false; + btnCpyStp.Enabled = false; + btnStepPaste.Enabled = false; + } + else + { + itemContainer1.Enabled = true; // enable this back on, in case it was turned off above. Other buttons are specifically set for step that is selected. + rbSteps.Enabled = setting; + } rbnCharacters.Enabled = rbnParagraph.Enabled = rbnSiblings.Enabled = rbnLinks.Enabled = setting; btnCMEdit.Enabled = setting; btnDelStep.Enabled = setting; // context menu item + if (allowDel) btnDelStep.Enabled = true; // enhanced step with no links can be deleted (see above) btnPageBreak.Enabled = setting; // context menu item btnCMHardSpace.Enabled = btnCMTransition.Enabled = btnCMRO.Enabled = btnCMSymbol.Enabled = setting; btnFindRplDlg.Enabled = setting; // no find replace button is available when in an enhanced document