private static string[] GetReviewTextLines(AnnReview review) { // We are drawing the following lines // author // status date // comment var lines = new string[3]; var author = review != null ? review.Author : null; if (string.IsNullOrEmpty(author)) { author = "[author]"; } lines[0] = author; if (review != null) { lines[1] = string.Format("{0} {1}", review.Status, review.Date); lines[2] = review.Comment; } else { lines[1] = string.Empty; lines[2] = string.Empty; } return(lines); }
private void _replyReview_Click(object sender, EventArgs e) { AnnReview review = new AnnReview(); review.Author = Environment.UserName; review.Date = DateTime.Now; review.Status = AnnReview.Reply; _annObject.Reviews.Add(review); ReviewTreeNode child = new ReviewTreeNode(_annObject, _annObject.Reviews, review, this, _automation, Tree); ChildNodes.Add(child); IsExpanded = true; _btnCollapseExpand.Text = "-"; _miExpandCollapse.Text = "Collapse"; _lblObjectName.Visible = true; _lblDate.Visible = true; if (IsExpanded) { Tree.RemoveChildsFromTree(ChildNodes); int parentIndex = Tree.Controls.GetChildIndex(this); Tree.AddChildsToTree(ChildNodes, ref parentIndex); } else { int parentIndex = Tree.Controls.GetChildIndex(this); Tree.AddChildsToTree(ChildNodes, ref parentIndex); } }
private void AddOrReply(TreeNode node, bool isReply) { _isModified = true; // add after selected var review = new AnnReview(); review.Author = this.UserName; review.Date = DateTime.Now; review.Status = AnnReview.Reply; var newNode = AddNode(_treeView, node, isReply, review); _treeView.SelectedNode = newNode; }
private void _addReview_Click(object sender, EventArgs e) { AnnReview review = new AnnReview(); review.Author = Environment.UserName; review.Date = DateTime.Now; review.Status = AnnReview.Reply; _reviews.Add(review); ReviewTreeNode reply = new ReviewTreeNode(_annObject, _reviews, review, TreeParentNode, _automation, Tree); TreeParentNode.ChildNodes.Add(reply); Tree.RemoveChildsFromTree(TreeParentNode.ChildNodes); int parentIndex = Tree.Controls.GetChildIndex(TreeParentNode); Tree.AddChildsToTree(TreeParentNode.ChildNodes, ref parentIndex); }
private static string GetReviewNodeText(AnnReview review) { var lines = GetReviewTextLines(review); // Miminum length is 4 var maxLength = 4; foreach (var line in lines) { if (!string.IsNullOrEmpty(line)) { maxLength = Math.Max(line.Length, maxLength); } } var sb = new StringBuilder(); for (var i = 0; i < maxLength; i++) { sb.Append("W"); } return(sb.ToString()); }
private static TreeNode AddNode(TreeView treeView, TreeNode relativeNode, bool sibling, AnnReview review) { // Add some text to make it wide. We will custom-draw this anyway TreeNode node = new TreeNode(GetReviewNodeText(review)); // add a copy so we don't change the original reviews if the user cancels node.Tag = review != null?review.Clone() : null; review = node.Tag as AnnReview; foreach (var reply in review.Replies) { AddNode(treeView, node, true, reply); } // Clean its replies, we dont need them here review.Replies.Clear(); if (sibling) { if (relativeNode != null) { relativeNode.Nodes.Add(node); } else { treeView.Nodes.Add(node); } } else { if (relativeNode != null) { TreeNodeCollection nodes; if (relativeNode.Parent != null) { nodes = relativeNode.Parent.Nodes; } else { nodes = treeView.Nodes; } var index = nodes.IndexOf(relativeNode); if (index != -1) { nodes.Insert(index + 1, node); } else { nodes.Add(node); } } else { treeView.Nodes.Add(node); } } return(node); }
private static void GetNode(TreeView treeView, TreeNode node, AnnObject annObject, AnnReview parentReview) { var nodeReview = node != null ? node.Tag as AnnReview : null; var review = nodeReview != null?nodeReview.Clone() : null; foreach (TreeNode childNode in node.Nodes) { GetNode(treeView, childNode, annObject, review); } if (parentReview != null) { parentReview.Replies.Add(review); } else { annObject.Reviews.Add(review); } }
public ReviewTreeNode(AnnObject annObject, IList <AnnReview> reviews, AnnReview reply, AutomationTreeNode treeParentNode, AnnAutomation automation, AutomationObjectsListControl tree) : base(tree) { InitializeComponent(); if (annObject == null) { throw new ArgumentNullException("annObject"); } if (annObject.Id == AnnObject.SelectObjectId || annObject.Id == AnnObject.None) { throw new ArgumentException("Cannot create this item with a selection or none annotation object", "annObject"); } if (reviews == null) { throw new ArgumentNullException("reviews"); } if (reply == null) { throw new ArgumentNullException("reply"); } if (automation == null) { throw new ArgumentNullException("automation"); } _annObject = annObject; _automation = automation; _reviews = reviews; _reply = reply; AnnAutomationObject automationObject = _automation.Manager.FindObjectById(_annObject.Id); if (automationObject != null) { _lblObjectName.Text = automationObject.Name; } else { _lblObjectName.Text = _annObject.FriendlyName; } _pbObjetIcon.Image = _replyImage; if (!String.IsNullOrEmpty(_reply.Author)) { _lblAuthor.Text = _reply.Author; } string date = _reply.Date.ToString(); if (!String.IsNullOrEmpty(date)) { _lblDate.Text = date; } string status = _reply.Status; if (!String.IsNullOrEmpty(status)) { _lblDate.Text = status + ": " + _lblDate.Text; } foreach (ToolStripMenuItem item in _miSetStatus.DropDownItems) { item.Checked = (item.Text == status); } if (!String.IsNullOrEmpty(_reply.Comment)) { _tbComment.Text = _reply.Comment; } _cbChecked.Checked = _reply.IsChecked; TreeParentNode = treeParentNode; IsExpanded = false; Width = Tree.TreeRootNode.Width - Margin.Left; }