From 37a481db247a799e6244fc58d37062bc784c57df Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 6 Aug 2014 00:56:13 +0000 Subject: [PATCH] Added new events NodeCopy and ClipboardStatus, changed paste operations to use MyCopyStep property of tab control instead of clipboard and changed method to determine when paste replace menu item is available --- PROMS/Volian.Controls.Library/vlnTreeView.cs | 66 ++++++++------------ 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs index a597a112..0fe12659 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs @@ -18,7 +18,8 @@ namespace Volian.Controls.Library { #region DelegatesAndEventArgs public delegate void vlnTreeViewEvent(object sender, vlnTreeEventArgs args); - public delegate void vlnTreeViewItemInfoEvent(object sender, vlnTreeItemInfoEventArgs args); + public delegate ItemInfo vlnTreeViewClipboardStatusEvent(object sender, vlnTreeEventArgs args); + public delegate void vlnTreeViewItemInfoEvent(object sender, vlnTreeItemInfoEventArgs args); public delegate bool vlnTreeViewBoolEvent(object sender, vlnTreeEventArgs args); public delegate bool vlnTreeViewItemInfoDeleteEvent(object sender, vlnTreeItemInfoEventArgs args); public delegate bool vlnTreeViewItemInfoInsertEvent(object sender, vlnTreeItemInfoInsertEventArgs args); @@ -363,6 +364,13 @@ namespace Volian.Controls.Library { if (NodeMove != null) NodeMove(sender, args); } + public event vlnTreeViewClipboardStatusEvent ClipboardStatus; + private ItemInfo OnClipboardStatus(object sender, vlnTreeEventArgs args) + { + ItemInfo rv = null; + if (ClipboardStatus != null) rv = ClipboardStatus(sender, args); + return rv; + } public event vlnTreeViewEvent NodeCopy; private void OnNodeCopy(object sender, vlnTreeEventArgs args) { @@ -1048,18 +1056,9 @@ namespace Volian.Controls.Library { #region MenuPaste // Find what's in paste buffer & determine whether the paste can occur for the selected node. - object tmpClip = Clipboard.GetData("PromsClipboard"); - if (tmpClip != null) - { - PromsClipboard tstClip = (PromsClipboard)tmpClip; - ItemInfo iiClipboard = ItemInfo.Get(tstClip.itemId); - // if the item doesn't exist anymore, don't allow the paste, by not adding - // paste menu items to context menu. - if (iiClipboard == null) - { - Clipboard.Clear(); - return; - } + ItemInfo iiClipboard = OnClipboardStatus(this,new vlnTreeEventArgs(tn)); + if(iiClipboard != null) + { // can it be pasted at current node. if (tn.VEObject as DocVersionInfo != null) // paste item must be a proc { @@ -1068,12 +1067,13 @@ namespace Volian.Controls.Library else { ItemInfo iiPasteHere = tn.VEObject as ItemInfo; + bool okToReplace = iiClipboard.ItemID != iiPasteHere.ItemID; 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)); + if (okToReplace) 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 @@ -1081,7 +1081,7 @@ namespace Volian.Controls.Library 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)); + if (okToReplace) 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) @@ -1089,7 +1089,7 @@ namespace Volian.Controls.Library else if (iiPasteHere.IsStep && iiClipboard.IsStep) { if (AddToInsertMenu(iiPasteHere, 0)) cm.MenuItems.Add("Paste Step Before", new EventHandler(mi_Click)); - cm.MenuItems.Add("Replace Existing Step", new EventHandler(mi_Click)); + if (okToReplace) cm.MenuItems.Add("Replace Existing Step", new EventHandler(mi_Click)); if (AddToInsertMenu(iiPasteHere, 1)) cm.MenuItems.Add("Paste Step After", new EventHandler(mi_Click)); } } @@ -1439,11 +1439,8 @@ namespace Volian.Controls.Library } 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); + ItemInfo iiClipboard = OnClipboardStatus(this, null); + if (iiClipboard == null) return; string message = string.Empty; if (iiClipboard.MyContent.MyEntry == null) { @@ -1470,12 +1467,12 @@ namespace Volian.Controls.Library ItemInfo iiPaste = tn.VEObject as ItemInfo; if (iiPaste == null) return; - if (p.IndexOf("Before") > -1) - PasteBeforeOrAfter(MenuSelections.StepBefore, tn, iiClipboard.ItemID); - else if (p.IndexOf("After") > -1) - PasteBeforeOrAfter(MenuSelections.StepAfter, tn, iiClipboard.ItemID); - else if (p.IndexOf("Replace") > -1) - PasteReplace(tn, iiClipboard.ItemID); + if (p.IndexOf("Before") > -1) + PasteBeforeOrAfter(MenuSelections.StepBefore, tn, iiClipboard.ItemID); + else if (p.IndexOf("After") > -1) + PasteBeforeOrAfter(MenuSelections.StepAfter, tn, iiClipboard.ItemID); + else if (p.IndexOf("Replace") > -1) + PasteReplace(tn, iiClipboard.ItemID); } private void PasteBeforeOrAfter(MenuSelections newtype, VETreeNode tn, int copyStartID) { @@ -1512,20 +1509,7 @@ namespace Volian.Controls.Library { 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; - DataObject myDO = new DataObject(); - myDO.SetText(ii.DisplayNumber==null||ii.DisplayNumber==""?" ":ii.DisplayNumber); - myDO.SetData("PromsClipboard", iClip); - Clipboard.SetDataObject(myDO); - //Clipboard.SetData("PromsClipboard", iClip); - //Clipboard.SetData(DataFormats.Text, ii.DisplayNumber); - } + OnNodeCopy(this, new vlnTreeEventArgs(tn)); } #endregion #region PropertyPagesInterface