/// <summary> /// Set the source sub item before the target one. /// </summary> /// <param name="targetNvd">The target node view data in the current view.</param> /// <param name="sourceItem">The source sub item of the current node view data.</param> /// <param name="targetItem">The target sub item of the target node view data.</param> public bool SetSubItem(NodeViewData targetNvd, SubItemAttachment sourceItem, SubItemAttachment targetItem, bool insertPreviously, bool isCopied) { if (targetNvd == null || sourceItem == null || sourceItem.Attachment == null || !isCopied && targetItem == sourceItem || !targetNvd.Node.AcceptsAttachment(sourceItem.Attachment)) { return false; } if (!isCopied) { this.Node.RemoveAttachment(sourceItem.Attachment); this.RemoveSubItem(sourceItem); } else { sourceItem = sourceItem.Clone(targetNvd.Node) as SubItemAttachment; sourceItem.Attachment.ResetId(); } if (targetItem == null) { targetNvd.Node.AddAttachment(sourceItem.Attachment); } else { Debug.Check(targetItem.Attachment != null); for (int i = 0; i < targetNvd.Node.Attachments.Count; ++i) { if (targetNvd.Node.Attachments[i] == targetItem.Attachment) { targetNvd.Node.AddAttachment(sourceItem.Attachment, insertPreviously ? i : i + 1); break; } } } if (targetItem == null) { targetNvd.AddSubItem(sourceItem); } else { for (int i = 0; i < targetNvd.SubItems.Count; ++i) { if (targetNvd.SubItems[i] == targetItem) { targetNvd.AddSubItem(sourceItem, insertPreviously ? i : i + 1); break; } } } bool setDirty = false; if (!isCopied) { sourceItem.Attachment.OnPropertyValueChanged(!setDirty); setDirty = true; } for (int i = 0; i < targetNvd.SubItems.Count; ++i) { SubItemAttachment attach = targetNvd.SubItems[i] as SubItemAttachment; if (attach != null && attach != sourceItem) { attach.Attachment.OnPropertyValueChanged(!setDirty); setDirty = true; } } targetNvd.SelectedSubItem = sourceItem; return true; }
/// <summary> /// Set the source sub item before the target one. /// </summary> /// <param name="targetNvd">The target node view data in the current view.</param> /// <param name="targetItem">The target sub item of the target node view data.</param> /// <param name="sourceItem">The source sub item of the current node view data.</param> public bool SetSubItem(NodeViewData targetNvd, SubItemAttachment targetItem, SubItemAttachment sourceItem, bool insertPrevious) { if (targetNvd == null || targetItem == null || targetItem.Attachment == null || sourceItem == null || sourceItem.Attachment == null || targetItem == sourceItem) return false; this.Node.RemoveAttachment(sourceItem.Attachment); for (int i = 0; i < targetNvd.Node.Attachments.Count; ++i) { if (targetNvd.Node.Attachments[i] == targetItem.Attachment) { targetNvd.Node.AddAttachment(sourceItem.Attachment, insertPrevious ? i : i + 1); break; } } this.RemoveSubItem(sourceItem); for (int i = 0; i < targetNvd.SubItems.Count; ++i) { if (targetNvd.SubItems[i] == targetItem) { targetNvd.AddSubItem(sourceItem, insertPrevious ? i : i + 1); break; } } sourceItem.Attachment.OnPropertyValueChanged(true); for (int i = 0; i < targetNvd.SubItems.Count; ++i) { SubItemAttachment attach = targetNvd.SubItems[i] as SubItemAttachment; if (attach != null && attach != sourceItem) attach.Attachment.OnPropertyValueChanged(false); } return true; }