diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.Designer.cs b/PROMS/Volian.Controls.Library/vlnTreeView.Designer.cs index 1428834d..98e486b8 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.Designer.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.Designer.cs @@ -11,7 +11,7 @@ namespace Volian.Controls.Library /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) + protected void Dispose(bool disposing) { if (disposing && (components != null)) { diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs index ee146086..0889706b 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs @@ -19,6 +19,20 @@ namespace Volian.Controls.Library public delegate bool vlnTreeViewBoolEvent(object sender, vlnTreeEventArgs args); public delegate TreeNode vlnTreeViewTreeNodeEvent(object sender, vlnTreeEventArgs args); public delegate DialogResult vlnTreeViewPropertyEvent(object sender, vlnTreePropertyEventArgs args); + public delegate void vlnTreeViewSectionInfoEvent(object sender, vlnTreeSectionInfoEventArgs args); + public partial class vlnTreeSectionInfoEventArgs + { + private SectionInfo _MySectionInfo; + public SectionInfo MySectionInfo + { + get { return _MySectionInfo; } + set { _MySectionInfo = value; } + } + public vlnTreeSectionInfoEventArgs(SectionInfo mySectionInfo) + { + _MySectionInfo = mySectionInfo; + } + } public partial class vlnTreeEventArgs { #region Business Methods @@ -157,6 +171,11 @@ namespace Volian.Controls.Library { if (NodeSelectionChange != null) NodeSelectionChange(sender, args); } + public event vlnTreeViewSectionInfoEvent SectionShouldClose; + private void OnSectionShouldClose(object sender, vlnTreeSectionInfoEventArgs args) + { + if (SectionShouldClose != null) SectionShouldClose(sender, args); + } #endregion #region Constructors public vlnTreeView() @@ -211,7 +230,7 @@ namespace Volian.Controls.Library cm.MenuItems.Add("Insert Folder After", new EventHandler(mi_Click)); } if (fi.FolderDocVersionCount == 0) cm.MenuItems.Add("New Folder", new EventHandler(mi_Click)); - if (fi.ChildFolderCount == 0) cm.MenuItems.Add("New Document Version", new EventHandler(mi_Click)); + if (fi.ChildFolderCount == 0) cm.MenuItems.Add("Create Working Draft", new EventHandler(mi_Click)); } else if (tn.VEObject as DocVersionInfo != null) // DocVersions can only contain procs cm.MenuItems.Add("New Procedure", new EventHandler(mi_Click)); @@ -256,37 +275,56 @@ namespace Volian.Controls.Library cm.MenuItems.Add("Open", new EventHandler(mi_Click)); #endregion #region Menu_CutCopy - // For initial release, cut/copy are not available for folders or docversions - if (tn.VEObject as FolderInfo != null && tn.VEObject as DocVersionInfo != null) + // For initial release, no cut operations will be coded. + // For initial release, copy is not available for folders or docversions + if (tn.VEObject as ItemInfo != null) { - cm.MenuItems.Add("Cut", new EventHandler(mi_Click)); + //cm.MenuItems.Add("Cut", new EventHandler(mi_Click)); cm.MenuItems.Add("Copy", new EventHandler(mi_Click)); } #endregion #region MenuPaste // Find what's in paste buffer & determine whether the paste can occur for the selected node. - //ItemInfo iiClipboard = Clipboard.GetData("ItemInfo") as ItemInfo; - //if (iiClipboard != null) - //{ - // // can it be pasted at current node. - // if (tn.VEObject as DocVersionInfo != null) // paste item must be a proc - // { - // if (iiClipboard.IsProcedure) cm.MenuItems.Add("Paste Procedure", new EventHandler(mi_Click)); - // } - // else - // { - // ItemInfo iiPasteHere = tn.VEObject as ItemInfo; - // if (iiPasteHere != null) - // { - // if (iiPasteHere.IsProcedure && iiClipboard.IsSection) // procedure must have sections only - // cm.MenuItems.Add("Paste Section", new EventHandler(mi_Click)); - // else if (iiPasteHere.IsSection && iiClipboard.IsSection) - // cm.MenuItems.Add("Paste Section", new EventHandler(mi_Click)); - // else if (iiPasteHere.IsStepSection && iiClipboard.IsStep) - // cm.MenuItems.Add("Paste Step", new EventHandler(mi_Click)); - // } - // } - //} + object tmpClip = Clipboard.GetData("PromsClipboard"); + if (tmpClip != null) + { + PromsClipboard tstClip = (PromsClipboard)tmpClip; + ItemInfo iiClipboard = ItemInfo.Get(tstClip.itemId); + // can it be pasted at current node. + if (tn.VEObject as DocVersionInfo != null) // paste item must be a proc + { + if (iiClipboard.IsProcedure) cm.MenuItems.Add("Paste Procedure", new EventHandler(mi_Click)); + } + else + { + ItemInfo iiPasteHere = tn.VEObject as ItemInfo; + if (iiPasteHere != null) + { + if (iiPasteHere.IsProcedure && iiClipboard.IsProcedure) // procedure can be pasted before/replace/after + { + cm.MenuItems.Add("Paste Procedure Before", new EventHandler(mi_Click)); + cm.MenuItems.Add("Replace Existing Procedure", new EventHandler(mi_Click)); + cm.MenuItems.Add("Paste Procedure After", new EventHandler(mi_Click)); + } + else if (iiPasteHere.IsProcedure && iiClipboard.IsSection) // procedure must have sections only + cm.MenuItems.Add("Paste Section", new EventHandler(mi_Click)); + else if (iiPasteHere.IsSection && iiClipboard.IsSection) + { + cm.MenuItems.Add("Paste Section Before", new EventHandler(mi_Click)); + cm.MenuItems.Add("Replace Existing Section", new EventHandler(mi_Click)); + cm.MenuItems.Add("Paste Section After", new EventHandler(mi_Click)); + } + else if (iiPasteHere.IsStepSection && iiClipboard.IsStep) + cm.MenuItems.Add("Paste Step", new EventHandler(mi_Click)); + else if (iiPasteHere.IsStep && iiClipboard.IsStep) + { + cm.MenuItems.Add("Paste Step Before", new EventHandler(mi_Click)); + cm.MenuItems.Add("Replace Existing Step", new EventHandler(mi_Click)); + cm.MenuItems.Add("Paste Section Step", new EventHandler(mi_Click)); + } + } + } + } #endregion #region Menu_Delete // Add delete to the menu unless at the very 'top' node. @@ -318,7 +356,7 @@ namespace Volian.Controls.Library case "New Folder": tv_NodeNew(MenuSelections.Folder); break; - case "New Document Version": + case "Create Working Draft": tv_NodeNew(MenuSelections.DocVersion); break; case "New Procedure": @@ -349,15 +387,23 @@ namespace Volian.Controls.Library case "New Step": tv_NodeNew(MenuSelections.Step); break; - case "Cut"://Cut the selected node - // Cut to Clipboard - break; case "Copy"://Copy the selected node - // Add to Clipboard + tv_NodeCopy(); break; - case "Paste"://Paste the clipboard node - // this is either a copy or a move depending upon where it came from - // if it is from a cut then when the paste is done it should be set to a copy + // lots of paste options: + case "Paste Procedure": + case "Paste Procedure Before": + case "Replace Existing Procedure": + case "Paste Procedure After": + case "Paste Section": + case "Paste Section Before": + case "Replace Existing Section": + case "Paste Section After": + case "Paste Step": + case "Paste Step Before": + case "Replace Existing Step": + case "Paste Step After": + tv_NodePaste(mi.Text); break; case "Delete"://Delete the selected node if (tv_NodeDelete()) @@ -377,6 +423,83 @@ namespace Volian.Controls.Library break; } } + + [Serializable] + public struct PromsClipboard + { + public int cType; + public int itemId; + } + public enum PromsClipboardType : int + { + Copy = 1, Cut = 2 + } + private void tv_NodePaste(string p) + { + object oClip = Clipboard.GetData("PromsClipboard"); + if (oClip == null) return; + + PromsClipboard iClip = (PromsClipboard) oClip; + ItemInfo iiClipboard = ItemInfo.Get(iClip.itemId); + VETreeNode tn = SelectedNode as VETreeNode; + DocVersionInfo dvi = tn.VEObject as DocVersionInfo; + if (dvi != null) + { + // TODO: KBR Adjust database. + VETreeNode tnnew = new VETreeNode(iiClipboard); + SelectedNode.Nodes.Add(tnnew); + return; + } + + ItemInfo iiPaste = tn.VEObject as ItemInfo; + if (iiPaste == null) return; + if (p.IndexOf("Before") > -1) + { + // TODO: KBR Adjust database. + VETreeNode tnnew = new VETreeNode(iiClipboard); + int indx = SelectedNode.Index; + SelectedNode.Parent.Nodes.Insert(indx, tnnew); + return; + } + if (p.IndexOf("After") > -1) + { + // TODO: KBR Adjust database. + VETreeNode tnnew = new VETreeNode(iiClipboard); + int indx = SelectedNode.Index; + SelectedNode.Parent.Nodes.Insert(indx+1, tnnew); + return; + } + if (p.IndexOf("Replace") > -1) + { + // TODO: KBR Adjust database. + VETreeNode tnnew = new VETreeNode(iiClipboard); + int indx = SelectedNode.Index; + TreeNode tmptn = SelectedNode; + SelectedNode = SelectedNode.Parent.Nodes[indx]; + SelectedNode.Remove(); + SelectedNode.Parent.Nodes.Insert(indx, tnnew); + return; + } + // if it got to here, just add as a child. + // TODO: KBR Adjust database. + VETreeNode tnnewc = new VETreeNode(iiClipboard); + SelectedNode.Nodes.Add(tnnewc); + } + + private void tv_NodeCopy() + { + if (SelectedNode==null)return; + VETreeNode tn = SelectedNode as VETreeNode; + ItemInfo ii = tn.VEObject as ItemInfo; + if (ii != null) + { + Clipboard.Clear(); + PromsClipboard iClip; + iClip.itemId = ii.ItemID; + iClip.cType = (int)PromsClipboardType.Copy; + Clipboard.SetData("PromsClipboard", iClip); + } + } #endregion #region PropertyPagesInterface private void SetupNodeProperties() @@ -400,28 +523,27 @@ namespace Volian.Controls.Library { using (Folder folder = folderInfo.Get()) { - if(OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(string.Format("{0} Properties", folder.FolderConfig.Name),folder.FolderConfig))==DialogResult.OK) - folder.Save().Dispose(); + OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(string.Format("{0} Properties", folder.FolderConfig.Name), folder.FolderConfig)); } } private void OpenProperties(DocVersionInfo dvInfo) { using (DocVersion dv = dvInfo.Get()) { - if (OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(string.Format("{0} Properties", dv.DocVersionConfig.Name), dv.DocVersionConfig)) == DialogResult.OK) - dv.Save().Dispose(); + OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(string.Format("{0} Properties", dv.DocVersionConfig.Name), dv.DocVersionConfig)); } } private void OpenProperties(ProcedureInfo procInfo) { using (Procedure proc = procInfo.Get()) { - if (OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(string.Format("{0} {1} Properties", proc.ProcedureConfig.Number, proc.ProcedureConfig.Title), proc.ProcedureConfig)) == DialogResult.OK) - proc.Save().Dispose(); + OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(string.Format("{0} {1} Properties", proc.ProcedureConfig.Number, proc.ProcedureConfig.Title), proc.ProcedureConfig)); } } private void OpenProperties(SectionInfo sectInfo) { + OnSectionShouldClose(this, new vlnTreeSectionInfoEventArgs(sectInfo)); + using (Section sect = sectInfo.Get()) { string title = null; @@ -429,9 +551,8 @@ namespace Volian.Controls.Library title = string.Format("{0} {1} Properties", sectInfo.SectionConfig.Number, sectInfo.SectionConfig.Title); else title = string.Format("{0} Properties", sectInfo.SectionConfig.Title); - if (OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(title, sect.SectionConfig)) == DialogResult.OK) - sect.Save().Dispose(); - sect.MyContent.Dispose(); // Force Dispose of related content + + OnNodeOpenProperty(this, new vlnTreePropertyEventArgs(title, sect.SectionConfig)); } } #endregion @@ -477,11 +598,11 @@ namespace Volian.Controls.Library { if (newtype == MenuSelections.DocVersion) { - using (DocVersion docversion = DocVersion.MakeDocVersion(parentfolder, "New Document Version", "Title", null, null, null)) + using (DocVersion docversion = DocVersion.MakeDocVersion(parentfolder, "Working Draft", "Title", null, null, null)) { ShowBrokenRules(docversion.BrokenRulesCollection); SetLastValues(DocVersionInfo.Get(docversion.VersionID)); - if (OnNodeOpenProperty(this, new vlnTreePropertyEventArgs("New Document Version", docversion.DocVersionConfig)) == DialogResult.OK) + if (OnNodeOpenProperty(this, new vlnTreePropertyEventArgs("Working Draft", docversion.DocVersionConfig)) == DialogResult.OK) docversion.Save().Dispose(); tn = new VETreeNode(_LastDocVersionInfo); SelectedNode.Nodes.Add(tn); // add tree node to end of list.