diff --git a/PROMS/Volian.Controls.Library/StepItem.cs b/PROMS/Volian.Controls.Library/StepItem.cs index 1f196edd..81571155 100644 --- a/PROMS/Volian.Controls.Library/StepItem.cs +++ b/PROMS/Volian.Controls.Library/StepItem.cs @@ -1073,6 +1073,7 @@ namespace Volian.Controls.Library if (ans == DialogResult.Yes) { MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(exTrans[0].MyContent.ContentItems[0]); + } else this.MyStepRTB.Focus(); @@ -1339,6 +1340,180 @@ namespace Volian.Controls.Library return child; } #endregion + #region CopyPaste + public void PasteSiblingBefore(int copyStartID) + { + ItemInfo newItemInfo = MyItemInfo.PasteSiblingBefore(copyStartID); + StepItem newStepItem = null; + switch (_MyChildRelation) + { + case ChildRelation.After: + newStepItem = ActiveParent.AddChildAfter(newItemInfo, this); + break; + case ChildRelation.Before: + newStepItem = ActiveParent.AddChildBefore(newItemInfo, this); + break; + case ChildRelation.RNO: + newStepItem = ActiveParent.AddChildRNO(newItemInfo, this); + break; + default: // Need debug + break; + } + _MyStepPanel.SelectedStepRTB = newStepItem.MyStepRTB;//Update Screen + _MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.Before, newItemInfo.MyContent.Type)); + + } + public void PasteSiblingAfter(int copyStartID) + { + ItemInfo newItemInfo = MyItemInfo.PasteSiblingAfter(copyStartID); + StepItem newStepItem = null; + switch (_MyChildRelation) + { + case ChildRelation.After: + newStepItem = ActiveParent.AddChildAfter(newItemInfo, MyNextStepItem); + break; + case ChildRelation.Before: + newStepItem = ActiveParent.AddChildBefore(newItemInfo, MyNextStepItem); + break; + case ChildRelation.RNO: + newStepItem = ActiveParent.AddChildRNO(newItemInfo, MyNextStepItem); + break; + default: // Need debug + break; + } + _MyStepPanel.SelectedStepRTB = newStepItem.MyStepRTB;//Update Screen + _MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.After, newItemInfo.MyContent.Type)); + + } + public StepItem PasteReplace(int copyStartID) + { + MyStepPanel.SelectedStepRTB = null; // Unselect the item to be deleted + ChildRelation childRelation = _MyChildRelation; + StepItem newFocus = null; + StepItem nextStepItem = MyNextStepItem; + StepItem prevStepItem = MyPreviousStepItem; + StepItem parentStepItem = ActiveParent; + + int TopMostYBefore = TopMostStepItem.Top; + int? TopMostParentY = (MyParentStepItem == null ? null : (int?)(MyParentStepItem.TopMostStepItem.Top)); + int? ParentY = (MyParentStepItem == null ? null : (int?)(MyParentStepItem.Top)); + ItemInfo newItemInfo = null; + try + { + newItemInfo = Item.PasteReplace(MyItemInfo, copyStartID); + } + catch (System.Data.SqlClient.SqlException ex) + { + HandleSqlExceptionOnDelete(ex); + return this; + } + // Remove the StepItem that was the replaced item. + RemoveFromParentsChildList(); + + if (MyNextStepItem != null) + { + if (MyPreviousStepItem != null) + { + MyNextStepItem.MyPreviousStepItem = MyPreviousStepItem; + MyPreviousStepItem = null; + } + else + { + MyNextStepItem.MyParentStepItem = MyParentStepItem; + MyParentStepItem = null; + MyNextStepItem.MyPreviousStepItem = null; + } + MyNextStepItem = null; + } + else if (MyPreviousStepItem != null) + { + MyPreviousStepItem.MyNextStepItem = null; + newFocus = MyPreviousStepItem; + MyPreviousStepItem = null; + } + else + { + newFocus = MyParentStepItem; + MyParentStepItem = null; + } + + // add copied item to ui where the replaced item was. + StepItem newStepItem = null; + switch (childRelation) + { + case ChildRelation.After: + newStepItem = parentStepItem.AddChildAfter(newItemInfo, nextStepItem); + break; + case ChildRelation.Before: + newStepItem = parentStepItem.AddChildBefore(newItemInfo, nextStepItem); + break; + case ChildRelation.RNO: + newStepItem = parentStepItem.AddChildRNO(newItemInfo, nextStepItem); + break; + default: // Need debug + break; + } + _MyStepPanel.SelectedStepRTB = newStepItem.MyStepRTB;//Update Screen + _MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.Replace, newItemInfo.MyContent.Type)); + return newStepItem; + } + public void HighlightBackColor() + { + // Highlight all of the rtb's within this stepitem: + if (MyAfterStepItems != null) + { + foreach (StepItem sia in MyAfterStepItems) + { + sia.MyStepRTB.HighlightBackColor(); + sia.HighlightBackColor(); + } + } + if (MyBeforeStepItems != null) + { + foreach (StepItem sib in MyBeforeStepItems) + { + sib.MyStepRTB.HighlightBackColor(); + sib.HighlightBackColor(); + } + } + if (MyRNOStepItems != null) + { + foreach (StepItem sir in MyRNOStepItems) + { + sir.MyStepRTB.HighlightBackColor(); + sir.HighlightBackColor(); + } + } + } + public void SetBackColor() + { + // Set (removing highlighting) all of the rtb's within this stepitem: + if (MyAfterStepItems != null) + { + foreach (StepItem sia in MyAfterStepItems) + { + sia.MyStepRTB.SetBackColor(); + sia.SetBackColor(); + } + } + if (MyBeforeStepItems != null) + { + foreach (StepItem sib in MyBeforeStepItems) + { + sib.MyStepRTB.SetBackColor(); + sib.SetBackColor(); + } + } + if (MyRNOStepItems != null) + { + foreach (StepItem sir in MyRNOStepItems) + { + sir.MyStepRTB.SetBackColor(); + sir.SetBackColor(); + } + } + } + #endregion #region Event Handlers /// /// If the background changes, change the background of the RichTextBox diff --git a/PROMS/Volian.Controls.Library/StepPanel.cs b/PROMS/Volian.Controls.Library/StepPanel.cs index c74f6d73..e102519e 100644 --- a/PROMS/Volian.Controls.Library/StepPanel.cs +++ b/PROMS/Volian.Controls.Library/StepPanel.cs @@ -135,6 +135,12 @@ namespace Volian.Controls.Library { WordSectionDeleted(sender, args); } + // if item pasted, have event to flag in other UI panels + public event StepPanelItemPastedEvent ItemPasted; + internal void OnItemPasted(object sender, vlnTreeItemInfoPasteEventArgs args) + { + ItemPasted(sender, args); + } #endregion #region Link Events /// @@ -684,11 +690,11 @@ namespace Volian.Controls.Library { // if on RNO, check display mode (1 column/2 column, etc) and how deep RNO is before going to // parents substeps. - if (ii.IsRNO && ii.MyParent.Steps != null && ii.RNOLevel >= ii.ColumnMode) return BottomPart(ii.MyParent.Steps[0].LastSibling); + if (ii.IsRNOPart && ii.MyParent.Steps != null && ii.RNOLevel >= ii.ColumnMode) return BottomPart(ii.MyParent.Steps[0].LastSibling); // If on top note and parent has cautions - go to bottom caution - if (ii.IsNoteStructure && ii.MyParent != null && ii.MyParent.Cautions != null) return BottomPart(ii.MyParent.Cautions[0].LastSibling); - if (ii.IsCautionStructure || ii.IsNoteStructure) + if (ii.IsFirstNotePart && ii.MyParent != null && ii.MyParent.Cautions != null) return BottomPart(ii.MyParent.Cautions[0].LastSibling); + if (ii.IsFirstCautionPart || ii.IsFirstNotePart) { if (ii.MyParent.MyPrevious != null) return BottomPart(ii.MyParent.MyPrevious); return ii.MyParent.MyParent; @@ -728,9 +734,9 @@ namespace Volian.Controls.Library // TODO: RHM - NextItems was not null when it should have been after delete of a note below a caution if (ii.NextItems != null && ii.NextItemCount > 0) return TopPart(ii.NextItems[0]); // If on caution, if parent has note - go to note - if (ii.IsCautionStructureFirstSib && ii.MyParent.Notes != null) return ii.MyParent.Notes[0]; + if (ii.IsCautionPart && ii.MyParent.Notes != null) return ii.MyParent.Notes[0]; // If on caution, if parent !has note or if on note go to parent - if ((ii.IsCautionStructureFirstSib && ii.MyParent.Notes == null) || ii.IsNoteStructureFirstSib) return ii.MyParent; + if ((ii.IsCautionPart && ii.MyParent.Notes == null) || ii.IsNotePart) return ii.MyParent; // Recursively call with parent until at procedure if (!ii.IsProcedure) return (ArrowDown(ii.MyParent, false, ii.MyParent.RNOLevel==ii.RNOLevel)); } @@ -1041,4 +1047,5 @@ namespace Volian.Controls.Library public delegate void StepPanelTabDisplayEvent(object sender, StepPanelTabDisplayEventArgs args); public delegate void StepPanelWordSectionCloseEvent(object sender, WordSectionEventArgs args); public delegate void StepPanelWordSectionDeletedEvent(object sender, WordSectionEventArgs args); + public delegate void StepPanelItemPastedEvent(object sender, vlnTreeItemInfoPasteEventArgs args); } diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index fc4615fc..153637ef 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -173,6 +173,12 @@ namespace Volian.Controls.Library if (MyStepItem == null || MyStepItem.MyStepPanel == null) return; BackColor = _MyItemInfo.ItemAnnotationCount == 0 ? MyStepItem.MyStepPanel.InactiveColor : Color.FromArgb(255, 255, 128); } + public void HighlightBackColor() + { + // Don't try to highlight if this rtb is used on property pages. + if (MyStepItem == null || MyStepItem.MyStepPanel == null) return; + BackColor = Color.Gray; + } private string _origRTF; public void RTBFillIn(bool edit) { @@ -1590,6 +1596,18 @@ namespace Volian.Controls.Library // comment on _OverWrite e.Handled = true; break; + case Keys.F5: + if (e.Shift) + { + e.Handled = true; + this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("StepPaste"); + } + else if (!e.Control && !e.Alt) + { + e.Handled = true; + this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.DoCopyStep(); + } + break; case Keys.F6: e.Handled = true; SendKeys.Send("%H{ESC}"); diff --git a/PROMS/Volian.Controls.Library/StepTabPanel.cs b/PROMS/Volian.Controls.Library/StepTabPanel.cs index c1b6df81..884fd483 100644 --- a/PROMS/Volian.Controls.Library/StepTabPanel.cs +++ b/PROMS/Volian.Controls.Library/StepTabPanel.cs @@ -142,6 +142,7 @@ namespace Volian.Controls.Library _MyStepPanel.TabDisplay += new Volian.Controls.Library.StepPanelTabDisplayEvent(_MyStepPanel_TabDisplay); _MyStepPanel.WordSectionClose += new StepPanelWordSectionCloseEvent(_MyStepPanel_WordSectionClose); _MyStepPanel.WordSectionDeleted += new StepPanelWordSectionDeletedEvent(_MyStepPanel_WordSectionDeleted); + _MyStepPanel.ItemPasted += new StepPanelItemPastedEvent(_MyStepPanel_ItemPasted); } @@ -278,6 +279,10 @@ namespace Volian.Controls.Library { _MyDisplayTabControl.OnWordSectionDeleted(sender, args); } + void _MyStepPanel_ItemPasted(object sender, vlnTreeItemInfoPasteEventArgs args) + { + _MyDisplayTabControl.OnItemPaste(sender, args); + } #endregion } } diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index 022bc872..d74ecdbe 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -277,6 +277,7 @@ namespace Volian.Controls.Library btnCMRedo.Enabled = btnRedo.Enabled = setting; btnCMPaste.Enabled = btnPaste.Enabled = setting; btnCMCopy.Enabled = btnCopy.Enabled = setting; + btnPasteAfter.Enabled = btnPasteBefore.Enabled = btnStepPaste.Enabled = btnPasteReplace.Enabled = setting; } private void SetButtonMenuEnabledDisabledOnStepType(bool setting) { @@ -328,6 +329,9 @@ namespace Volian.Controls.Library // all selected copy while in either Edit or View mode btnCMCopy.Enabled = btnCopy.Enabled = _MyStepRTB.SelectionLength > 0; + // paste step only available if a step was copied. Also, check for valid types: + SetPasteButtonEnabled(); + // do all Transition and ReferencedObject menu items/buttons based on whether a 'link is selected' and the link type. btnCMGoTo.Enabled = btnGoTo.Enabled = _MyStepRTB.IsSelectionLinked(_MyStepRTB.SelectionStart, _MyStepRTB.SelectionLength); //(_MyStepRTB.MyLinkText != null); if (btnCMGoTo.Enabled == true && _MyStepRTB.MyLinkText != null) // must have some link test, use it to set edit of transition or ro... @@ -342,6 +346,37 @@ namespace Volian.Controls.Library } // OLD: SetStepButtonAndMenuEnabling(docontextmenus); } + + private void SetPasteButtonEnabled() + { + // if there is no 'copied' step, or if a procedure is copied, just turn all buttons off, this can only + // be done from the tree. + StepTabPanel tmp = Parent as StepTabPanel; + if (tmp.MyDisplayTabControl.MyCopyStep == null || tmp.MyDisplayTabControl.MyCopyStep.IsProcedurePart) + { + btnPasteReplace.Enabled = btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnStepPaste.Enabled = false; + return; + } + // If a section is copied, it can be pasted as a section (before/after/replace). If can also + // be pasted as a subsection if the format allows it. + if (tmp.MyDisplayTabControl.MyCopyStep.IsSectionPart) + { + btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = MyItemInfo.IsSectionPart; + // when doing 'substep' part of paste, need to check if format allows subsection. + } + else if (tmp.MyDisplayTabControl.MyCopyStep.IsCautionPart || tmp.MyDisplayTabControl.MyCopyStep.IsNotePart) + // Part type of copied step must be same as Part type of destination, with exceptions of caution/note and step/rno + // can be pasted into each other. + // Part types are procedure - 1, section = 2, step = 6, caution = 3, note = 4, RNO (IsRNO), = 5 table/figure = 7. + btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = (MyItemInfo.IsCautionPart || MyItemInfo.IsNotePart); + else if (tmp.MyDisplayTabControl.MyCopyStep.IsRNOPart || tmp.MyDisplayTabControl.MyCopyStep.IsStepPart) + btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = (MyItemInfo.IsRNOPart || MyItemInfo.IsStepPart); + else + btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = tmp.MyDisplayTabControl.MyCopyStep.IsTablePart == MyItemInfo.IsTablePart; + + // Can't replace step with same step + if (tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID) btnPasteReplace.Enabled = false; + } private void SetStepButtonAndMenuEnabling(bool docontextmenus) { if (MyStepItem == null) return; @@ -365,6 +400,7 @@ namespace Volian.Controls.Library btnEditMode.Checked = btnCMEditMode1.Checked = MyStepItem.MyStepPanel.PanelViewEditMode != E_ViewMode.View; // if on procedure, 'Delete' buttons should be disabled. btnDelelete.Enabled = btnDelStep.Enabled = ! MyItemInfo.IsProcedure; + btnCpyStp.Enabled = !MyItemInfo.IsProcedure; // if on procedure or section, 'change type' & 'insert' buttons should be disabled. if (MyItemInfo.IsProcedure || MyItemInfo.IsSection) { @@ -569,6 +605,7 @@ namespace Volian.Controls.Library { Clipboard.Clear(); DataObject myDO = new DataObject("Rich Text Format", _MyStepRTB.SelectedRtf); + myDO.SetText(_MyStepRTB.SelectedText); Clipboard.SetDataObject(myDO); _MyStepRTB.SelectedText = ""; } @@ -576,6 +613,7 @@ namespace Volian.Controls.Library { Clipboard.Clear(); DataObject myDO = new DataObject("Rich Text Format", _MyStepRTB.SelectedRtf); + myDO.SetText(_MyStepRTB.SelectedText); Clipboard.SetDataObject(myDO); } private void btnBold_Click(object sender, EventArgs e) @@ -878,8 +916,11 @@ namespace Volian.Controls.Library bool displayMenu = false; E_AccStep? actable = 0; StepData sd = MyItemInfo.FormatStepData; - actable = sd.StepEditData.AcTable; - if (actable == null) actable = 0; + if (sd != null) // will be null if section + { + actable = sd.StepEditData.AcTable; + if (actable == null) actable = 0; + } //btnInsCaut.Enabled = (actable & E_AccStep.AddingCaution) > 0; switch (menuName) { @@ -911,6 +952,10 @@ namespace Volian.Controls.Library displayMenu = (actable & E_AccStep.AddingTable) > 0; _ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMInsFigure); break; + case "StepPaste": + displayMenu = true; + _ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMStepPaste); + break; } if (displayMenu) { @@ -960,8 +1005,8 @@ namespace Volian.Controls.Library { deletedEmpty = true; deletedHLS = MyItemInfo.IsHigh; - deletedSubStep = MyItemInfo.IsSubStep; - deletedRNO = MyItemInfo.IsRNO; + deletedSubStep = MyItemInfo.IsStepPart; + deletedRNO = MyItemInfo.IsRNOPart; deletedNote = MyItemInfo.IsNote; deletedCaution = MyItemInfo.IsCaution; @@ -990,7 +1035,7 @@ namespace Volian.Controls.Library CreateNewRNO(); } } - else if (MyItemInfo.IsRNO) + else if (MyItemInfo.IsRNOPart) { MyStepRTB.StepRTB_ArrowPressed(E_ArrowKeys.CtrlLeft); if (MyItemInfo.IsHigh) @@ -1006,7 +1051,7 @@ namespace Volian.Controls.Library else InsertSiblingBeforeOrAfter("after"); } - else if (MyItemInfo.IsInRNO && MyItemInfo.IsSubStep) + else if (MyItemInfo.IsInRNO && MyItemInfo.IsStepPart) { if (deletedEmpty) { @@ -1016,7 +1061,7 @@ namespace Volian.Controls.Library else InsertSiblingBeforeOrAfter("after"); } - else if (MyItemInfo.IsSubStep) + else if (MyItemInfo.IsStepPart) { if (deletedSubStep) { @@ -1073,6 +1118,48 @@ namespace Volian.Controls.Library else btnInsNote.RaiseClick(); } + private void btnPasteAfter_Click(object sender, EventArgs e) + { + StepTabPanel tmp = Parent as StepTabPanel; + MyStepItem.PasteSiblingAfter(tmp.MyDisplayTabControl.MyCopyStep.ItemID); + } + private void btnPasteBefore_Click(object sender, EventArgs e) + { + StepTabPanel tmp = Parent as StepTabPanel; + MyStepItem.PasteSiblingBefore(tmp.MyDisplayTabControl.MyCopyStep.ItemID); + } + private void btnStepPaste_Click(object sender, EventArgs e) + { + // just return + } + + private void btnCpyStp_Click(object sender, EventArgs e) + { + DoCopyStep(); + } + + public void DoCopyStep() + { + // highlight selected step(s) and prompt to see if selection is what user wants: + MyStepItem.HighlightBackColor(); + DialogResult dr = MessageBox.Show("Step as Marked?", "Identify Step To Be Copied", MessageBoxButtons.YesNo); + if (dr == DialogResult.Yes) + { + StepTabPanel tmp = Parent as StepTabPanel; + tmp.MyDisplayTabControl.MyCopyStep = MyItemInfo; + btnStepPaste.Enabled = true; + SetPasteButtonEnabled(); + } + MyStepItem.SetBackColor(); + } + + private void btnPasteReplace_Click(object sender, EventArgs e) + { + StepTabPanel tmp = Parent as StepTabPanel; + StepItem oldStepItem = MyStepItem; + MyStepItem = MyStepItem.PasteReplace(tmp.MyDisplayTabControl.MyCopyStep.ItemID); + if (MyStepItem.MyItemInfo.ItemID != oldStepItem.MyItemInfo.ItemID) oldStepItem.Dispose(); + } } public enum E_FieldToEdit { StepText, Text, Number }; diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.designer.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.designer.cs index adac57ad..9269fb50 100644 Binary files a/PROMS/Volian.Controls.Library/StepTabRibbon.designer.cs and b/PROMS/Volian.Controls.Library/StepTabRibbon.designer.cs differ diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.resx b/PROMS/Volian.Controls.Library/StepTabRibbon.resx index 3c7ae060..51d55bc6 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.resx +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + @@ -130,9 +133,6 @@ 2CVVWYKhQwAAAABJRU5ErkJggg== - - 17, 17 - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 @@ -142,9 +142,6 @@ hNwGBmaHAP5n4G8q6gFdoZLjBpE7j5KJdaRlAAAAAElFTkSuQmCC - - 17, 17 - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 diff --git a/PROMS/Volian.Controls.Library/TemporaryFormat.cs b/PROMS/Volian.Controls.Library/TemporaryFormat.cs index 8ba9bfcd..66d53a35 100644 --- a/PROMS/Volian.Controls.Library/TemporaryFormat.cs +++ b/PROMS/Volian.Controls.Library/TemporaryFormat.cs @@ -71,7 +71,7 @@ namespace Volian.Controls.Library int typ = (int)myDisplayItem.MyItemInfo.MyContent.Type; if (typ >= 20000) { - if (myDisplayItem.RNOLevel > 0 && myDisplayItem.MyItemInfo.IsRNO) return ""; + if (myDisplayItem.RNOLevel > 0 && myDisplayItem.MyItemInfo.IsRNOPart) return ""; // Step 1: Get TabFormat from Format format = _TabFormats[typ % 10000]; if (format == "") diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs index 967ece45..4582918f 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs @@ -20,6 +20,7 @@ namespace Volian.Controls.Library public delegate bool vlnTreeViewBoolEvent(object sender, vlnTreeEventArgs args); public delegate bool vlnTreeViewItemInfoDeleteEvent(object sender, vlnTreeItemInfoEventArgs args); public delegate bool vlnTreeViewItemInfoInsertEvent(object sender, vlnTreeItemInfoInsertEventArgs args); + public delegate bool vlnTreeViewItemInfoPasteEvent(object sender, vlnTreeItemInfoPasteEventArgs 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); @@ -144,6 +145,48 @@ namespace Volian.Controls.Library } #endregion } + #region PasteEventArgs + public partial class vlnTreeItemInfoPasteEventArgs + { + #region Business Methods + private ItemInfo _MyItemInfo; + public ItemInfo MyItemInfo + { + get { return _MyItemInfo; } + set { _MyItemInfo = value; } + } + private int _CopyStartID; + public int CopyStartID + { + get { return _CopyStartID; } + set { _CopyStartID = value; } + } + private ItemInfo.EAddpingPart _PasteType; + public ItemInfo.EAddpingPart PasteType + { + get { return _PasteType; } + set { _PasteType = value; } + } + private int? _Type; + public int? Type + { + get { return _Type; } + set { _Type = value; } + } + #endregion + #region Factory Methods + private vlnTreeItemInfoPasteEventArgs() { ;} + public vlnTreeItemInfoPasteEventArgs(ItemInfo myItemInfo, int copyStartId, ItemInfo.EAddpingPart pasteType, int? type) + { + _MyItemInfo = myItemInfo; + _CopyStartID = copyStartId; + _PasteType = pasteType; + _Type = type; + } + + #endregion + } + #endregion public partial class vlnTreePropertyEventArgs : EventArgs { private string _Title; @@ -232,6 +275,12 @@ namespace Volian.Controls.Library if (InsertItemInfo != null) return InsertItemInfo(sender, args); return false; } + public event vlnTreeViewItemInfoPasteEvent PasteItemInfo; + private bool OnPasteItemInfo(object sender, vlnTreeItemInfoPasteEventArgs args) + { + if (PasteItemInfo != null) return PasteItemInfo(sender, args); + return false; + } public event vlnTreeViewEvent NodeMove; private void OnNodeMove(object sender, vlnTreeEventArgs args) { @@ -300,7 +349,7 @@ namespace Volian.Controls.Library // that allow more than one type of operation associated with their selection. public enum MenuSelections : int { - Folder = 1, FolderBefore = 2, FolderAfter = 3, DocVersion = 4, Procedure = 5, ProcedureBefore = 6, ProcedureAfter = 7, Section = 8, SectionBefore = 9, SectionAfter = 10, Step = 11, StepBefore = 12, StepAfter = 13 + Folder = 1, FolderBefore = 2, FolderAfter = 3, DocVersion = 4, Procedure = 5, ProcedureBefore = 6, ProcedureAfter = 7, Section = 8, SectionBefore = 9, SectionAfter = 10, Step = 11, StepBefore = 12, StepAfter = 13, StepReplace = 14 } void tv_MouseDown(object sender, MouseEventArgs e) { @@ -373,11 +422,9 @@ namespace Volian.Controls.Library cm.MenuItems.Add("Open", new EventHandler(mi_Click)); #endregion #region Menu_CutCopy - // 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("Copy", new EventHandler(mi_Click)); } #endregion @@ -445,7 +492,7 @@ namespace Volian.Controls.Library { 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)); + cm.MenuItems.Add("Paste Step After", new EventHandler(mi_Click)); } } } @@ -564,47 +611,50 @@ namespace Volian.Controls.Library 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); + 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) + { + // If paste-from step is open in the editor, use the OnPasteItemInfo to paste the step and add stepitems + // to the step editor panel. + ItemInfo ii = tn.VEObject as ItemInfo; + ItemInfo.EAddpingPart pasteOpt = newtype == MenuSelections.StepBefore ? ItemInfo.EAddpingPart.Before : ItemInfo.EAddpingPart.After; + // If parent step is open in step editor, the 'OnPasteItemInfo' event will cause + // the item to be pasted in the step editor and the tree. + if (OnPasteItemInfo(this, new vlnTreeItemInfoPasteEventArgs(ii, copyStartID, pasteOpt, ii.MyContent.Type))==null) + { + //return; + // The parent step was not open in the step editor, just paste step (in data) and add treenode. + ItemInfo newItemInfo = null; + if (newtype == MenuSelections.StepBefore) + newItemInfo = ii.PasteSiblingBefore(copyStartID); + else + newItemInfo = ii.PasteSiblingAfter(copyStartID); + } + SelectedNode = (VETreeNode)((newtype == MenuSelections.StepAfter) ? tn.NextNode : tn.PrevNode); + } + private void PasteReplace(VETreeNode tn, int copyStartID) + { + VETreeNode prevtn = (VETreeNode) tn.PrevNode; + VETreeNode partn = (VETreeNode) tn.Parent; + ItemInfo ii = tn.VEObject as ItemInfo; + if (OnPasteItemInfo(this, new vlnTreeItemInfoPasteEventArgs(ii, copyStartID, ItemInfo.EAddpingPart.Replace, ii.MyContent.Type))==null) + { + //return; + ItemInfo replItemInfo = Item.PasteReplace(ii, copyStartID); + } + SelectedNode = (VETreeNode)((prevtn != null) ? prevtn.NextNode : partn.FirstNode); } - private void tv_NodeCopy() { if (SelectedNode==null)return; @@ -616,7 +666,12 @@ namespace Volian.Controls.Library PromsClipboard iClip; iClip.itemId = ii.ItemID; iClip.cType = (int)PromsClipboardType.Copy; - Clipboard.SetData("PromsClipboard", iClip); + DataObject myDO = new DataObject(); + myDO.SetText(ii.DisplayNumber); + myDO.SetData("PromsClipboard", iClip); + Clipboard.SetDataObject(myDO); + //Clipboard.SetData("PromsClipboard", iClip); + //Clipboard.SetData(DataFormats.Text, ii.DisplayNumber); } } #endregion